Mesa (master): zink: Cap PIPE_SHADER_CAP_MAX_CONST_BUFFERS to 32

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Dec 7 21:42:39 UTC 2020


Module: Mesa
Branch: master
Commit: e2b4247e403957ebd9767b2e8700442306c7e7c6
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e2b4247e403957ebd9767b2e8700442306c7e7c6

Author: Witold Baryluk <witold.baryluk at gmail.com>
Date:   Mon Dec  7 20:30:32 2020 +0000

zink: Cap PIPE_SHADER_CAP_MAX_CONST_BUFFERS to 32

PIPE_MAX_CONSTANT_BUFFERS is 32, however many Vulkan implementations
has maxPerStageDescriptorUniformBuffers that exceeds it, for example:

radv 8388606,
anv 64
nvidia 1048580 for RTX 2000 and up.

and, together with the current zink logic, the returned value
will exceed the maximum allowed value for the cap.

This causes cso_destroy_context to pass big values back to zink
(via zink_set_constant_buffer), resulting in access beyond end of
allocated buffer for all UBOs.

Cap the cap to PIPE_MAX_CONSTANT_BUFFERS (32), not INT_MAX.

Add an assert to verify future drivers.

Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Fixes: daaf5f1d186 ("gallium: Fix leak of currently bound UBOs at CSO context destruction.")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7976>

---

 src/gallium/auxiliary/cso_cache/cso_context.c | 1 +
 src/gallium/drivers/zink/zink_screen.c        | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index a7550afc033..07bed069935 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -399,6 +399,7 @@ void cso_destroy_context( struct cso_context *ctx )
             assert(maxsam <= PIPE_MAX_SAMPLERS);
             assert(maxview <= PIPE_MAX_SHADER_SAMPLER_VIEWS);
             assert(maxssbo <= PIPE_MAX_SHADER_BUFFERS);
+            assert(maxcb <= PIPE_MAX_CONSTANT_BUFFERS);
             if (maxsam > 0) {
                ctx->pipe->bind_sampler_states(ctx->pipe, sh, 0, maxsam, zeros);
             }
diff --git a/src/gallium/drivers/zink/zink_screen.c b/src/gallium/drivers/zink/zink_screen.c
index f71ab7e1a04..796319d6ee5 100644
--- a/src/gallium/drivers/zink/zink_screen.c
+++ b/src/gallium/drivers/zink/zink_screen.c
@@ -467,7 +467,8 @@ zink_get_shader_param(struct pipe_screen *pscreen,
       return 65536;
 
    case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
-      return  MIN2(screen->info.props.limits.maxPerStageDescriptorUniformBuffers, INT_MAX);
+      return  MIN2(screen->info.props.limits.maxPerStageDescriptorUniformBuffers,
+                   PIPE_MAX_CONSTANT_BUFFERS);
 
    case PIPE_SHADER_CAP_MAX_TEMPS:
       return INT_MAX;



More information about the mesa-commit mailing list