zink: track depth swizzle on samplerviews
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Thu, 5 Jan 2023 21:28:33 +0000 (16:28 -0500)
committerMarge Bot <emma+marge@anholt.net>
Tue, 24 Jan 2023 08:30:09 +0000 (08:30 +0000)
this will provide info for shader rewrites

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20598>

src/gallium/drivers/zink/zink_context.c
src/gallium/drivers/zink/zink_shader_keys.h
src/gallium/drivers/zink/zink_types.h

index 9002922..ebe6994 100644 (file)
@@ -1022,6 +1022,19 @@ zink_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *pres,
             ivci.components.b = zink_component_mapping(clamp_zs_swizzle(sampler_view->base.swizzle_b));
             ivci.components.a = zink_component_mapping(clamp_zs_swizzle(sampler_view->base.swizzle_a));
          }
+         if (ivci.subresourceRange.aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT) {
+            VkComponentSwizzle *swizzle = (VkComponentSwizzle*)&ivci.components;
+            for (unsigned i = 0; i < 4; i++) {
+               /* these require shader rewrites to correctly emulate */
+               if (swizzle[i] == VK_COMPONENT_SWIZZLE_ONE || swizzle[i] == VK_COMPONENT_SWIZZLE_ZERO)
+                  sampler_view->shadow_needs_shader_swizzle = true;
+            }
+            /* this is the data that will be used in shader rewrites */
+            sampler_view->swizzle.s[0] = clamp_zs_swizzle(sampler_view->base.swizzle_r);
+            sampler_view->swizzle.s[1] = clamp_zs_swizzle(sampler_view->base.swizzle_g);
+            sampler_view->swizzle.s[2] = clamp_zs_swizzle(sampler_view->base.swizzle_b);
+            sampler_view->swizzle.s[3] = clamp_zs_swizzle(sampler_view->base.swizzle_a);
+         }
       } else {
          enum pipe_swizzle swizzle[4] = {
             sampler_view->base.swizzle_r,
index 3a14aeb..4605d6e 100644 (file)
@@ -67,6 +67,15 @@ struct zink_gs_key {
    unsigned size;
 };
 
+struct zink_fs_shadow_swizzle {
+   uint8_t s[4];
+};
+
+struct zink_fs_shadow_key {
+   uint32_t mask;
+   struct zink_fs_shadow_swizzle swizzle[32];
+};
+
 struct zink_fs_key_base {
    bool coord_replace_yinvert : 1;
    bool samples : 1;
index 31a797d..30966c9 100644 (file)
@@ -1468,6 +1468,8 @@ struct zink_sampler_view {
       struct zink_buffer_view *buffer_view;
    };
    struct zink_surface *cube_array;
+   bool shadow_needs_shader_swizzle;
+   struct zink_fs_shadow_swizzle swizzle;
 };
 
 struct zink_image_view {