Signed-off-by: Józef Kucia jkucia@codeweavers.com ---
Fixes https://bugs.winehq.org/show_bug.cgi?id=43131
--- dlls/wined3d/glsl_shader.c | 3 ++- dlls/wined3d/shader.c | 3 ++- dlls/wined3d/shader_sm4.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index 0ff9ee44bb26..31810d6ddf29 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -6606,10 +6606,11 @@ static void shader_glsl_texkill(const struct wined3d_shader_instruction *ins) { if (ins->ctx->reg_maps->shader_version.major >= 4) { + const char *condition = ins->flags == WINED3D_SHADER_CONDITIONAL_OP_NZ ? "bool" : "!bool"; struct glsl_src_param src_param;
shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src_param); - shader_addline(ins->ctx->buffer, "if (bool(%s)) discard;\n", src_param.param_str); + shader_addline(ins->ctx->buffer, "if (%s(%s)) discard;\n", condition, src_param.param_str); } else { diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c index 3707d1587f9d..c4eed76d78f0 100644 --- a/dlls/wined3d/shader.c +++ b/dlls/wined3d/shader.c @@ -2958,7 +2958,8 @@ static void shader_trace_init(const struct wined3d_shader_frontend *fe, void *fe if (ins.handler_idx == WINED3DSIH_BREAKP || ins.handler_idx == WINED3DSIH_CONTINUEP || ins.handler_idx == WINED3DSIH_IF - || ins.handler_idx == WINED3DSIH_RETP) + || ins.handler_idx == WINED3DSIH_RETP + || ins.handler_idx == WINED3DSIH_TEXKILL) { switch (ins.flags) { diff --git a/dlls/wined3d/shader_sm4.c b/dlls/wined3d/shader_sm4.c index a04debe264d9..2665a67b80a6 100644 --- a/dlls/wined3d/shader_sm4.c +++ b/dlls/wined3d/shader_sm4.c @@ -894,7 +894,8 @@ static const struct wined3d_sm4_opcode_info opcode_table[] = {WINED3D_SM4_OP_DEFAULT, WINED3DSIH_DEFAULT, "", ""}, {WINED3D_SM4_OP_DERIV_RTX, WINED3DSIH_DSX, "f", "f"}, {WINED3D_SM4_OP_DERIV_RTY, WINED3DSIH_DSY, "f", "f"}, - {WINED3D_SM4_OP_DISCARD, WINED3DSIH_TEXKILL, "", "u"}, + {WINED3D_SM4_OP_DISCARD, WINED3DSIH_TEXKILL, "", "u", + shader_sm4_read_conditional_op}, {WINED3D_SM4_OP_DIV, WINED3DSIH_DIV, "f", "ff"}, {WINED3D_SM4_OP_DP2, WINED3DSIH_DP2, "f", "ff"}, {WINED3D_SM4_OP_DP3, WINED3DSIH_DP3, "f", "ff"},
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/wined3d/glsl_shader.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index 31810d6ddf29..fa1b8603f7af 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -5070,13 +5070,20 @@ static void shader_glsl_default(const struct wined3d_shader_instruction *ins) shader_addline(ins->ctx->buffer, "default:\n"); }
-static void shader_glsl_if(const struct wined3d_shader_instruction *ins) +static void shader_glsl_generate_conditional_op(const struct wined3d_shader_instruction *ins, + const char *op) { - const char *condition = (ins->flags == WINED3D_SHADER_CONDITIONAL_OP_NZ) ? "bool" : "!bool"; - struct glsl_src_param src0_param; + struct glsl_src_param src_param; + const char *condition;
- shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param); - shader_addline(ins->ctx->buffer, "if (%s(%s)) {\n", condition, src0_param.param_str); + condition = ins->flags == WINED3D_SHADER_CONDITIONAL_OP_NZ ? "bool" : "!bool"; + shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src_param); + shader_addline(ins->ctx->buffer, "if (%s(%s)) %s\n", condition, src_param.param_str, op); +} + +static void shader_glsl_if(const struct wined3d_shader_instruction *ins) +{ + shader_glsl_generate_conditional_op(ins, "{"); }
static void shader_glsl_ifc(const struct wined3d_shader_instruction *ins) @@ -5130,22 +5137,19 @@ static void shader_glsl_breakc(const struct wined3d_shader_instruction *ins)
static void shader_glsl_conditional_op(const struct wined3d_shader_instruction *ins) { - const char *condition = (ins->flags == WINED3D_SHADER_CONDITIONAL_OP_NZ) ? "bool" : "!bool"; - struct glsl_src_param src_param; const char *op;
switch (ins->handler_idx) { - case WINED3DSIH_BREAKP: op = "break"; break; - case WINED3DSIH_CONTINUEP: op = "continue"; break; - case WINED3DSIH_RETP: op = "return"; break; + case WINED3DSIH_BREAKP: op = "break;"; break; + case WINED3DSIH_CONTINUEP: op = "continue;"; break; + case WINED3DSIH_RETP: op = "return;"; break; default: ERR("Unhandled opcode %#x.\n", ins->handler_idx); return; }
- shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src_param); - shader_addline(ins->ctx->buffer, "if (%s(%s)) %s;\n", condition, src_param.param_str, op); + shader_glsl_generate_conditional_op(ins, op); }
static void shader_glsl_continue(const struct wined3d_shader_instruction *ins) @@ -6606,11 +6610,7 @@ static void shader_glsl_texkill(const struct wined3d_shader_instruction *ins) { if (ins->ctx->reg_maps->shader_version.major >= 4) { - const char *condition = ins->flags == WINED3D_SHADER_CONDITIONAL_OP_NZ ? "bool" : "!bool"; - struct glsl_src_param src_param; - - shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src_param); - shader_addline(ins->ctx->buffer, "if (%s(%s)) discard;\n", condition, src_param.param_str); + shader_glsl_generate_conditional_op(ins, "discard;"); } else {
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 59f2e6ef9fc6..2447cd771ce3 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -12991,6 +12991,102 @@ static void test_sm4_continuec_instruction(void) release_test_context(&test_context); }
+static void test_sm4_discard_instruction(void) +{ + ID3D11PixelShader *ps_discard_nz, *ps_discard_z; + struct d3d11_test_context test_context; + ID3D11DeviceContext *context; + ID3D11Device *device; + ID3D11Buffer *cb; + unsigned int i; + HRESULT hr; + + static const DWORD ps_discard_nz_code[] = + { +#if 0 + uint data; + + float4 main() : SV_Target + { + if (data) + discard; + return float4(0.0f, 0.5f, 0.0f, 1.0f); + } +#endif + 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016, + 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d, + 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, + 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e, + }; + static const DWORD ps_discard_z_code[] = + { +#if 0 + uint data; + + float4 main() : SV_Target + { + if (!data) + discard; + return float4(0.0f, 1.0f, 0.0f, 1.0f); + } +#endif + 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016, + 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d, + 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, + 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, + }; + static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; + static const struct uvec4 values[] = + { + {0x0000000}, + {0x0000001}, + {0x8000000}, + {0xfffffff}, + }; + + if (!init_test_context(&test_context, NULL)) + return; + + device = test_context.device; + context = test_context.immediate_context; + + cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*values), NULL); + ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb); + + hr = ID3D11Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code), + NULL, &ps_discard_nz); + ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr); + hr = ID3D11Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code), + NULL, &ps_discard_z); + ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(values); ++i) + { + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &values[i], 0, 0); + + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + ID3D11DeviceContext_PSSetShader(context, ps_discard_nz, NULL, 0); + draw_quad(&test_context); + check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1); + + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + ID3D11DeviceContext_PSSetShader(context, ps_discard_z, NULL, 0); + draw_quad(&test_context); + check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1); + } + + ID3D11Buffer_Release(cb); + ID3D11PixelShader_Release(ps_discard_nz); + ID3D11PixelShader_Release(ps_discard_z); + release_test_context(&test_context); +} + static void test_sm5_swapc_instruction(void) { struct input @@ -22506,6 +22602,7 @@ START_TEST(d3d11) test_sm4_if_instruction(); test_sm4_breakc_instruction(); test_sm4_continuec_instruction(); + test_sm4_discard_instruction(); test_sm5_swapc_instruction(); test_create_input_layout(); test_input_assembler();
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d10core/tests/device.c | 93 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+)
diff --git a/dlls/d3d10core/tests/device.c b/dlls/d3d10core/tests/device.c index f9478113ea6a..4228773eb4ae 100644 --- a/dlls/d3d10core/tests/device.c +++ b/dlls/d3d10core/tests/device.c @@ -9715,6 +9715,98 @@ static void test_sm4_continuec_instruction(void) release_test_context(&test_context); }
+static void test_sm4_discard_instruction(void) +{ + ID3D10PixelShader *ps_discard_nz, *ps_discard_z; + struct d3d10core_test_context test_context; + ID3D10Device *device; + ID3D10Buffer *cb; + unsigned int i; + HRESULT hr; + + static const DWORD ps_discard_nz_code[] = + { +#if 0 + uint data; + + float4 main() : SV_Target + { + if (data) + discard; + return float4(0.0f, 0.5f, 0.0f, 1.0f); + } +#endif + 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016, + 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d, + 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, + 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e, + }; + static const DWORD ps_discard_z_code[] = + { +#if 0 + uint data; + + float4 main() : SV_Target + { + if (!data) + discard; + return float4(0.0f, 1.0f, 0.0f, 1.0f); + } +#endif + 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016, + 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d, + 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, + 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, + }; + static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; + static const struct uvec4 values[] = + { + {0x0000000}, + {0x0000001}, + {0x8000000}, + {0xfffffff}, + }; + + if (!init_test_context(&test_context)) + return; + + device = test_context.device; + + cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(*values), NULL); + ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb); + + hr = ID3D10Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code), &ps_discard_nz); + ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr); + hr = ID3D10Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code), &ps_discard_z); + ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(values); ++i) + { + ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &values[i], 0, 0); + + ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white); + ID3D10Device_PSSetShader(device, ps_discard_nz); + draw_quad(&test_context); + check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1); + + ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white); + ID3D10Device_PSSetShader(device, ps_discard_z); + draw_quad(&test_context); + check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1); + } + + ID3D10Buffer_Release(cb); + ID3D10PixelShader_Release(ps_discard_nz); + ID3D10PixelShader_Release(ps_discard_z); + release_test_context(&test_context); +} + static void test_create_input_layout(void) { D3D10_INPUT_ELEMENT_DESC layout_desc[] = @@ -12979,6 +13071,7 @@ START_TEST(device) test_sm4_if_instruction(); test_sm4_breakc_instruction(); test_sm4_continuec_instruction(); + test_sm4_discard_instruction(); test_create_input_layout(); test_input_assembler(); test_null_sampler();
Hi,
While running your changed tests on Windows, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check? Full results can be found at https://testbot.winehq.org/JobDetails.pl?Key=34352
Your paranoid android.
=== wvistau64 (32 bit device) === device.c:4105: Test failed: Got unexpected IAVertices count: 0. device.c:4106: Test failed: Got unexpected IAPrimitives count: 0. device.c:4107: Test failed: Got unexpected VSInvocations count: 0. device.c:4110: Test failed: Got unexpected CInvocations count: 0. device.c:4111: Test failed: Got unexpected CPrimitives count: 0.
=== wvistau64 (64 bit device) === device.c:4105: Test failed: Got unexpected IAVertices count: 0. device.c:4106: Test failed: Got unexpected IAPrimitives count: 0. device.c:4107: Test failed: Got unexpected VSInvocations count: 0. device.c:4110: Test failed: Got unexpected CInvocations count: 0. device.c:4111: Test failed: Got unexpected CPrimitives count: 0.