Henri Verbeet : wined3d: Invalidate sRGB write state in wined3d_cs_exec_set_rendertarget_view() if needed.

Alexandre Julliard julliard at winehq.org
Thu Mar 25 16:49:22 CDT 2021


Module: wine
Branch: master
Commit: b1c84499544354e75505cc366352c72c010d735e
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=b1c84499544354e75505cc366352c72c010d735e

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Thu Mar 25 16:46:42 2021 +0100

wined3d: Invalidate sRGB write state in wined3d_cs_exec_set_rendertarget_view() if needed.

Instead of in wined3d_context_gl_setup_target(). If the render-target view
uses an sRGB format, but the underlying resource has a typeless format, we'd
potentially miss an invalidation in wined3d_context_gl_setup_target() where we
only have access to the underlying resource.

Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/d3d11/tests/d3d11.c  |  2 +-
 dlls/wined3d/context_gl.c |  5 -----
 dlls/wined3d/cs.c         | 18 +++++++++++++++---
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c
index 3e8cbfb18b4..38a0afc3fee 100644
--- a/dlls/d3d11/tests/d3d11.c
+++ b/dlls/d3d11/tests/d3d11.c
@@ -15184,7 +15184,7 @@ static void test_swapchain_views(void)
     ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
 
     draw_color_quad(&test_context, &color);
-    todo_wine check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
+    check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
 
     srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
     srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
diff --git a/dlls/wined3d/context_gl.c b/dlls/wined3d/context_gl.c
index fa61b70f525..123214afd5d 100644
--- a/dlls/wined3d/context_gl.c
+++ b/dlls/wined3d/context_gl.c
@@ -4122,11 +4122,6 @@ static void wined3d_context_gl_setup_target(struct wined3d_context_gl *context_g
             if ((old->alpha_size && !new->alpha_size) || (!old->alpha_size && new->alpha_size)
                     || !(texture->resource.format_flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING))
                 context_invalidate_state(&context_gl->c, STATE_BLEND);
-
-            /* Update sRGB writing when switching between formats that do/do not support sRGB writing */
-            if ((context_gl->c.current_rt.texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE)
-                    != (texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE))
-                context_invalidate_state(&context_gl->c, STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE));
         }
 
         /* When switching away from an offscreen render target, and we're not
diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index c9bc9443e5d..6bf9827d3e1 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -1191,17 +1191,29 @@ void wined3d_device_context_emit_set_scissor_rects(struct wined3d_device_context
 static void wined3d_cs_exec_set_rendertarget_view(struct wined3d_cs *cs, const void *data)
 {
     const struct wined3d_cs_set_rendertarget_view *op = data;
-    BOOL prev_alpha_swizzle, curr_alpha_swizzle;
+    bool prev_alpha_swizzle, curr_alpha_swizzle;
     struct wined3d_rendertarget_view *prev;
+    bool prev_srgb_write, curr_srgb_write;
+    struct wined3d_device *device;
 
+    device = cs->c.device;
     prev = cs->state.fb.render_targets[op->view_idx];
     cs->state.fb.render_targets[op->view_idx] = op->view;
-    device_invalidate_state(cs->c.device, STATE_FRAMEBUFFER);
+    device_invalidate_state(device, STATE_FRAMEBUFFER);
 
     prev_alpha_swizzle = prev && prev->format->id == WINED3DFMT_A8_UNORM;
     curr_alpha_swizzle = op->view && op->view->format->id == WINED3DFMT_A8_UNORM;
     if (prev_alpha_swizzle != curr_alpha_swizzle)
-        device_invalidate_state(cs->c.device, STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL));
+        device_invalidate_state(device, STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL));
+
+    if (!(device->adapter->d3d_info.wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL)
+            || cs->state.render_states[WINED3D_RS_SRGBWRITEENABLE])
+    {
+        prev_srgb_write = prev && prev->format_flags & WINED3DFMT_FLAG_SRGB_WRITE;
+        curr_srgb_write = op->view && op->view->format_flags & WINED3DFMT_FLAG_SRGB_WRITE;
+        if (prev_srgb_write != curr_srgb_write)
+            device_invalidate_state(device, STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE));
+    }
 }
 
 void wined3d_device_context_emit_set_rendertarget_view(struct wined3d_device_context *context, unsigned int view_idx,




More information about the wine-cvs mailing list