Module: Mesa Branch: main Commit: a3899c4530c26c1cbc0e204c71f417fb9ee4e132 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=a3899c4530c26c1cbc0e204c71f417fb9ee4e132
Author: Jesse Natalie <jenat...@microsoft.com> Date: Tue Nov 7 09:05:39 2023 -0800 d3d12: Add a fallback for int clears where value can't be cast to float Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26104> --- src/gallium/drivers/d3d12/ci/d3d12-quick_gl.txt | 3 -- src/gallium/drivers/d3d12/d3d12_context.cpp | 62 ++++++++++++++++++++----- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/gallium/drivers/d3d12/ci/d3d12-quick_gl.txt b/src/gallium/drivers/d3d12/ci/d3d12-quick_gl.txt index fe9b49e482c..6af39436eaf 100644 --- a/src/gallium/drivers/d3d12/ci/d3d12-quick_gl.txt +++ b/src/gallium/drivers/d3d12/ci/d3d12-quick_gl.txt @@ -32,7 +32,6 @@ spec@!opengl 3.2@gl-3.2-adj-prims line cull-back pv-last,Fail spec@!opengl 3.2@gl-3.2-adj-prims line cull-front pv-last,Fail spec@!opengl 3.2@gl-3.2-adj-prims pv-last,Fail spec@arb_draw_indirect@arb_draw_indirect-api-errors,Crash -spec@arb_clear_texture@arb_clear_texture-integer,Fail spec@arb_explicit_attrib_location@overlapping-locations-input-attribs api,Crash spec@arb_explicit_attrib_location@overlapping-locations-input-attribs shader,Crash spec@arb_framebuffer_object@fbo-blit-scaled-linear,Fail @@ -166,8 +165,6 @@ spec@ext_framebuffer_multisample@sample-alpha-to-one 2,Fail spec@ext_framebuffer_multisample@sample-alpha-to-one 4,Fail spec@ext_framebuffer_multisample@sample-alpha-to-one 6,Fail spec@ext_framebuffer_multisample@sample-alpha-to-one 8,Fail -spec@ext_texture_integer@fbo_integer_precision_clear,Fail -spec@ext_texture_integer@fbo_integer_readpixels_sint_uint,Fail spec@ext_texture_integer@texwrap formats,Fail spec@ext_texture_integer@texwrap formats offset,Fail spec@ext_texture_integer@texwrap formats offset@GL_ALPHA16I_EXT,Fail diff --git a/src/gallium/drivers/d3d12/d3d12_context.cpp b/src/gallium/drivers/d3d12/d3d12_context.cpp index a5134471e2d..3d632b346b0 100644 --- a/src/gallium/drivers/d3d12/d3d12_context.cpp +++ b/src/gallium/drivers/d3d12/d3d12_context.cpp @@ -2044,29 +2044,69 @@ d3d12_clear_render_target(struct pipe_context *pctx, D3D12_TRANSITION_FLAG_INVALIDATE_BINDINGS); d3d12_apply_resource_states(ctx, false); - enum pipe_format format = psurf->texture->format; + enum pipe_format format = psurf->format; float clear_color[4]; + bool clear_fallback = false; if (util_format_is_pure_uint(format)) { - for (int c = 0; c < 4; ++c) + for (int c = 0; c < 4 && !clear_fallback; ++c) { clear_color[c] = color->ui[c]; + clear_fallback = (uint32_t)clear_color[c] != color->ui[c]; + } } else if (util_format_is_pure_sint(format)) { - for (int c = 0; c < 4; ++c) + for (int c = 0; c < 4 && !clear_fallback; ++c) { clear_color[c] = color->i[c]; + clear_fallback = (int32_t)clear_color[c] != color->i[c]; + } } else { for (int c = 0; c < 4; ++c) clear_color[c] = color->f[c]; } - if (!(util_format_colormask(util_format_description(psurf->texture->format)) & - PIPE_MASK_A)) - clear_color[3] = 1.0f; + if (clear_fallback) { + util_blitter_save_blend(ctx->blitter, ctx->gfx_pipeline_state.blend); + util_blitter_save_depth_stencil_alpha(ctx->blitter, ctx->gfx_pipeline_state.zsa); + util_blitter_save_vertex_elements(ctx->blitter, ctx->gfx_pipeline_state.ves); + util_blitter_save_stencil_ref(ctx->blitter, &ctx->stencil_ref); + util_blitter_save_rasterizer(ctx->blitter, ctx->gfx_pipeline_state.rast); + util_blitter_save_fragment_shader(ctx->blitter, ctx->gfx_stages[PIPE_SHADER_FRAGMENT]); + util_blitter_save_vertex_shader(ctx->blitter, ctx->gfx_stages[PIPE_SHADER_VERTEX]); + util_blitter_save_geometry_shader(ctx->blitter, ctx->gfx_stages[PIPE_SHADER_GEOMETRY]); + util_blitter_save_tessctrl_shader(ctx->blitter, ctx->gfx_stages[PIPE_SHADER_TESS_CTRL]); + util_blitter_save_tesseval_shader(ctx->blitter, ctx->gfx_stages[PIPE_SHADER_TESS_EVAL]); + + util_blitter_save_framebuffer(ctx->blitter, &ctx->fb); + util_blitter_save_viewport(ctx->blitter, ctx->viewport_states); + util_blitter_save_scissor(ctx->blitter, ctx->scissor_states); + util_blitter_save_fragment_sampler_states(ctx->blitter, + ctx->num_samplers[PIPE_SHADER_FRAGMENT], + (void **)ctx->samplers[PIPE_SHADER_FRAGMENT]); + util_blitter_save_fragment_sampler_views(ctx->blitter, + ctx->num_sampler_views[PIPE_SHADER_FRAGMENT], + ctx->sampler_views[PIPE_SHADER_FRAGMENT]); + util_blitter_save_fragment_constant_buffer_slot(ctx->blitter, ctx->cbufs[PIPE_SHADER_FRAGMENT]); + util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vbs); + util_blitter_save_sample_mask(ctx->blitter, ctx->gfx_pipeline_state.sample_mask, 0); + util_blitter_save_so_targets(ctx->blitter, ctx->gfx_pipeline_state.num_so_targets, ctx->so_targets); + + union pipe_color_union local_color; + memcpy(&local_color, color, sizeof(local_color)); + if (!(util_format_colormask(util_format_description(psurf->format)) & PIPE_MASK_A)) { + assert(!util_format_is_float(psurf->format)); + local_color.ui[3] = 1; + } + util_blitter_clear_render_target(ctx->blitter, psurf, &local_color, dstx, dsty, width, height); + } else { + if (!(util_format_colormask(util_format_description(psurf->format)) & + PIPE_MASK_A)) + clear_color[3] = 1.0f; - D3D12_RECT rect = { (int)dstx, (int)dsty, - (int)dstx + (int)width, - (int)dsty + (int)height }; - ctx->cmdlist->ClearRenderTargetView(surf->desc_handle.cpu_handle, - clear_color, 1, &rect); + D3D12_RECT rect = { (int)dstx, (int)dsty, + (int)dstx + (int)width, + (int)dsty + (int)height }; + ctx->cmdlist->ClearRenderTargetView(surf->desc_handle.cpu_handle, + clear_color, 1, &rect); + } d3d12_batch_reference_surface_texture(d3d12_current_batch(ctx), surf);