Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/wined3d/glsl_shader.c | 10 ++++++++++ dlls/wined3d/shader.c | 4 ++++ dlls/wined3d/wined3d_private.h | 6 ++++-- 3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index da7e70071d19..6f23cf8a4034 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -3242,6 +3242,10 @@ static void shader_glsl_get_register_name(const struct wined3d_shader_register * sprintf(register_name, "vpc[%u]", reg->idx[0].offset); break;
+ case WINED3DSPR_SAMPLEMASK: + sprintf(register_name, "sample_mask"); + break; + default: FIXME("Unhandled register type %#x.\n", reg->type); sprintf(register_name, "unrecognized_register"); @@ -7627,6 +7631,9 @@ static void shader_glsl_generate_ps_epilogue(const struct wined3d_gl_info *gl_in shader_glsl_generate_fog_code(buffer, gl_info, args->fog);
shader_glsl_generate_alpha_test(buffer, gl_info, args->alpha_test_func + 1); + + if (reg_maps->sample_mask) + shader_addline(buffer, "gl_SampleMask[0] = floatBitsToInt(sample_mask);\n"); }
/* Context activation is done by the caller. */ @@ -7822,6 +7829,9 @@ static GLuint shader_glsl_generate_pshader(const struct wined3d_context *context
shader_addline(buffer, "void main()\n{\n");
+ if (reg_maps->sample_mask) + shader_addline(buffer, "float sample_mask = uintBitsToFloat(0xffffffffu);\n"); + /* Direct3D applications expect integer vPos values, while OpenGL drivers * add approximately 0.5. This causes off-by-one problems as spotted by * the vPos d3d9 visual test. Unfortunately ATI cards do not add exactly diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c index 45ae04a9bec9..3a0a3022172f 100644 --- a/dlls/wined3d/shader.c +++ b/dlls/wined3d/shader.c @@ -810,6 +810,10 @@ static BOOL shader_record_register_usage(struct wined3d_shader *shader, struct w reg_maps->vocp = 1; break;
+ case WINED3DSPR_SAMPLEMASK: + reg_maps->sample_mask = 1; + break; + default: TRACE("Not recording register of type %#x and [%#x][%#x].\n", reg->type, reg->idx[0].offset, reg->idx[1].offset); diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index b2e4372e9ae5..f40d1639496b 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1040,7 +1040,8 @@ struct wined3d_shader_reg_maps DWORD vocp : 1; DWORD input_rel_addressing : 1; DWORD viewport_array : 1; - DWORD padding : 15; + DWORD sample_mask : 1; + DWORD padding : 14;
DWORD rt_mask; /* Used render targets, 32 max. */
@@ -4115,13 +4116,14 @@ static inline BOOL shader_is_scalar(const struct wined3d_shader_register *reg) /* oPos */ return FALSE;
+ case WINED3DSPR_CONSTBOOL: /* b# */ case WINED3DSPR_DEPTHOUT: /* oDepth */ case WINED3DSPR_DEPTHOUTGE: case WINED3DSPR_DEPTHOUTLE: - case WINED3DSPR_CONSTBOOL: /* b# */ case WINED3DSPR_LOOP: /* aL */ case WINED3DSPR_PREDICATE: /* p0 */ case WINED3DSPR_PRIMID: /* primID */ + case WINED3DSPR_SAMPLEMASK: /* oMask */ return TRUE;
case WINED3DSPR_MISCTYPE:
From: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 9e673eef234f..b4566299420d 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -26816,6 +26816,78 @@ static void test_multisample_resolve(void) release_test_context(&test_context); }
+static void test_sample_mask(void) +{ + static const DWORD ps_code[] = + { +#if 0 + float4 main(in float4 pos : SV_Position, out uint sample_mask : SV_Coverage) : SV_Target + { + sample_mask = 0x5; + return float4(1.0, 1.0, 1.0, 1.0); + } +#endif + 0x43425844, 0x196779a9, 0xda85988a, 0xb7f0a0b6, 0xb30dd6ba, 0x00000001, 0x00000114, 0x00000003, + 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, + 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000001, 0xffffffff, 0x00000e01, + 0x545f5653, 0x65677261, 0x56530074, 0x766f435f, 0x67617265, 0xabab0065, 0x58454853, 0x00000054, + 0x00000050, 0x00000015, 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x0000f000, + 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, + 0x04000036, 0x0000f001, 0x00004001, 0x00000005, 0x0100003e, + }; + static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0; + static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f}; + struct d3d11_test_context test_context; + D3D11_TEXTURE2D_DESC texture_desc; + ID3D11DeviceContext *context; + ID3D11RenderTargetView *rtv; + ID3D11Texture2D *texture; + ID3D11PixelShader *ps; + ID3D11Device *device; + UINT quality_levels; + HRESULT hr; + + if (!init_test_context(&test_context, &feature_level)) + return; + device = test_context.device; + context = test_context.immediate_context; + + hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &quality_levels); + ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr); + if (!quality_levels) + { + skip("4xMSAA not supported.\n"); + release_test_context(&test_context); + return; + } + + hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps); + ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr); + ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0); + + ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc); + texture_desc.SampleDesc.Count = 4; + texture_desc.SampleDesc.Quality = 0; + hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture); + ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr); + hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv); + ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr); + + ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL); + ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black); + draw_quad(&test_context); + ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0, + (ID3D11Resource *)texture, 0, texture_desc.Format); + check_texture_color(test_context.backbuffer, 0x7f7f7f7f, 1); + + ID3D11RenderTargetView_Release(rtv); + ID3D11Texture2D_Release(texture); + ID3D11PixelShader_Release(ps); + release_test_context(&test_context); +} + static void test_depth_clip(void) { struct d3d11_test_context test_context; @@ -27027,5 +27099,6 @@ START_TEST(d3d11) test_unbound_multisample_texture(); test_multiple_viewports(); test_multisample_resolve(); + test_sample_mask(); test_depth_clip(); }
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
From: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/wined3d/directx.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index e125c5ff6ef4..32c255240f72 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -3407,6 +3407,7 @@ static void load_gl_funcs(struct wined3d_gl_info *gl_info) MAP_GL_FUNCTION(glIsEnabledi, glIsEnabledIndexedEXT); MAP_GL_FUNCTION(glLinkProgram, glLinkProgramARB); MAP_GL_FUNCTION(glMapBuffer, glMapBufferARB); + MAP_GL_FUNCTION(glMinSampleShading, glMinSampleShadingARB); MAP_GL_FUNCTION_CAST(glShaderSource, glShaderSourceARB); MAP_GL_FUNCTION(glTexBuffer, glTexBufferARB); MAP_GL_FUNCTION_CAST(glTexImage3D, glTexImage3DEXT);
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/wined3d/utils.c | 6 ++++-- dlls/wined3d/wined3d_private.h | 1 - 2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 49b08bfbe4bc..655fdb1d8d3f 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -2756,7 +2756,7 @@ static void query_internal_format(struct wined3d_adapter *adapter, struct wined3d_format *format, const struct wined3d_format_texture_info *texture_info, struct wined3d_gl_info *gl_info, BOOL srgb_write_supported, BOOL srgb_format) { - GLint count, multisample_types[MAX_MULTISAMPLE_TYPES]; + GLint count, multisample_types[8]; unsigned int i, max_log2; GLenum target;
@@ -2835,7 +2835,9 @@ static void query_internal_format(struct wined3d_adapter *adapter, count = 0; GL_EXTCALL(glGetInternalformativ(target, format->glInternal, GL_NUM_SAMPLE_COUNTS, 1, &count)); - count = min(count, MAX_MULTISAMPLE_TYPES); + if (count > ARRAY_SIZE(multisample_types)) + FIXME("Unexpectedly high number of multisample types %d.\n", count); + count = min(count, ARRAY_SIZE(multisample_types)); GL_EXTCALL(glGetInternalformativ(target, format->glInternal, GL_SAMPLES, count, multisample_types)); checkGLcall("query sample counts"); diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index f40d1639496b..3e344a5f0f3e 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -275,7 +275,6 @@ static inline enum complex_fixup get_complex_fixup(struct color_fixup_desc fixup #define MAX_UNORDERED_ACCESS_VIEWS 8 #define MAX_TGSM_REGISTERS 8192 #define MAX_VERTEX_BLENDS 4 -#define MAX_MULTISAMPLE_TYPES 8
struct min_lookup {
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Verifies if pixel shader is executed per sample or per pixel.
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 450 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 450 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index b4566299420d..2a8ec0a8d888 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -26816,6 +26816,455 @@ static void test_multisample_resolve(void) release_test_context(&test_context); }
+static void test_sample_shading(void) +{ + struct shader + { + const DWORD *code; + size_t size; + }; + + D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc; + struct d3d11_test_context test_context; + struct swapchain_desc swapchain_desc; + D3D11_TEXTURE2D_DESC texture_desc; + ID3D11UnorderedAccessView *uav; + D3D11_BUFFER_DESC buffer_desc; + ID3D11ShaderResourceView *srv; + ID3D11DeviceContext *context; + ID3D11RenderTargetView *rtv; + struct resource_readback rb; + ID3D11Buffer *buffer, *cb; + ID3D11Texture2D *texture; + struct uvec4 ps_constant; + ID3D11PixelShader *ps; + ID3D11Device *device; + unsigned int data; + unsigned int i; + HRESULT hr; + + static const DWORD ps_unused_sample_index_code[] = + { +#if 0 + RWByteAddressBuffer u; + + float4 main(uint id : SV_SampleIndex) : SV_Target + { + u.InterlockedAdd(0, 1); + return float4(0.0f, 1.0f, 0.0f, 1.0f); + } +#endif + 0x43425844, 0x41e4574b, 0x1e6441d6, 0x5e756375, 0xacd5dc27, 0x00000001, 0x00000104, 0x00000003, + 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000001, 0x535f5653, 0x6c706d61, 0x646e4965, + 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, + 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, + 0x00000050, 0x00000019, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, + 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, + 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, + 0x0100003e, + }; + static const struct shader ps_unused_sample_index + = {ps_unused_sample_index_code, sizeof(ps_unused_sample_index_code)}; + static const DWORD ps_sample_index_code[] = + { +#if 0 + RWByteAddressBuffer u; + + float4 main(uint id : SV_SampleIndex) : SV_Target + { + u.InterlockedAdd(0, 1); + u.InterlockedAdd(4, id); + return float4(0.0f, 1.0f, 0.0f, 1.0f); + } +#endif + 0x43425844, 0x943ab9ed, 0x91520b4a, 0xb75df9d0, 0x692cd3e6, 0x00000001, 0x00000130, 0x00000003, + 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965, + 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, + 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000090, + 0x00000050, 0x00000024, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012, + 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, + 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, + 0x00000004, 0x0010100a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, + 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, + }; + static const struct shader ps_sample_index = {ps_sample_index_code, sizeof(ps_sample_index_code)}; + static const DWORD ps_samplepos_code[] = + { +#if 0 + Texture2DMS<float> t; + RWByteAddressBuffer u; + + float4 main() : SV_Target + { + float2 sample_position = t.GetSamplePosition(0); + u.InterlockedAdd(0, 1); + u.InterlockedAdd(4, sample_position.x + sample_position.y); + return float4(0.0f, 1.0f, 0.0f, 1.0f); + } +#endif + 0x43425844, 0x9ec7f344, 0x588f5863, 0x436c0531, 0x69dc54bb, 0x00000001, 0x00000160, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e8, 0x00000050, 0x0000003a, + 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001, + 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, + 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0800006e, 0x00100032, 0x00000000, 0x00107046, + 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a, + 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, + 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036, + 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, + }; + static const struct shader ps_samplepos = {ps_samplepos_code, sizeof(ps_samplepos_code)}; + static const DWORD ps_samplepos_rasterizer_code[] = + { +#if 0 + RWByteAddressBuffer u; + + float4 main() : SV_Target + { + float2 sample_position = GetRenderTargetSamplePosition(0); + u.InterlockedAdd(0, 1); + u.InterlockedAdd(4, sample_position.x + sample_position.y); + return float4(0.0f, 1.0f, 0.0f, 1.0f); + } +#endif + 0x43425844, 0xe31795d9, 0x4e9951da, 0xc1713913, 0xfb12da31, 0x00000001, 0x00000148, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d0, 0x00000050, 0x00000034, + 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, + 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, + 0x0600006e, 0x00100032, 0x00000000, 0x0000e046, 0x00004001, 0x00000000, 0x07000000, 0x00100012, + 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, + 0x0010000a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, + 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, + 0x3f800000, 0x0100003e, + }; + static const struct shader ps_samplepos_rasterizer + = {ps_samplepos_rasterizer_code, sizeof(ps_samplepos_rasterizer_code)}; + static const DWORD ps_samplepos_indexed_code[] = + { +#if 0 + RWByteAddressBuffer u; + + float4 main(uint id : SV_SampleIndex) : SV_Target + { + float2 sample_position = GetRenderTargetSamplePosition(id); + u.InterlockedAdd(0, 1); + u.InterlockedAdd(4, sample_position.x + sample_position.y); + return float4(0.0f, 1.0f, 0.0f, 1.0f); + } +#endif + 0x43425844, 0x4b501464, 0x0cd4f636, 0x36428677, 0x6db6b4fb, 0x00000001, 0x00000180, 0x00000003, + 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965, + 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, + 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e0, + 0x00000050, 0x00000038, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012, + 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, + 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0600006e, 0x00100032, + 0x00000000, 0x0000e046, 0x0010100a, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a, + 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, + 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036, + 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, + }; + static const struct shader ps_samplepos_indexed + = {ps_samplepos_indexed_code, sizeof(ps_samplepos_indexed_code)}; + static const DWORD ps_sampleinfo_code[] = + { +#if 0 + Texture2DMS<float> t; + RWByteAddressBuffer u; + + float4 main() : SV_Target + { + uint width, height, sample_count; + t.GetDimensions(width, height, sample_count); + u.InterlockedAdd(0, 1); + u.InterlockedAdd(4, sample_count); + return float4(0.0f, 1.0f, 0.0f, 1.0f); + } +#endif + 0x43425844, 0x4e4f4065, 0x20d88902, 0xd4750e8c, 0x652b8c04, 0x00000001, 0x00000124, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050, 0x0000002b, + 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001, + 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, + 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a, + 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, + 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, + 0x0100003e, + }; + static const struct shader ps_sampleinfo = {ps_sampleinfo_code, sizeof(ps_sampleinfo_code)}; + static const DWORD ps_sampleinfo_rasterizer_code[] = + { +#if 0 + RWByteAddressBuffer u; + + float4 main() : SV_Target + { + uint sample_count = GetRenderTargetSampleCount(); + u.InterlockedAdd(0, 1); + u.InterlockedAdd(4, sample_count); + return float4(0.0f, 1.0f, 0.0f, 1.0f); + } +#endif + 0x43425844, 0xfbbd8619, 0x9c2654c8, 0xb385363a, 0x4aacd10f, 0x00000001, 0x00000110, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000098, 0x00000050, 0x00000026, + 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, + 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, + 0x0400086f, 0x00100012, 0x00000000, 0x0000e00a, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, + 0x00000004, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, + 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, + }; + static const struct shader ps_sampleinfo_rasterizer + = {ps_sampleinfo_rasterizer_code, sizeof(ps_sampleinfo_rasterizer_code)}; + static const DWORD ps_sample_code[] = + { +#if 0 + RWByteAddressBuffer u; + + float4 main(sample float4 position : SV_Position) : SV_Target + { + u.InterlockedAdd(0, 1); + u.InterlockedAdd(4, position.x); + return float4(0.0f, 1.0f, 0.0f, 1.0f); + } +#endif + 0x43425844, 0x46ecbadb, 0xedccbea6, 0x236d7923, 0x0c356c8c, 0x00000001, 0x00000148, 0x00000003, + 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x7469736f, 0x006e6f69, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050, + 0x0000002b, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04003864, 0x00101012, 0x00000000, + 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, + 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500001c, 0x00100012, 0x00000000, + 0x0010100a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, + 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, + 0x3f800000, 0x0100003e, + }; + static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)}; + static const DWORD ps_color_code[] = + { +#if 0 + float4 main(uint id : SV_SampleIndex) : SV_Target + { + switch (id) + { + case 0: return float4(1.0f, 0.0f, 0.0f, 1.0f); + case 1: return float4(0.0f, 1.0f, 0.0f, 1.0f); + case 2: return float4(0.0f, 0.0f, 1.0f, 1.0f); + default: return float4(0.0f, 0.0f, 0.0f, 1.0f); + } + } +#endif + 0x43425844, 0x94c35f48, 0x04c6b0f7, 0x407d8214, 0xc24f01e5, 0x00000001, 0x00000194, 0x00000003, + 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965, + 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, + 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f4, + 0x00000050, 0x0000003d, 0x0100086a, 0x04000863, 0x00101012, 0x00000000, 0x0000000a, 0x03000065, + 0x001020f2, 0x00000000, 0x0300004c, 0x0010100a, 0x00000000, 0x03000006, 0x00004001, 0x00000000, + 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, + 0x0100003e, 0x03000006, 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, + 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x03000006, 0x00004001, 0x00000002, + 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, + 0x0100003e, 0x0100000a, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, + 0x00000000, 0x3f800000, 0x0100003e, 0x01000017, 0x0100003e, + }; + static const DWORD ps_resolve_code[] = + { +#if 0 + Texture2DMS<float4> t; + + uint sample; + uint rt_size; + + float4 main(float4 position : SV_Position) : SV_Target + { + float3 p; + t.GetDimensions(p.x, p.y, p.z); + p *= float3(position.x / rt_size, position.y / rt_size, 0); + return t.Load((int2)p.xy, sample); + } +#endif + 0x43425844, 0x68a4590b, 0xc1ec3070, 0x1b957c43, 0x0c080741, 0x00000001, 0x000001c8, 0x00000003, + 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000012c, 0x00000050, + 0x0000004b, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002058, 0x00107000, + 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, + 0x00000000, 0x02000068, 0x00000001, 0x06000056, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, + 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00100006, 0x00000000, + 0x8900003d, 0x80000102, 0x00155543, 0x001000c2, 0x00000000, 0x00004001, 0x00000000, 0x001074e6, + 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, + 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, + 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8c00002e, 0x80000102, 0x00155543, + 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0020800a, 0x00000000, + 0x00000000, 0x0100003e, + }; + static const struct + { + const struct shader *ps; + BOOL sample_shading; + BOOL todo; + BOOL broken; + } + tests[] = + { + {&ps_unused_sample_index, FALSE, FALSE, TRUE /* broken on Nvidia */}, + {&ps_sample_index, TRUE}, + {&ps_samplepos, FALSE}, + {&ps_samplepos_rasterizer, FALSE}, + {&ps_samplepos_indexed, TRUE, TRUE}, + {&ps_sampleinfo, FALSE}, + {&ps_sampleinfo_rasterizer, FALSE}, + {&ps_sample, TRUE, TRUE, TRUE /* broken on Intel */}, + }; + static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0; + static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; + static const unsigned int zero[4] = {0}; + + swapchain_desc.windowed = TRUE; + swapchain_desc.buffer_count = 1; + swapchain_desc.width = 32; + swapchain_desc.height = 32; + swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD; + swapchain_desc.flags = 0; + if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc)) + return; + device = test_context.device; + context = test_context.immediate_context; + + ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc); + texture_desc.SampleDesc.Count = 4; + texture_desc.SampleDesc.Quality = 0; + texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE; + hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture); + ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr); + hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv); + ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr); + hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv); + ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr); + + buffer_desc.ByteWidth = 1024; + buffer_desc.Usage = D3D11_USAGE_DEFAULT; + buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS; + buffer_desc.CPUAccessFlags = 0; + buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS; + hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer); + ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr); + uav_desc.Format = DXGI_FORMAT_R32_TYPELESS; + uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; + U(uav_desc).Buffer.FirstElement = 0; + U(uav_desc).Buffer.NumElements = 256; + U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW; + hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav); + ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps); + ok(hr == S_OK, "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr); + ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0); + + ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero); + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, + 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL); + draw_quad(&test_context); + check_texture_color(test_context.backbuffer, 0xff00ff00, 0); + get_buffer_readback(buffer, &rb); + data = get_readback_color(&rb, 0, 0); + ok(1024 <= data && data <= 1056, "Test %u: Got unexpected value %u.\n", i, data); + release_resource_readback(&rb); + + ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero); + ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white); + ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, + 1, &rtv, NULL, 1, 1, &uav, NULL); + draw_quad(&test_context); + get_buffer_readback(buffer, &rb); + data = get_readback_color(&rb, 0, 0); + todo_wine_if(tests[i].todo) + { + if (tests[i].sample_shading) + { + ok(4096 <= data || broken(tests[i].broken && data >= 1024), + "Test %u: Got unexpected value %u.\n", i, data); + } + else + { + ok((1024 <= data && data <= 1056) || broken(tests[i].broken && data >= 4096), + "Test %u: Got unexpected value %u.\n", i, data); + } + } + release_resource_readback(&rb); + + ID3D11PixelShader_Release(ps); + } + + if (is_warp_device(device)) + { + skip("Sample shading tests fail on WARP.\n"); + goto done; + } + + hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps); + ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr); + ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0); + ID3D11PixelShader_Release(ps); + + ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white); + ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL); + draw_quad(&test_context); + ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0, + (ID3D11Resource *)texture, 0, texture_desc.Format); + check_texture_color(test_context.backbuffer, 0xff404040, 2); + + hr = ID3D11Device_CreatePixelShader(device, ps_resolve_code, sizeof(ps_resolve_code), NULL, &ps); + ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr); + ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0); + ID3D11PixelShader_Release(ps); + ps_constant.x = 0; + ps_constant.y = texture_desc.Width; + cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant); + ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb); + + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL); + ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv); + draw_quad(&test_context); + check_texture_color(test_context.backbuffer, 0xff0000ff, 0); + ps_constant.x = 1; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0); + draw_quad(&test_context); + check_texture_color(test_context.backbuffer, 0xff00ff00, 0); + ps_constant.x = 2; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0); + draw_quad(&test_context); + check_texture_color(test_context.backbuffer, 0xffff0000, 0); + ps_constant.x = 3; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0); + draw_quad(&test_context); + check_texture_color(test_context.backbuffer, 0xff000000, 0); + + ID3D11Buffer_Release(cb); +done: + ID3D11Buffer_Release(buffer); + ID3D11UnorderedAccessView_Release(uav); + ID3D11RenderTargetView_Release(rtv); + ID3D11ShaderResourceView_Release(srv); + ID3D11Texture2D_Release(texture); + release_test_context(&test_context); +} + static void test_sample_mask(void) { static const DWORD ps_code[] = @@ -27099,6 +27548,7 @@ START_TEST(d3d11) test_unbound_multisample_texture(); test_multiple_viewports(); test_multisample_resolve(); + test_sample_shading(); test_sample_mask(); test_depth_clip(); }
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com