From b04eaa8589e233c4866cb93ffd688945d5cc0c1d Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 28 Feb 2025 11:23:18 -0500 Subject: [PATCH] zink: clamp UBO sizes instead of asserting this is a nice idea, but there are apps/games that do not respect hardware capabilities and yolo-bind fixed size buffers fixes Ballionaire (2667120) launch on non-desktop drivers cc: mesa-stable Part-of: --- src/gallium/drivers/zink/zink_context.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index f0e8de25e07..276482fab42 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -678,9 +678,14 @@ update_descriptor_state_ubo_db(struct zink_context *ctx, gl_shader_stage shader, ctx->di.descriptor_res[ZINK_DESCRIPTOR_TYPE_UBO][shader][slot] = res; if (res) { ctx->di.db.ubos[shader][slot].address = res->obj->bda + ctx->ubos[shader][slot].buffer_offset; - ctx->di.db.ubos[shader][slot].range = ctx->ubos[shader][slot].buffer_size; - assert(ctx->di.db.ubos[shader][slot].range == VK_WHOLE_SIZE || - ctx->di.db.ubos[shader][slot].range <= screen->info.props.limits.maxUniformBufferRange); + ctx->di.db.ubos[shader][slot].range = MIN2(ctx->ubos[shader][slot].buffer_size, screen->info.props.limits.maxUniformBufferRange); +#ifndef NDEBUG + static bool warned = false; + if (!warned && ctx->ubos[shader][slot].buffer_size > screen->info.props.limits.maxUniformBufferRange) { + mesa_loge("ZINK: app is binding too-big UBO! Clamping!"); + warned = true; + } +#endif } else { ctx->di.db.ubos[shader][slot].address = 0; ctx->di.db.ubos[shader][slot].range = VK_WHOLE_SIZE; @@ -696,10 +701,15 @@ update_descriptor_state_ubo_lazy(struct zink_context *ctx, gl_shader_stage shade ctx->di.descriptor_res[ZINK_DESCRIPTOR_TYPE_UBO][shader][slot] = res; if (res) { ctx->di.t.ubos[shader][slot].buffer = res->obj->buffer; - ctx->di.t.ubos[shader][slot].range = ctx->ubos[shader][slot].buffer_size; - assert(ctx->di.t.ubos[shader][slot].range <= screen->info.props.limits.maxUniformBufferRange); - } - else { + ctx->di.t.ubos[shader][slot].range = MIN2(ctx->ubos[shader][slot].buffer_size, screen->info.props.limits.maxUniformBufferRange); +#ifndef NDEBUG + static bool warned = false; + if (!warned && ctx->ubos[shader][slot].buffer_size > screen->info.props.limits.maxUniformBufferRange) { + mesa_loge("ZINK: app is binding too-big UBO! Clamping!"); + warned = true; + } +#endif + } else { bool have_null_descriptors = screen->info.rb2_feats.nullDescriptor; VkBuffer null_buffer = zink_resource(ctx->dummy_vertex_buffer)->obj->buffer; ctx->di.t.ubos[shader][slot].buffer = have_null_descriptors ? VK_NULL_HANDLE : null_buffer;