diff --git a/tests/hlsl/depth-out.shader_test b/tests/hlsl/depth-out.shader_test index 7acd05b4..fa40e1a1 100644 --- a/tests/hlsl/depth-out.shader_test +++ b/tests/hlsl/depth-out.shader_test @@ -33,3 +33,78 @@ depth less clear dsv 0.5 todo(sm>=6 | glsl) draw quad probe dsv all r (0.5) + + +[require] +shader model >= 5.0 + +[rtv 0] +format r32g32b32a32 float +size (2d, 640, 480) + +[vertex shader] +float2 depth; + +void main(float4 in_position : POSITION, out float4 out_position : SV_Position) +{ + out_position = in_position; + out_position.z = depth.x; +} + +[pixel shader todo] +float2 depth; + +float4 main(out float out_depth : SV_DepthLessEqual) : SV_Target +{ + out_depth = depth.y; + return float4(0.0f, 1.0f, 0.0f, 1.0f); +} + +[test] +uniform 0 float4 0.75 0.75 0.0 0.0 +clear rtv 0 1.0 1.0 1.0 1.0 +clear dsv 0.5 +depth greater equal +todo draw quad +probe all rgba (0.0, 1.0, 0.0, 1.0) +probe dsv all r (0.75) + +uniform 0 float4 0.75 0.375 0.0 0.0 +clear rtv 0 1.0 1.0 1.0 1.0 +clear dsv 0.5 +todo draw quad +probe all rgba (1.0, 1.0, 1.0, 1.0) +probe dsv all r (0.5) + + +[pixel shader todo] +float2 depth; + +float4 main(out float out_depth : SV_DepthGreaterEqual) : SV_Target +{ + out_depth = depth.y; + return float4(0.0f, 1.0f, 0.0f, 1.0f); +} + +[test] +uniform 0 float4 0.75 0.75 0.0 0.0 +clear rtv 0 1.0 1.0 1.0 1.0 +clear dsv 0.5 +depth greater equal +todo draw quad +probe all rgba (0.0, 1.0, 0.0, 1.0) +probe dsv all r (0.75) + +uniform 0 float4 0.375 0.625 0.0 0.0 +clear rtv 0 1.0 1.0 1.0 1.0 +clear dsv 0.5 +todo draw quad +probe all rgba (0.0, 1.0, 0.0, 1.0) +probe dsv all r (0.625) + +uniform 0 float4 0.375 0.375 0.0 0.0 +clear rtv 0 1.0 1.0 1.0 1.0 +clear dsv 0.5 +todo draw quad +probe all rgba (1.0, 1.0, 1.0, 1.0) +probe dsv all r (0.5) diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 98e87115..f3b6972f 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -834,6 +834,19 @@ static void parse_test_directive(struct shader_runner *runner, const char *line) runner->last_render_failed = !runner->ops->dispatch(runner, x, y, z); } + else if (match_string(line, "clear rtv", &line)) + { + struct resource *resource; + unsigned int slot; + struct vec4 v; + + if (sscanf(line, "%u %f %f %f %f", &slot, &v.x, &v.y, &v.z, &v.w) < 5) + fatal_error("Malformed rtv clear arguments '%s'.\n", line); + + if (!(resource = shader_runner_get_resource(runner, RESOURCE_TYPE_RENDER_TARGET, slot))) + fatal_error("Resource not found.\n"); + runner->ops->clear(runner, resource, &v); + } else if (match_string(line, "clear dsv", &line)) { struct resource *resource; diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index a8ab80e0..c656a318 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -620,6 +620,10 @@ static void d3d11_runner_clear(struct shader_runner *r, struct resource *res, co switch (resource->r.type) { + case RESOURCE_TYPE_RENDER_TARGET: + ID3D11DeviceContext_ClearRenderTargetView(context, resource->rtv, (const float *)clear_value); + break; + case RESOURCE_TYPE_DEPTH_STENCIL: ID3D11DeviceContext_ClearDepthStencilView(context, resource->dsv, D3D11_CLEAR_DEPTH, clear_value->x, 0); break; diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index bb4157d4..7729de7c 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -468,6 +468,11 @@ static void d3d12_runner_clear(struct shader_runner *r, struct resource *resourc switch (resource->type) { + case RESOURCE_TYPE_RENDER_TARGET: + view = get_cpu_rtv_handle(test_context, runner->rtv_heap, resource->slot); + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, view, (const float *)clear_value, 0, NULL); + break; + case RESOURCE_TYPE_DEPTH_STENCIL: view = get_cpu_dsv_handle(test_context, runner->dsv_heap, 0); ID3D12GraphicsCommandList_ClearDepthStencilView(command_list, view, diff --git a/tests/shader_runner_gl.c b/tests/shader_runner_gl.c index 7e93763f..fdc418ba 100644 --- a/tests/shader_runner_gl.c +++ b/tests/shader_runner_gl.c @@ -940,6 +940,7 @@ static void gl_runner_clear(struct shader_runner *r, struct resource *res, const { struct gl_resource *resource = gl_resource(res); struct gl_runner *runner = gl_runner(r); + GLbitfield clear_mask; if (!runner->fbo_id) glGenFramebuffers(1, &runner->fbo_id); @@ -947,10 +948,18 @@ static void gl_runner_clear(struct shader_runner *r, struct resource *res, const switch (resource->r.type) { + case RESOURCE_TYPE_RENDER_TARGET: + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, resource->id, 0); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glClearColor(clear_value->x, clear_value->y, clear_value->z, clear_value->w); + clear_mask = GL_COLOR_BUFFER_BIT; + break; + case RESOURCE_TYPE_DEPTH_STENCIL: glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, resource->id, 0); glDepthMask(GL_TRUE); glClearDepthf(clear_value->x); + clear_mask = GL_DEPTH_BUFFER_BIT; break; default: @@ -958,7 +967,7 @@ static void gl_runner_clear(struct shader_runner *r, struct resource *res, const } glScissor(0, 0, res->width, res->height); - glClear(GL_DEPTH_BUFFER_BIT); + glClear(clear_mask); } static bool gl_runner_draw(struct shader_runner *r, diff --git a/tests/shader_runner_vulkan.c b/tests/shader_runner_vulkan.c index 8a3e9163..d9f06980 100644 --- a/tests/shader_runner_vulkan.c +++ b/tests/shader_runner_vulkan.c @@ -1225,6 +1225,13 @@ static void vulkan_runner_clear(struct shader_runner *r, struct resource *res, c switch (resource->r.type) { + case RESOURCE_TYPE_RENDER_TARGET: + attachment_desc.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + sub_pass_desc.colorAttachmentCount = 1; + sub_pass_desc.pColorAttachments = &attachment_ref; + memcpy(vk_clear_value.color.float32, clear_value, sizeof(vk_clear_value.color.float32)); + break; + case RESOURCE_TYPE_DEPTH_STENCIL: attachment_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; sub_pass_desc.pDepthStencilAttachment = &attachment_ref;