Mesa (main): zink: break out sample location updating to separate function

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri May 20 16:58:31 UTC 2022


Module: Mesa
Branch: main
Commit: 190ccf3324c97406de122f79cf62ff5477b12a64
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=190ccf3324c97406de122f79cf62ff5477b12a64

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Tue May 10 12:17:37 2022 -0400

zink: break out sample location updating to separate function

no functional changes

Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16476>

---

 src/gallium/drivers/zink/zink_context.c     | 22 ++++++++++++++++++++++
 src/gallium/drivers/zink/zink_context.h     |  2 ++
 src/gallium/drivers/zink/zink_render_pass.c | 18 +-----------------
 3 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index e92de9f476c..5230be4cb6b 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -1974,6 +1974,28 @@ zink_update_fbfetch(struct zink_context *ctx)
    }
 }
 
+void
+zink_update_vk_sample_locations(struct zink_context *ctx)
+{
+   if (ctx->gfx_pipeline_state.sample_locations_enabled && ctx->sample_locations_changed) {
+      unsigned samples = ctx->gfx_pipeline_state.rast_samples + 1;
+      unsigned idx = util_logbase2_ceil(MAX2(samples, 1));
+      VkExtent2D grid_size = zink_screen(ctx->base.screen)->maxSampleLocationGridSize[idx];
+ 
+      for (unsigned pixel = 0; pixel < grid_size.width * grid_size.height; pixel++) {
+         for (unsigned sample = 0; sample < samples; sample++) {
+            unsigned pixel_x = pixel % grid_size.width;
+            unsigned pixel_y = pixel / grid_size.width;
+            unsigned wi = pixel * samples + sample;
+            unsigned ri = (pixel_y * grid_size.width + pixel_x % grid_size.width);
+            ri = ri * samples + sample;
+            ctx->vk_sample_locations[wi].x = (ctx->sample_locations[ri] & 0xf) / 16.0f;
+            ctx->vk_sample_locations[wi].y = (16 - (ctx->sample_locations[ri] >> 4)) / 16.0f;
+         }
+      }
+   }
+}
+
 void
 zink_batch_rp(struct zink_context *ctx)
 {
diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h
index 76394ff141b..fcf3d036933 100644
--- a/src/gallium/drivers/zink/zink_context.h
+++ b/src/gallium/drivers/zink/zink_context.h
@@ -430,6 +430,8 @@ zink_batch_no_rp(struct zink_context *ctx);
 
 VkImageView
 zink_prep_fb_attachment(struct zink_context *ctx, struct zink_surface *surf, unsigned i);
+void
+zink_update_vk_sample_locations(struct zink_context *ctx);
 
 static inline VkPipelineStageFlags
 zink_pipeline_flags_from_pipe_stage(enum pipe_shader_type pstage)
diff --git a/src/gallium/drivers/zink/zink_render_pass.c b/src/gallium/drivers/zink/zink_render_pass.c
index bb5b5ef8ec1..f51623cf74e 100644
--- a/src/gallium/drivers/zink/zink_render_pass.c
+++ b/src/gallium/drivers/zink/zink_render_pass.c
@@ -417,23 +417,7 @@ setup_framebuffer(struct zink_context *ctx)
    struct zink_screen *screen = zink_screen(ctx->base.screen);
    struct zink_render_pass *rp = ctx->gfx_pipeline_state.render_pass;
 
-   if (ctx->gfx_pipeline_state.sample_locations_enabled && ctx->sample_locations_changed) {
-      unsigned samples = ctx->gfx_pipeline_state.rast_samples + 1;
-      unsigned idx = util_logbase2_ceil(MAX2(samples, 1));
-      VkExtent2D grid_size = screen->maxSampleLocationGridSize[idx];
- 
-      for (unsigned pixel = 0; pixel < grid_size.width * grid_size.height; pixel++) {
-         for (unsigned sample = 0; sample < samples; sample++) {
-            unsigned pixel_x = pixel % grid_size.width;
-            unsigned pixel_y = pixel / grid_size.width;
-            unsigned wi = pixel * samples + sample;
-            unsigned ri = (pixel_y * grid_size.width + pixel_x % grid_size.width);
-            ri = ri * samples + sample;
-            ctx->vk_sample_locations[wi].x = (ctx->sample_locations[ri] & 0xf) / 16.0f;
-            ctx->vk_sample_locations[wi].y = (16 - (ctx->sample_locations[ri] >> 4)) / 16.0f;
-         }
-      }
-   }
+   zink_update_vk_sample_locations(ctx);
 
    if (rp)
       ctx->rp_changed |= ctx->rp_clears_enabled != rp->state.clears;



More information about the mesa-commit mailing list