In D3D10+ all clip distances declared in a shader are always enabled. In other words, enablement of clip distances is a property of a shader.
Signed-off-by: Józef Kucia jkucia@codeweavers.com ---
From wined3d API standpoint, the RS_CLIPPLANEENABLE state is ignored
when SM4+ shaders are active. We shouldn't touch the RS_CLIPPLANEENABLE state when SM4+ shaders are in use.
Fixes https://bugs.winehq.org/show_bug.cgi?id=43932
--- dlls/wined3d/glsl_shader.c | 63 ++++++++++++++++++++++++++++++++++-------- dlls/wined3d/shader.c | 36 +++++++++++++++++++++++- dlls/wined3d/wined3d_private.h | 43 ++++++++++++++-------------- 3 files changed, 109 insertions(+), 33 deletions(-)
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index 5d08c00175eb..b89b7aa3d53c 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -241,7 +241,10 @@ struct glsl_shader_prog_link struct glsl_cs_program cs; GLuint id; DWORD constant_update_mask; - UINT constant_version; + unsigned int constant_version; + DWORD shader_controlled_clip_distances : 1; + DWORD clip_distance_mask : 8; /* MAX_CLIP_DISTANCES, 8 */ + DWORD padding : 23; };
struct glsl_program_key @@ -6923,6 +6926,26 @@ static void shader_glsl_setup_sm4_shader_output(struct shader_glsl_priv *priv, } }
+static void shader_glsl_generate_clip_or_cull_distances(struct wined3d_string_buffer *buffer, + const struct wined3d_shader_signature_element *element, DWORD clip_or_cull_distance_mask) +{ + unsigned int i, clip_or_cull_index; + char reg_mask[6]; + + /* Assign consecutive indices starting from 0. */ + clip_or_cull_index = element->semantic_idx ? wined3d_popcount(clip_or_cull_distance_mask & 0xf) : 0; + for (i = 0; i < 4; ++i) + { + if (!(element->mask & (WINED3DSP_WRITEMASK_0 << i))) + continue; + + shader_glsl_write_mask_to_str(WINED3DSP_WRITEMASK_0 << i, reg_mask); + shader_addline(buffer, "gl_ClipDistance[%u] = outputs[%u]%s;\n", + clip_or_cull_index, element->register_idx, reg_mask); + ++clip_or_cull_index; + } +} + static void shader_glsl_setup_sm3_rasterizer_input(struct shader_glsl_priv *priv, const struct wined3d_gl_info *gl_info, const DWORD *map, const struct wined3d_shader_signature *input_signature, @@ -6932,7 +6955,7 @@ static void shader_glsl_setup_sm3_rasterizer_input(struct shader_glsl_priv *priv { struct wined3d_string_buffer *buffer = &priv->shader_buffer; const char *semantic_name; - UINT semantic_idx; + unsigned int semantic_idx; char reg_mask[6]; unsigned int i;
@@ -6966,6 +6989,10 @@ static void shader_glsl_setup_sm3_rasterizer_input(struct shader_glsl_priv *priv shader_addline(buffer, "gl_Layer = floatBitsToInt(outputs[%u])%s;\n", output->register_idx, reg_mask); } + else if (output->sysval_semantic == WINED3D_SV_CLIP_DISTANCE) + { + shader_glsl_generate_clip_or_cull_distances(buffer, output, reg_maps_out->clip_distance_mask); + } else if (output->sysval_semantic) { FIXME("Unhandled sysval semantic %#x.\n", output->sysval_semantic); @@ -9852,6 +9879,7 @@ static HRESULT shader_glsl_compile_compute_shader(struct shader_glsl_priv *priv, entry->ps.id = 0; entry->cs.id = shader_id; entry->constant_version = 0; + entry->shader_controlled_clip_distances = 0; entry->ps.np2_fixup_info = NULL; add_glsl_program_entry(priv, entry);
@@ -9926,11 +9954,12 @@ static void set_glsl_compute_shader_program(const struct wined3d_context *contex static void set_glsl_shader_program(const struct wined3d_context *context, const struct wined3d_state *state, struct shader_glsl_priv *priv, struct glsl_context_data *ctx_data) { - const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_d3d_info *d3d_info = context->d3d_info; + const struct wined3d_gl_info *gl_info = context->gl_info; + const struct wined3d_shader *pre_rasterization_shader; const struct ps_np2fixup_info *np2fixup_info = NULL; - struct glsl_shader_prog_link *entry = NULL; struct wined3d_shader *hshader, *dshader, *gshader; + struct glsl_shader_prog_link *entry = NULL; struct wined3d_shader *vshader = NULL; struct wined3d_shader *pshader = NULL; GLuint reorder_shader_id = 0; @@ -10068,6 +10097,7 @@ static void set_glsl_shader_program(const struct wined3d_context *context, const entry->ps.id = ps_id; entry->cs.id = 0; entry->constant_version = 0; + entry->shader_controlled_clip_distances = 0; entry->ps.np2_fixup_info = np2fixup_info; /* Add the hash table entry */ add_glsl_program_entry(priv, entry); @@ -10194,7 +10224,15 @@ static void set_glsl_shader_program(const struct wined3d_context *context, const shader_glsl_init_gs_uniform_locations(gl_info, priv, program_id, &entry->gs); shader_glsl_init_ps_uniform_locations(gl_info, priv, program_id, &entry->ps, pshader ? pshader->limits->constant_float : 0); - checkGLcall("Find glsl program uniform locations"); + checkGLcall("find glsl program uniform locations"); + + pre_rasterization_shader = gshader ? gshader : dshader ? dshader : vshader; + if (pre_rasterization_shader && pre_rasterization_shader->reg_maps.shader_version.major >= 4) + { + unsigned int clip_distance_count = wined3d_popcount(pre_rasterization_shader->reg_maps.clip_distance_mask); + entry->shader_controlled_clip_distances = 1; + entry->clip_distance_mask = (1u << clip_distance_count) - 1; + }
if (needs_legacy_glsl_syntax(gl_info)) { @@ -10350,6 +10388,7 @@ static void shader_glsl_select(void *shader_priv, struct wined3d_context *contex struct glsl_context_data *ctx_data = context->shader_backend_data; const struct wined3d_gl_info *gl_info = context->gl_info; struct shader_glsl_priv *priv = shader_priv; + struct glsl_shader_prog_link *glsl_program; GLenum current_vertex_color_clamp; GLuint program_id, prev_id;
@@ -10357,13 +10396,15 @@ static void shader_glsl_select(void *shader_priv, struct wined3d_context *contex priv->fragment_pipe->enable_extension(gl_info, !use_ps(state));
prev_id = ctx_data->glsl_program ? ctx_data->glsl_program->id : 0; - set_glsl_shader_program(context, state, priv, ctx_data); + glsl_program = ctx_data->glsl_program;
- if (ctx_data->glsl_program) + if (glsl_program) { - program_id = ctx_data->glsl_program->id; - current_vertex_color_clamp = ctx_data->glsl_program->vs.vertex_color_clamp; + program_id = glsl_program->id; + current_vertex_color_clamp = glsl_program->vs.vertex_color_clamp; + if (glsl_program->shader_controlled_clip_distances) + context_enable_clip_distances(context, glsl_program->clip_distance_mask); } else { @@ -10392,8 +10433,8 @@ static void shader_glsl_select(void *shader_priv, struct wined3d_context *contex GL_EXTCALL(glUseProgram(program_id)); checkGLcall("glUseProgram");
- if (program_id) - context->constant_update_mask |= ctx_data->glsl_program->constant_update_mask; + if (glsl_program) + context->constant_update_mask |= glsl_program->constant_update_mask; }
context->shader_update_mask |= (1u << WINED3D_SHADER_TYPE_COMPUTE); diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c index c4eed76d78f0..7d59f8b9a042 100644 --- a/dlls/wined3d/shader.c +++ b/dlls/wined3d/shader.c @@ -952,6 +952,31 @@ static HRESULT shader_record_shader_phase(struct wined3d_shader *shader, return WINED3D_OK; }
+static HRESULT shader_calculate_clip_or_cull_distance_mask( + const struct wined3d_shader_signature_element *e, DWORD *mask) +{ + unsigned int i; + + *mask = 0; + + /* Cull and clip distances are packed in 4 component registers. 0 and 1 are + * the only allowed semantic indices. + */ + if (e->semantic_idx >= MAX_CLIP_DISTANCES / 4) + { + WARN("Invalid clip/cull distance index %u.\n", e->semantic_idx); + return WINED3DERR_INVALIDCALL; + } + + for (i = 0; i < 4; ++i) + { + if (e->mask & (WINED3DSP_WRITEMASK_0 << i)) + *mask |= 1u << (4 * e->semantic_idx + i); + } + + return WINED3D_OK; +} + static void wined3d_insert_interpolation_mode(DWORD *packed_interpolation_mode, unsigned int register_idx, enum wined3d_shader_interpolation_mode mode) { @@ -1754,7 +1779,16 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st { for (i = 0; i < output_signature->element_count; ++i) { - reg_maps->output_registers |= 1u << output_signature->elements[i].register_idx; + const struct wined3d_shader_signature_element *e = &output_signature->elements[i]; + DWORD mask; + + reg_maps->output_registers |= 1u << e->register_idx; + if (e->sysval_semantic == WINED3D_SV_CLIP_DISTANCE) + { + if (FAILED(hr = shader_calculate_clip_or_cull_distance_mask(e, &mask))) + return hr; + reg_maps->clip_distance_mask |= mask; + } } } else if (reg_maps->output_registers) diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index da06ba159f79..b8f0b4d194e0 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1006,31 +1006,32 @@ struct wined3d_shader_reg_maps BYTE bumpmat; /* MAX_TEXTURES, 8 */ BYTE luminanceparams; /* MAX_TEXTURES, 8 */ struct wined3d_shader_resource_info uav_resource_info[MAX_UNORDERED_ACCESS_VIEWS]; - DWORD uav_read_mask; /* MAX_UNORDERED_ACCESS_VIEWS, 8 */ - DWORD uav_counter_mask; /* MAX_UNORDERED_ACCESS_VIEWS, 8 */ - - WORD usesnrm : 1; - WORD vpos : 1; - WORD usesdsx : 1; - WORD usesdsy : 1; - WORD usestexldd : 1; - WORD usesmova : 1; - WORD usesfacing : 1; - WORD usesrelconstF : 1; - WORD fog : 1; - WORD usestexldl : 1; - WORD usesifc : 1; - WORD usescall : 1; - WORD usespow : 1; - WORD point_size : 1; - WORD vocp : 1; - WORD padding : 1; + DWORD uav_read_mask : 8; /* MAX_UNORDERED_ACCESS_VIEWS, 8 */ + DWORD uav_counter_mask : 8; /* MAX_UNORDERED_ACCESS_VIEWS, 8 */ + + DWORD clip_distance_mask : 8; /* MAX_CLIP_DISTANCES, 8 */ + DWORD usesnrm : 1; + DWORD vpos : 1; + DWORD usesdsx : 1; + DWORD usesdsy : 1; + DWORD usestexldd : 1; + DWORD usesmova : 1; + DWORD usesfacing : 1; + DWORD usesrelconstF : 1; + DWORD fog : 1; + DWORD usestexldl : 1; + DWORD usesifc : 1; + DWORD usescall : 1; + DWORD usespow : 1; + DWORD point_size : 1; + DWORD vocp : 1; + DWORD padding : 25;
DWORD rt_mask; /* Used render targets, 32 max. */
/* Whether or not loops are used in this shader, and nesting depth */ - unsigned loop_depth; - UINT min_rel_offset, max_rel_offset; + unsigned int loop_depth; + unsigned int min_rel_offset, max_rel_offset;
struct wined3d_shader_tgsm *tgsm; SIZE_T tgsm_capacity;
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 584 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 574 insertions(+), 10 deletions(-)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 906761dd337d..341350382fd3 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -1267,12 +1267,13 @@ static void draw_quad_vs(unsigned int line, struct d3d11_test_context *context, vs_code, vs_code_size, &context->input_layout); ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
- context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad); - hr = ID3D11Device_CreateVertexShader(device, vs_code, vs_code_size, NULL, &context->vs); ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr); }
+ if (!context->vb) + context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad); + ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout); ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); stride = sizeof(*quad); @@ -12116,13 +12117,6 @@ float4 main(const ps_in v) : SV_TARGET 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e, }; - static const struct vec2 quad[] = - { - {-1.0f, -1.0f}, - {-1.0f, 1.0f}, - { 1.0f, -1.0f}, - { 1.0f, 1.0f}, - }; static const struct { float color[4]; @@ -12172,7 +12166,6 @@ float4 main(const ps_in v) : SV_TARGET vs_code, sizeof(vs_code), &test_context.input_layout); ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
- test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad); colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors); index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
@@ -22563,6 +22556,576 @@ static void test_format_compatibility(void) ok(!refcount, "Device has %u references left.\n", refcount); }
+static void check_clip_distance(struct d3d11_test_context *test_context, ID3D11Buffer *vb) +{ + static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; + struct vertex + { + float clip_distance0; + float clip_distance1; + }; + + ID3D11DeviceContext *context = test_context->immediate_context; + struct resource_readback rb; + struct vertex vertices[4]; + unsigned int i; + RECT rect; + + for (i = 0; i < ARRAY_SIZE(vertices); ++i) + vertices[i].clip_distance0 = 1.0f; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0); + ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white); + ID3D11DeviceContext_Draw(context, 4, 0); + check_texture_color(test_context->backbuffer, 0xff00ff00, 1); + + for (i = 0; i < ARRAY_SIZE(vertices); ++i) + vertices[i].clip_distance0 = 0.0f; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0); + ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white); + ID3D11DeviceContext_Draw(context, 4, 0); + check_texture_color(test_context->backbuffer, 0xff00ff00, 1); + + for (i = 0; i < ARRAY_SIZE(vertices); ++i) + vertices[i].clip_distance0 = -1.0f; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0); + ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white); + ID3D11DeviceContext_Draw(context, 4, 0); + check_texture_color(test_context->backbuffer, 0xffffffff, 1); + + for (i = 0; i < ARRAY_SIZE(vertices); ++i) + vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0); + ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white); + ID3D11DeviceContext_Draw(context, 4, 0); + get_texture_readback(test_context->backbuffer, 0, &rb); + SetRect(&rect, 0, 0, 320, 480); + check_readback_data_color(&rb, &rect, 0xff00ff00, 1); + SetRect(&rect, 320, 0, 320, 480); + check_readback_data_color(&rb, &rect, 0xffffffff, 1); + release_resource_readback(&rb); + + for (i = 0; i < ARRAY_SIZE(vertices); ++i) + vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0); + ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white); + ID3D11DeviceContext_Draw(context, 4, 0); + get_texture_readback(test_context->backbuffer, 0, &rb); + SetRect(&rect, 0, 0, 640, 240); + check_readback_data_color(&rb, &rect, 0xff00ff00, 1); + SetRect(&rect, 0, 240, 640, 240); + check_readback_data_color(&rb, &rect, 0xffffffff, 1); + release_resource_readback(&rb); +} + +static void test_clip_distance(void) +{ + struct d3d11_test_context test_context; + ID3D11Buffer *vs_cb, *tess_cb, *gs_cb; + D3D_FEATURE_LEVEL feature_level; + ID3D11DomainShader *ds = NULL; + ID3D11DeviceContext *context; + struct resource_readback rb; + unsigned int offset, stride; + ID3D11HullShader *hs = NULL; + ID3D11GeometryShader *gs; + ID3D11Device *device; + ID3D11Buffer *vb; + unsigned int i; + HRESULT hr; + RECT rect; + + static const DWORD vs_code[] = + { +#if 0 + bool use_constant; + float clip_distance; + + struct input + { + float4 position : POSITION; + float distance0 : CLIP_DISTANCE0; + float distance1 : CLIP_DISTANCE1; + }; + + struct vertex + { + float4 position : SV_POSITION; + float user_clip : CLIP_DISTANCE; + float clip : SV_ClipDistance; + }; + + void main(input vin, out vertex vertex) + { + vertex.position = vin.position; + vertex.user_clip = vin.distance0; + vertex.clip = vin.distance0; + if (use_constant) + vertex.clip = clip_distance; + } +#endif + 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003, + 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050, + 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000, + 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002, + 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f, + 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, + 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, + 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, + 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, + 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, + 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2, + 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002, + 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, + 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000, + 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e, + }; + static const DWORD vs_multiple_code[] = + { +#if 0 + bool use_constant; + float clip_distance0; + float clip_distance1; + + struct input + { + float4 position : POSITION; + float distance0 : CLIP_DISTANCE0; + float distance1 : CLIP_DISTANCE1; + }; + + struct vertex + { + float4 position : SV_POSITION; + float user_clip : CLIP_DISTANCE; + float2 clip : SV_ClipDistance; + }; + + void main(input vin, out vertex vertex) + { + vertex.position = vin.position; + vertex.user_clip = vin.distance0; + vertex.clip.x = vin.distance0; + if (use_constant) + vertex.clip.x = clip_distance0; + vertex.clip.y = vin.distance1; + if (use_constant) + vertex.clip.y = clip_distance1; + } +#endif + 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003, + 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050, + 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000, + 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002, + 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f, + 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, + 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, + 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49, + 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, + 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, + 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012, + 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, + 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, + 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, + 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, + 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a, + 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e, + }; +#if 0 + bool use_constant; + float clip_distance0; + float clip_distance1; + float tessellation_factor; + + struct vertex + { + float4 position : SV_POSITION; + float user_clip : CLIP_DISTANCE; + float clip : SV_ClipDistance; + }; + + struct patch_constant_data + { + float edges[4] : SV_TessFactor; + float inside[2] : SV_InsideTessFactor; + }; + + patch_constant_data patch_constant() + { + patch_constant_data output; + + output.edges[0] = tessellation_factor; + output.edges[1] = tessellation_factor; + output.edges[2] = tessellation_factor; + output.edges[3] = tessellation_factor; + output.inside[0] = tessellation_factor; + output.inside[1] = tessellation_factor; + + return output; + } + + [domain("quad")] + [outputcontrolpoints(4)] + [outputtopology("triangle_cw")] + [partitioning("pow2")] + [patchconstantfunc("patch_constant")] + vertex hs_main(InputPatch<vertex, 4> input, + uint i : SV_OutputControlPointID) + { + vertex o; + o.position = input[i].position; + o.user_clip = input[i].user_clip; + o.clip = input[i].user_clip; + return o; + } + + float4 interpolate_vec(float4 a, float4 b, float4 c, float4 d, float2 tess_coord) + { + float4 e = lerp(a, b, tess_coord.x); + float4 f = lerp(c, d, tess_coord.x); + return lerp(e, f, tess_coord.y); + } + + float interpolate(float a, float b, float c, float d, float2 tess_coord) + { + float e = lerp(a, b, tess_coord.x); + float f = lerp(c, d, tess_coord.x); + return lerp(e, f, tess_coord.y); + } + + [domain("quad")] + vertex ds_main(patch_constant_data input, + float2 tess_coord : SV_DomainLocation, + const OutputPatch<vertex, 4> patch) + { + vertex output; + + output.position = interpolate_vec(patch[0].position, patch[1].position, + patch[2].position, patch[3].position, tess_coord); + output.user_clip = interpolate(patch[0].user_clip, patch[1].user_clip, + patch[2].user_clip, patch[3].user_clip, tess_coord); + output.clip = interpolate(patch[0].clip, patch[1].clip, + patch[2].clip, patch[3].clip, tess_coord); + if (use_constant) + output.clip = clip_distance0; + + return output; + } +#endif + static const DWORD hs_code[] = + { + 0x43425844, 0x5a6d7564, 0x5f30a6c9, 0x2cf3b848, 0x5b4c6dca, 0x00000001, 0x00000414, 0x00000004, + 0x00000030, 0x000000b4, 0x00000138, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, + 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, + 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, + 0x00000002, 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, + 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, + 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, + 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, + 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, + 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc, + 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01, + 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002, + 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003, + 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01, + 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365, + 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, + 0x00000210, 0x00030050, 0x00000084, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01001096, + 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x01000072, 0x0200005f, + 0x00016000, 0x0400005f, 0x002010f2, 0x00000004, 0x00000000, 0x0400005f, 0x00201012, 0x00000004, + 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x00102012, 0x00000001, 0x03000065, + 0x00102012, 0x00000002, 0x02000068, 0x00000001, 0x04000036, 0x00100012, 0x00000000, 0x00016001, + 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x07000036, + 0x00102012, 0x00000001, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x07000036, 0x00102012, + 0x00000002, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x0100003e, 0x01000073, 0x02000099, + 0x00000004, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x0000000b, 0x04000067, + 0x00102012, 0x00000001, 0x0000000c, 0x04000067, 0x00102012, 0x00000002, 0x0000000d, 0x04000067, + 0x00102012, 0x00000003, 0x0000000e, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000000, + 0x00000004, 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x07000036, 0x00902012, 0x0010000a, + 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002, + 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000004, 0x0000000f, 0x04000067, 0x00102012, + 0x00000005, 0x00000010, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000004, 0x00000002, + 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x08000036, 0x00d02012, 0x00000004, 0x0010000a, + 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, + }; + static const DWORD ds_code[] = + { + 0x43425844, 0xc54dc020, 0x063a9622, 0x6f649eb9, 0xceb1dd36, 0x00000001, 0x0000054c, 0x00000004, + 0x00000030, 0x000000b4, 0x00000178, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, + 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, + 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, + 0x00000002, 0x00000101, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, + 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc, 0x00000006, + 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000001, 0x00000098, + 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000001, 0x00000098, 0x00000002, 0x0000000b, + 0x00000003, 0x00000002, 0x00000001, 0x00000098, 0x00000003, 0x0000000b, 0x00000003, 0x00000003, + 0x00000001, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000001, 0x000000a6, + 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, + 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000007c, + 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, + 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, + 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, + 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x58454853, + 0x00000348, 0x00040050, 0x000000d2, 0x01002093, 0x01001895, 0x0100086a, 0x04000059, 0x00208e46, + 0x00000000, 0x00000001, 0x0200005f, 0x0001c032, 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, + 0x0400005f, 0x00219012, 0x00000004, 0x00000001, 0x0400005f, 0x00219012, 0x00000004, 0x00000002, + 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, + 0x00102012, 0x00000002, 0x00000002, 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, + 0x80219e46, 0x00000041, 0x00000002, 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, + 0x001000f2, 0x00000000, 0x0001c006, 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, + 0x0a000000, 0x001000f2, 0x00000001, 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, + 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, + 0x00219e46, 0x00000000, 0x00000000, 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, + 0x80100e46, 0x00000041, 0x00000001, 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, + 0x00000000, 0x00100e46, 0x00000001, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041, + 0x00000002, 0x00000001, 0x0021900a, 0x00000003, 0x00000001, 0x09000032, 0x00100012, 0x00000000, + 0x0001c00a, 0x0010000a, 0x00000000, 0x0021900a, 0x00000002, 0x00000001, 0x0a000000, 0x00100022, + 0x00000000, 0x8021900a, 0x00000041, 0x00000000, 0x00000001, 0x0021900a, 0x00000001, 0x00000001, + 0x09000032, 0x00100022, 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000, + 0x00000001, 0x08000000, 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a, + 0x00000000, 0x08000032, 0x00102012, 0x00000001, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a, + 0x00000000, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041, 0x00000002, 0x00000002, + 0x0021900a, 0x00000003, 0x00000002, 0x09000032, 0x00100012, 0x00000000, 0x0001c00a, 0x0010000a, + 0x00000000, 0x0021900a, 0x00000002, 0x00000002, 0x0a000000, 0x00100022, 0x00000000, 0x8021900a, + 0x00000041, 0x00000000, 0x00000002, 0x0021900a, 0x00000001, 0x00000002, 0x09000032, 0x00100022, + 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000, 0x00000002, 0x08000000, + 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a, 0x00000000, 0x08000032, + 0x00100012, 0x00000000, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000, 0x0b000037, + 0x00102012, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, + 0x0010000a, 0x00000000, 0x0100003e, + }; + static const DWORD gs_code[] = + { +#if 0 + bool use_constant; + float clip_distance; + + struct vertex + { + float4 position : SV_POSITION; + float user_clip : CLIP_DISTANCE; + float clip : SV_ClipDistance; + }; + + [maxvertexcount(3)] + void main(triangle vertex input[3], inout TriangleStream<vertex> output) + { + vertex o; + o = input[0]; + o.clip = input[0].user_clip; + if (use_constant) + o.clip = clip_distance; + output.Append(o); + o = input[1]; + o.clip = input[1].user_clip; + if (use_constant) + o.clip = clip_distance; + output.Append(o); + o = input[2]; + o.clip = input[2].user_clip; + if (use_constant) + o.clip = clip_distance; + output.Append(o); + } +#endif + 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003, + 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, + 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002, + 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, + 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008, + 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, + 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, + 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, + 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040, + 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, + 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012, + 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, + 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002, + 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000, + 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037, + 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, + 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, + 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036, + 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, + 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001, + 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036, + 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001, + 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, + 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036, + 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e, + }; + static const D3D11_INPUT_ELEMENT_DESC layout_desc[] = + { + {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0}, + }; + struct + { + float clip_distance0; + float clip_distance1; + } + vertices[] = + { + {1.0f, 1.0f}, + {1.0f, 1.0f}, + {1.0f, 1.0f}, + {1.0f, 1.0f}, + }; + static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; + static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f}; + struct + { + BOOL use_constant; + float clip_distance0; + float clip_distance1; + float tessellation_factor; + } cb_data; + + if (!init_test_context(&test_context, NULL)) + return; + device = test_context.device; + context = test_context.immediate_context; + feature_level = ID3D11Device_GetFeatureLevel(device); + + hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc), + vs_code, sizeof(vs_code), &test_context.input_layout); + ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr); + + vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices); + stride = sizeof(*vertices); + offset = 0; + ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset); + + hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs); + ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr); + + memset(&cb_data, 0, sizeof(cb_data)); + cb_data.tessellation_factor = 1.0f; + vs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data); + ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &vs_cb); + tess_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data); + ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &tess_cb); + ID3D11DeviceContext_DSSetConstantBuffers(context, 0, 1, &tess_cb); + gs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data); + ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &gs_cb); + + /* vertex shader */ + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + draw_color_quad(&test_context, &green); + check_texture_color(test_context.backbuffer, 0xff00ff00, 1); + + check_clip_distance(&test_context, vb); + + cb_data.use_constant = TRUE; + cb_data.clip_distance0 = -1.0f; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0); + + /* tessellation shaders */ + if (feature_level >= D3D_FEATURE_LEVEL_11_0) + { + ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST); + + hr = ID3D11Device_CreateHullShader(device, hs_code, sizeof(hs_code), NULL, &hs); + ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr); + ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0); + hr = ID3D11Device_CreateDomainShader(device, ds_code, sizeof(ds_code), NULL, &ds); + ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr); + ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0); + + check_clip_distance(&test_context, vb); + + cb_data.use_constant = FALSE; + cb_data.tessellation_factor = 2.0f; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0); + + for (i = 0; i < ARRAY_SIZE(vertices); ++i) + vertices[i].clip_distance0 = 1.0f; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0); + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + ID3D11DeviceContext_Draw(context, 4, 0); + check_texture_color(test_context.backbuffer, 0xff00ff00, 1); + + cb_data.use_constant = TRUE; + cb_data.clip_distance0 = -1.0f; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0); + } + else + { + skip("Tessellation shaders are not supported.\n"); + } + + /* geometry shader */ + hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs); + ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr); + ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0); + + check_clip_distance(&test_context, vb); + + cb_data.use_constant = TRUE; + cb_data.clip_distance0 = 1.0f; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)gs_cb, 0, NULL, &cb_data, 0, 0); + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + ID3D11DeviceContext_Draw(context, 4, 0); + check_texture_color(test_context.backbuffer, 0xff00ff00, 1); + + /* multiple clip distances */ + ID3D11DeviceContext_HSSetShader(context, NULL, NULL, 0); + ID3D11DeviceContext_DSSetShader(context, NULL, NULL, 0); + ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0); + + ID3D11VertexShader_Release(test_context.vs); + hr = ID3D11Device_CreateVertexShader(device, vs_multiple_code, sizeof(vs_multiple_code), + NULL, &test_context.vs); + ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr); + + cb_data.use_constant = FALSE; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0); + + for (i = 0; i < ARRAY_SIZE(vertices); ++i) + vertices[i].clip_distance0 = 1.0f; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0); + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + draw_color_quad(&test_context, &green); + check_texture_color(test_context.backbuffer, 0xff00ff00, 1); + + for (i = 0; i < ARRAY_SIZE(vertices); ++i) + { + vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f; + vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f; + } + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0); + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + draw_color_quad(&test_context, &green); + get_texture_readback(test_context.backbuffer, 0, &rb); + SetRect(&rect, 0, 0, 320, 240); + check_readback_data_color(&rb, &rect, 0xff00ff00, 1); + SetRect(&rect, 0, 240, 320, 480); + check_readback_data_color(&rb, &rect, 0xffffffff, 1); + SetRect(&rect, 320, 0, 640, 480); + check_readback_data_color(&rb, &rect, 0xffffffff, 1); + release_resource_readback(&rb); + + cb_data.use_constant = TRUE; + cb_data.clip_distance0 = 0.0f; + cb_data.clip_distance1 = 0.0f; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0); + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + draw_color_quad(&test_context, &green); + check_texture_color(test_context.backbuffer, 0xff00ff00, 1); + + if (hs) + ID3D11HullShader_Release(hs); + if (ds) + ID3D11DomainShader_Release(ds); + ID3D11GeometryShader_Release(gs); + ID3D11Buffer_Release(vb); + ID3D11Buffer_Release(vs_cb); + ID3D11Buffer_Release(tess_cb); + ID3D11Buffer_Release(gs_cb); + release_test_context(&test_context); +} + START_TEST(d3d11) { test_create_device(); @@ -22670,4 +23233,5 @@ START_TEST(d3d11) test_early_depth_stencil(); test_conservative_depth_output(); test_format_compatibility(); + test_clip_distance(); }
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/wined3d/directx.c | 2 ++ dlls/wined3d/glsl_shader.c | 13 +++++++++++-- dlls/wined3d/shader.c | 6 ++++++ dlls/wined3d/wined3d_gl.h | 1 + dlls/wined3d/wined3d_private.h | 3 ++- 5 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index e0bf98604428..5058740464a2 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -119,6 +119,7 @@ static const struct wined3d_extension_map gl_extension_map[] = {"GL_ARB_conservative_depth", ARB_CONSERVATIVE_DEPTH }, {"GL_ARB_copy_buffer", ARB_COPY_BUFFER }, {"GL_ARB_copy_image", ARB_COPY_IMAGE }, + {"GL_ARB_cull_distance", ARB_CULL_DISTANCE }, {"GL_ARB_debug_output", ARB_DEBUG_OUTPUT }, {"GL_ARB_depth_buffer_float", ARB_DEPTH_BUFFER_FLOAT }, {"GL_ARB_depth_texture", ARB_DEPTH_TEXTURE }, @@ -3916,6 +3917,7 @@ static BOOL wined3d_adapter_init_gl_caps(struct wined3d_adapter *adapter, {ARB_CLEAR_TEXTURE, MAKEDWORD_VERSION(4, 4)},
{ARB_CLIP_CONTROL, MAKEDWORD_VERSION(4, 5)}, + {ARB_CULL_DISTANCE, MAKEDWORD_VERSION(4, 5)}, {ARB_DERIVATIVE_CONTROL, MAKEDWORD_VERSION(4, 5)},
{ARB_PIPELINE_STATISTICS_QUERY, MAKEDWORD_VERSION(4, 6)}, diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index b89b7aa3d53c..976c7cdb6213 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -6930,8 +6930,10 @@ static void shader_glsl_generate_clip_or_cull_distances(struct wined3d_string_bu const struct wined3d_shader_signature_element *element, DWORD clip_or_cull_distance_mask) { unsigned int i, clip_or_cull_index; + const char *name; char reg_mask[6];
+ name = element->sysval_semantic == WINED3D_SV_CLIP_DISTANCE ? "Clip" : "Cull"; /* Assign consecutive indices starting from 0. */ clip_or_cull_index = element->semantic_idx ? wined3d_popcount(clip_or_cull_distance_mask & 0xf) : 0; for (i = 0; i < 4; ++i) @@ -6940,8 +6942,8 @@ static void shader_glsl_generate_clip_or_cull_distances(struct wined3d_string_bu continue;
shader_glsl_write_mask_to_str(WINED3DSP_WRITEMASK_0 << i, reg_mask); - shader_addline(buffer, "gl_ClipDistance[%u] = outputs[%u]%s;\n", - clip_or_cull_index, element->register_idx, reg_mask); + shader_addline(buffer, "gl_%sDistance[%u] = outputs[%u]%s;\n", + name, clip_or_cull_index, element->register_idx, reg_mask); ++clip_or_cull_index; } } @@ -6993,6 +6995,10 @@ static void shader_glsl_setup_sm3_rasterizer_input(struct shader_glsl_priv *priv { shader_glsl_generate_clip_or_cull_distances(buffer, output, reg_maps_out->clip_distance_mask); } + else if (output->sysval_semantic == WINED3D_SV_CULL_DISTANCE) + { + shader_glsl_generate_clip_or_cull_distances(buffer, output, reg_maps_out->cull_distance_mask); + } else if (output->sysval_semantic) { FIXME("Unhandled sysval semantic %#x.\n", output->sysval_semantic); @@ -7393,6 +7399,8 @@ static void shader_glsl_generate_alpha_test(struct wined3d_string_buffer *buffer static void shader_glsl_enable_extensions(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info) { + if (gl_info->supported[ARB_CULL_DISTANCE]) + shader_addline(buffer, "#extension GL_ARB_cull_distance : enable\n"); if (gl_info->supported[ARB_GPU_SHADER5]) shader_addline(buffer, "#extension GL_ARB_gpu_shader5 : enable\n"); if (gl_info->supported[ARB_SHADER_ATOMIC_COUNTERS]) @@ -10875,6 +10883,7 @@ static unsigned int shader_glsl_get_shader_model(const struct wined3d_gl_info *g
if (shader_model_4 && gl_info->supported[ARB_COMPUTE_SHADER] + && gl_info->supported[ARB_CULL_DISTANCE] && gl_info->supported[ARB_DERIVATIVE_CONTROL] && gl_info->supported[ARB_DRAW_INDIRECT] && gl_info->supported[ARB_GPU_SHADER5] diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c index 7d59f8b9a042..d9765731abb1 100644 --- a/dlls/wined3d/shader.c +++ b/dlls/wined3d/shader.c @@ -1789,6 +1789,12 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st return hr; reg_maps->clip_distance_mask |= mask; } + else if (e->sysval_semantic == WINED3D_SV_CULL_DISTANCE) + { + if (FAILED(hr = shader_calculate_clip_or_cull_distance_mask(e, &mask))) + return hr; + reg_maps->cull_distance_mask |= mask; + } } } else if (reg_maps->output_registers) diff --git a/dlls/wined3d/wined3d_gl.h b/dlls/wined3d/wined3d_gl.h index 455f4154a2a8..0894c946db83 100644 --- a/dlls/wined3d/wined3d_gl.h +++ b/dlls/wined3d/wined3d_gl.h @@ -52,6 +52,7 @@ enum wined3d_gl_extension ARB_CONSERVATIVE_DEPTH, ARB_COPY_BUFFER, ARB_COPY_IMAGE, + ARB_CULL_DISTANCE, ARB_DEBUG_OUTPUT, ARB_DEPTH_BUFFER_FLOAT, ARB_DEPTH_TEXTURE, diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index b8f0b4d194e0..6f1328084b84 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1010,6 +1010,7 @@ struct wined3d_shader_reg_maps DWORD uav_counter_mask : 8; /* MAX_UNORDERED_ACCESS_VIEWS, 8 */
DWORD clip_distance_mask : 8; /* MAX_CLIP_DISTANCES, 8 */ + DWORD cull_distance_mask : 8; /* MAX_CLIP_DISTANCES, 8 */ DWORD usesnrm : 1; DWORD vpos : 1; DWORD usesdsx : 1; @@ -1025,7 +1026,7 @@ struct wined3d_shader_reg_maps DWORD usespow : 1; DWORD point_size : 1; DWORD vocp : 1; - DWORD padding : 25; + DWORD padding : 17;
DWORD rt_mask; /* Used render targets, 32 max. */
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 209 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 341350382fd3..330f20123b3f 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -23126,6 +23126,214 @@ static void test_clip_distance(void) release_test_context(&test_context); }
+static void test_combined_clip_and_cull_distances(void) +{ + struct d3d11_test_context test_context; + ID3D11DeviceContext *context; + struct resource_readback rb; + unsigned int offset, stride; + ID3D11Device *device; + unsigned int i, j, k; + ID3D11Buffer *vb; + HRESULT hr; + + static const DWORD vs_code[] = + { +#if 0 + struct input + { + float4 position : POSITION; + float clip0 : CLIP_DISTANCE0; + float clip1 : CLIP_DISTANCE1; + float clip2 : CLIP_DISTANCE2; + float clip3 : CLIP_DISTANCE3; + float cull0 : CULL_DISTANCE0; + float cull1 : CULL_DISTANCE1; + float cull2 : CULL_DISTANCE2; + float cull3 : CULL_DISTANCE3; + }; + + struct vertex + { + float4 position : SV_Position; + float3 clip0 : SV_ClipDistance1; + float3 cull0 : SV_CullDistance1; + float clip1 : SV_ClipDistance2; + float cull1 : SV_CullDistance2; + }; + + void main(input vin, out vertex vertex) + { + vertex.position = vin.position; + vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2); + vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2); + vertex.clip1 = vin.clip3; + vertex.cull1 = vin.cull3; + } +#endif + 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003, + 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0, + 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000, + 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002, + 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9, + 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000, + 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006, + 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7, + 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, + 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f, + 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, + 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c, + 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003, + 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002, + 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e, + 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f, + 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012, + 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f, + 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007, + 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067, + 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067, + 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036, + 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, + 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042, + 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004, + 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002, + 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036, + 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e, + }; + static const D3D11_INPUT_ELEMENT_DESC layout_desc[] = + { + {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D11_INPUT_PER_VERTEX_DATA, 0}, + }; + struct + { + float clip_distance[4]; + float cull_distance[4]; + } + vertices[4] = + { + {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + }; + static const struct test + { + float vertices[4]; + BOOL triangle_visible[2]; + } + cull_distance_tests[] = + { + {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}}, + {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}}, + {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}}, + {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}}, + {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}}, + {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}}, + {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}}, + {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}}, + {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}}, + + {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}}, + {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}}, + {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}}, + {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}}, + {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}}, + + {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}}, + }; + static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; + static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f}; + + if (!init_test_context(&test_context, NULL)) + return; + device = test_context.device; + context = test_context.immediate_context; + + hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc), + vs_code, sizeof(vs_code), &test_context.input_layout); + ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr); + + vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices); + stride = sizeof(*vertices); + offset = 0; + ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset); + + hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs); + ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr); + + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + draw_color_quad(&test_context, &green); + check_texture_color(test_context.backbuffer, 0xff00ff00, 1); + + for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i) + { + for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j) + { + const struct test *test = &cull_distance_tests[j]; + unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)]; + unsigned int color; + + for (k = 0; k < ARRAY_SIZE(vertices); ++k) + vertices[k].cull_distance[i] = test->vertices[k]; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0); + + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + draw_color_quad(&test_context, &green); + + for (k = 0; k < ARRAY_SIZE(expected_color); ++k) + expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff; + + if (expected_color[0] == expected_color[1]) + { + check_texture_color(test_context.backbuffer, *expected_color, 1); + } + else + { + get_texture_readback(test_context.backbuffer, 0, &rb); + color = get_readback_color(&rb, 160, 240); + ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color); + color = get_readback_color(&rb, 480, 240); + ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color); + release_resource_readback(&rb); + } + } + + for (j = 0; j < ARRAY_SIZE(vertices); ++j) + vertices[j].cull_distance[i] = 1.0f; + } + + for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i) + { + for (j = 0; j < ARRAY_SIZE(vertices); ++j) + vertices[j].clip_distance[i] = -1.0f; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0); + + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + draw_color_quad(&test_context, &green); + check_texture_color(test_context.backbuffer, 0xffffffff, 1); + + for (j = 0; j < ARRAY_SIZE(vertices); ++j) + vertices[j].clip_distance[i] = 1.0f; + } + + memset(vertices, 0, sizeof(vertices)); + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0); + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + draw_color_quad(&test_context, &green); + check_texture_color(test_context.backbuffer, 0xff00ff00, 1); + + ID3D11Buffer_Release(vb); + release_test_context(&test_context); +} + START_TEST(d3d11) { test_create_device(); @@ -23234,4 +23442,5 @@ START_TEST(d3d11) test_conservative_depth_output(); test_format_compatibility(); test_clip_distance(); + test_combined_clip_and_cull_distances(); }
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
A plane isn't transformed as simply as a vector.
Signed-off-by: Józef Kucia jkucia@codeweavers.com ---
Fixes https://bugs.winehq.org/show_bug.cgi?id=44104
--- dlls/wined3d/glsl_shader.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index 976c7cdb6213..18822c50dfc8 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -1308,7 +1308,7 @@ static void swap_rows(float **a, float **b) *b = tmp; }
-static BOOL invert_matrix(struct wined3d_matrix *out, struct wined3d_matrix *m) +static BOOL invert_matrix(struct wined3d_matrix *out, const struct wined3d_matrix *m) { float wtmp[4][8]; float m0, m1, m2, m3, s; @@ -1512,6 +1512,18 @@ static BOOL invert_matrix(struct wined3d_matrix *out, struct wined3d_matrix *m) return TRUE; }
+static void transpose_matrix(struct wined3d_matrix *out, const struct wined3d_matrix *m) +{ + struct wined3d_matrix temp; + unsigned int i, j; + + for (i = 0; i < 4; ++i) + for (j = 0; j < 4; ++j) + (&temp._11)[4 * j + i] = (&m->_11)[4 * i + j]; + + *out = temp; +} + static void shader_glsl_ffp_vertex_normalmatrix_uniform(const struct wined3d_context *context, const struct wined3d_state *state, struct glsl_shader_prog_link *prog) { @@ -1709,13 +1721,18 @@ static void shader_glsl_clip_plane_uniform(const struct wined3d_context *context const struct wined3d_state *state, unsigned int index, struct glsl_shader_prog_link *prog) { const struct wined3d_gl_info *gl_info = context->gl_info; + struct wined3d_matrix matrix; struct wined3d_vec4 plane;
+ plane = state->clip_planes[index]; + /* Clip planes are affected by the view transform in d3d for FFP draws. */ if (!use_vs(state)) - multiply_vector_matrix(&plane, &state->clip_planes[index], &state->transforms[WINED3D_TS_VIEW]); - else - plane = state->clip_planes[index]; + { + invert_matrix(&matrix, &state->transforms[WINED3D_TS_VIEW]); + transpose_matrix(&matrix, &matrix); + multiply_vector_matrix(&plane, &plane, &matrix); + }
GL_EXTCALL(glUniform4fv(prog->vs.clip_planes_location + index, 1, &plane.x)); }
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
2017-12-05 0:26 GMT+01:00 Józef Kucia jkucia@codeweavers.com:
A plane isn't transformed as simply as a vector.
Signed-off-by: Józef Kucia jkucia@codeweavers.com
FWIW this makes a lot of sense to me.
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/ddraw/ddraw_private.h | 4 ++++ dlls/ddraw/device.c | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h index 0ae453287093..0b6666a85159 100644 --- a/dlls/ddraw/ddraw_private.h +++ b/dlls/ddraw/ddraw_private.h @@ -38,6 +38,8 @@ #include "wine/list.h" #include "wine/wined3d.h"
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) + extern const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops DECLSPEC_HIDDEN; extern DWORD force_refresh_rate DECLSPEC_HIDDEN;
@@ -341,6 +343,8 @@ struct d3d_device /* Handle management */ struct ddraw_handle_table handle_table; D3DMATRIXHANDLE world, proj, view; + + struct wined3d_vec4 user_clip_planes[D3DMAXUSERCLIPPLANES]; };
HRESULT d3d_device_create(struct ddraw *ddraw, struct ddraw_surface *target, IUnknown *rt_iface, diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index 7d92df5603bf..32a2f1a6be50 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -6457,6 +6457,7 @@ static HRESULT WINAPI d3d_device7_GetLightEnable_FPUPreserve(IDirect3DDevice7 *i static HRESULT d3d_device7_SetClipPlane(IDirect3DDevice7 *iface, DWORD idx, D3DVALUE *plane) { struct d3d_device *device = impl_from_IDirect3DDevice7(iface); + const struct wined3d_vec4 *wined3d_plane; HRESULT hr;
TRACE("iface %p, idx %u, plane %p.\n", iface, idx, plane); @@ -6464,8 +6465,16 @@ static HRESULT d3d_device7_SetClipPlane(IDirect3DDevice7 *iface, DWORD idx, D3DV if (!plane) return DDERR_INVALIDPARAMS;
+ wined3d_plane = (struct wined3d_vec4 *)plane; + wined3d_mutex_lock(); - hr = wined3d_device_set_clip_plane(device->wined3d_device, idx, (struct wined3d_vec4 *)plane); + hr = wined3d_device_set_clip_plane(device->wined3d_device, idx, wined3d_plane); + if (hr == WINED3DERR_INVALIDCALL && idx < ARRAY_SIZE(device->user_clip_planes)) + { + WARN("Clip plane %u is not supported.\n", idx); + device->user_clip_planes[idx] = *wined3d_plane; + hr = D3D_OK; + } wined3d_mutex_unlock();
return hr; @@ -6505,6 +6514,7 @@ static HRESULT WINAPI d3d_device7_SetClipPlane_FPUPreserve(IDirect3DDevice7 *ifa static HRESULT d3d_device7_GetClipPlane(IDirect3DDevice7 *iface, DWORD idx, D3DVALUE *plane) { struct d3d_device *device = impl_from_IDirect3DDevice7(iface); + struct wined3d_vec4 *wined3d_plane; HRESULT hr;
TRACE("iface %p, idx %u, plane %p.\n", iface, idx, plane); @@ -6512,8 +6522,16 @@ static HRESULT d3d_device7_GetClipPlane(IDirect3DDevice7 *iface, DWORD idx, D3DV if (!plane) return DDERR_INVALIDPARAMS;
+ wined3d_plane = (struct wined3d_vec4 *)plane; + wined3d_mutex_lock(); - hr = wined3d_device_get_clip_plane(device->wined3d_device, idx, (struct wined3d_vec4 *)plane); + hr = wined3d_device_get_clip_plane(device->wined3d_device, idx, wined3d_plane); + if (hr == WINED3DERR_INVALIDCALL && idx < ARRAY_SIZE(device->user_clip_planes)) + { + WARN("Clip plane %u is not supported.\n", idx); + *wined3d_plane = device->user_clip_planes[idx]; + hr = D3D_OK; + } wined3d_mutex_unlock();
return hr;
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
On 5 December 2017 at 02:56, Józef Kucia jkucia@codeweavers.com wrote:
@@ -341,6 +343,8 @@ struct d3d_device /* Handle management */ struct ddraw_handle_table handle_table; D3DMATRIXHANDLE world, proj, view;
- struct wined3d_vec4 user_clip_planes[D3DMAXUSERCLIPPLANES];
};
HRESULT d3d_device_create(struct ddraw *ddraw, struct ddraw_surface *target, IUnknown *rt_iface,
...
@@ -6464,8 +6465,16 @@ static HRESULT d3d_device7_SetClipPlane(IDirect3DDevice7 *iface, DWORD idx, D3DV if (!plane) return DDERR_INVALIDPARAMS;
- wined3d_plane = (struct wined3d_vec4 *)plane;
- wined3d_mutex_lock();
- hr = wined3d_device_set_clip_plane(device->wined3d_device, idx, (struct wined3d_vec4 *)plane);
hr = wined3d_device_set_clip_plane(device->wined3d_device, idx, wined3d_plane);
if (hr == WINED3DERR_INVALIDCALL && idx < ARRAY_SIZE(device->user_clip_planes))
{
WARN("Clip plane %u is not supported.\n", idx);
device->user_clip_planes[idx] = *wined3d_plane;
hr = D3D_OK;
} wined3d_mutex_unlock();
return hr;
Ultimately it's perhaps not that big of a deal, but the name "user_clip_planes" seems to suggest it contains a copy of the UCPs, while it really only contains the ones you can't use.
On Tue, Dec 5, 2017 at 5:42 PM, Henri Verbeet hverbeet@gmail.com wrote:
Ultimately it's perhaps not that big of a deal, but the name "user_clip_planes" seems to suggest it contains a copy of the UCPs, while it really only contains the ones you can't use.
Yes, it makes sense to store all clip planes. I'll fix this. Thanks.
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/wined3d/device.c | 10 ++-------- dlls/wined3d/stateblock.c | 2 +- dlls/wined3d/wined3d_private.h | 4 +--- 3 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 7340488d7c89..d57758d32abd 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -1757,7 +1757,7 @@ HRESULT CDECL wined3d_device_set_clip_plane(struct wined3d_device *device, { TRACE("device %p, plane_idx %u, plane %p.\n", device, plane_idx, plane);
- if (plane_idx >= WINED3D_MAX_USER_CLIP_PLANES) + if (plane_idx >= device->adapter->gl_info.limits.user_clip_distances) { TRACE("Application has requested clipplane this device doesn't support.\n"); return WINED3DERR_INVALIDCALL; @@ -1774,12 +1774,6 @@ HRESULT CDECL wined3d_device_set_clip_plane(struct wined3d_device *device,
device->update_state->clip_planes[plane_idx] = *plane;
- if (plane_idx >= device->adapter->gl_info.limits.user_clip_distances) - { - WARN("Clip plane %u is not supported.\n", plane_idx); - return WINED3D_OK; - } - if (!device->recording) wined3d_cs_emit_set_clip_plane(device->cs, plane_idx, plane);
@@ -1791,7 +1785,7 @@ HRESULT CDECL wined3d_device_get_clip_plane(const struct wined3d_device *device, { TRACE("device %p, plane_idx %u, plane %p.\n", device, plane_idx, plane);
- if (plane_idx >= WINED3D_MAX_USER_CLIP_PLANES) + if (plane_idx >= device->adapter->gl_info.limits.user_clip_distances) { TRACE("Application has requested clipplane this device doesn't support.\n"); return WINED3DERR_INVALIDCALL; diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index f80b8750b4f8..9d613605b980 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -218,7 +218,7 @@ static void stateblock_savedstates_set_all(struct wined3d_saved_states *states, stateblock_set_bits(states->renderState, WINEHIGHEST_RENDER_STATE + 1); for (i = 0; i < MAX_TEXTURES; ++i) states->textureState[i] = 0x3ffff; for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) states->samplerState[i] = 0x3ffe; - states->clipplane = 0xffffffff; + states->clipplane = (1u << MAX_CLIP_DISTANCES) - 1; states->pixelShaderConstantsB = 0xffff; states->pixelShaderConstantsI = 0xffff; states->vertexShaderConstantsB = 0xffff; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 6f1328084b84..5b75c6f95ce4 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -259,8 +259,6 @@ static inline enum complex_fixup get_complex_fixup(struct color_fixup_desc fixup return complex_fixup; }
-#define WINED3D_MAX_USER_CLIP_PLANES 32 - /* Device caps */ #define MAX_STREAMS 16 #define MAX_TEXTURES 8 @@ -2829,7 +2827,7 @@ struct wined3d_state DWORD texture_states[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
struct wined3d_matrix transforms[HIGHEST_TRANSFORMSTATE + 1]; - struct wined3d_vec4 clip_planes[WINED3D_MAX_USER_CLIP_PLANES]; + struct wined3d_vec4 clip_planes[MAX_CLIP_DISTANCES]; struct wined3d_material material; struct wined3d_viewport viewport; RECT scissor_rect;
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com