From 74a172a44857ccf7c73a03913bd4e1498dbf601e Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Thu, 12 May 2022 20:09:22 +0200 Subject: [PATCH] radeonsi: fix glTexBuffer max size handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The spec says the number of texels must be clamped to the value of GL_MAX_TEXTURE_BUFFER_SIZE. Reviewed-by: Qiang Yu Reviewed-by: Mihai Preda Reviewed-by: Marek Olšák Part-of: --- .../drivers/radeonsi/ci/gfx10_3-sienna_cichlid-fail.csv | 7 ------- src/gallium/drivers/radeonsi/ci/gfx8-polaris11-fail.csv | 7 ------- src/gallium/drivers/radeonsi/si_descriptors.c | 4 +++- src/gallium/drivers/radeonsi/si_pipe.c | 3 +++ src/gallium/drivers/radeonsi/si_pipe.h | 2 ++ src/gallium/drivers/radeonsi/si_state.c | 5 ++++- src/gallium/drivers/radeonsi/si_state.h | 16 ++++++++++++++++ 7 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/gallium/drivers/radeonsi/ci/gfx10_3-sienna_cichlid-fail.csv b/src/gallium/drivers/radeonsi/ci/gfx10_3-sienna_cichlid-fail.csv index b9687f8..4dd7599 100644 --- a/src/gallium/drivers/radeonsi/ci/gfx10_3-sienna_cichlid-fail.csv +++ b/src/gallium/drivers/radeonsi/ci/gfx10_3-sienna_cichlid-fail.csv @@ -88,13 +88,6 @@ spec@arb_shader_texture_lod@execution@arb_shader_texture_lod-texgradcube,Fail spec@arb_shading_language_packing@execution@built-in-functions@fs-packhalf2x16,Fail spec@arb_shading_language_packing@execution@built-in-functions@vs-packhalf2x16,Fail spec@arb_tessellation_shader@execution@tcs-tes-levels-out-of-bounds-write,Crash -spec@arb_texture_buffer_object@texture-buffer-size-clamp,Fail -spec@arb_texture_buffer_object@texture-buffer-size-clamp@r8ui_texture_buffer_size_via_image,Fail -spec@arb_texture_buffer_object@texture-buffer-size-clamp@r8ui_texture_buffer_size_via_sampler,Fail -spec@arb_texture_buffer_object@texture-buffer-size-clamp@rg8ui_texture_buffer_size_via_image,Fail -spec@arb_texture_buffer_object@texture-buffer-size-clamp@rg8ui_texture_buffer_size_via_sampler,Fail -spec@arb_texture_buffer_object@texture-buffer-size-clamp@rgba8ui_texture_buffer_size_via_image,Fail -spec@arb_texture_buffer_object@texture-buffer-size-clamp@rgba8ui_texture_buffer_size_via_sampler,Fail spec@egl_ext_protected_content@conformance,Fail spec@ext_framebuffer_blit@fbo-blit-check-limits,Fail spec@ext_image_dma_buf_import@ext_image_dma_buf_import-sample_uyvy,Fail diff --git a/src/gallium/drivers/radeonsi/ci/gfx8-polaris11-fail.csv b/src/gallium/drivers/radeonsi/ci/gfx8-polaris11-fail.csv index df561a7..54fbbc9 100644 --- a/src/gallium/drivers/radeonsi/ci/gfx8-polaris11-fail.csv +++ b/src/gallium/drivers/radeonsi/ci/gfx8-polaris11-fail.csv @@ -102,13 +102,6 @@ spec@arb_shader_texture_lod@execution@arb_shader_texture_lod-texgradcube,Fail spec@arb_shading_language_packing@execution@built-in-functions@fs-packhalf2x16,Fail spec@arb_shading_language_packing@execution@built-in-functions@vs-packhalf2x16,Fail spec@arb_tessellation_shader@execution@tcs-tes-levels-out-of-bounds-write,Crash -spec@arb_texture_buffer_object@texture-buffer-size-clamp,Fail -spec@arb_texture_buffer_object@texture-buffer-size-clamp@r8ui_texture_buffer_size_via_image,Fail -spec@arb_texture_buffer_object@texture-buffer-size-clamp@r8ui_texture_buffer_size_via_sampler,Fail -spec@arb_texture_buffer_object@texture-buffer-size-clamp@rg8ui_texture_buffer_size_via_image,Fail -spec@arb_texture_buffer_object@texture-buffer-size-clamp@rg8ui_texture_buffer_size_via_sampler,Fail -spec@arb_texture_buffer_object@texture-buffer-size-clamp@rgba8ui_texture_buffer_size_via_image,Fail -spec@arb_texture_buffer_object@texture-buffer-size-clamp@rgba8ui_texture_buffer_size_via_sampler,Fail spec@arb_texture_compression@texwrap formats bordercolor-swizzled,Fail spec@arb_texture_compression@texwrap formats bordercolor-swizzled@GL_COMPRESSED_RGB- swizzled- border color only,Fail spec@arb_texture_compression@texwrap formats bordercolor-swizzled@GL_COMPRESSED_RGBA- swizzled- border color only,Fail diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c b/src/gallium/drivers/radeonsi/si_descriptors.c index 698ac5f..3dd76a0 100644 --- a/src/gallium/drivers/radeonsi/si_descriptors.c +++ b/src/gallium/drivers/radeonsi/si_descriptors.c @@ -755,8 +755,10 @@ static void si_set_shader_image_desc(struct si_context *ctx, const struct pipe_i if (res->b.b.target == PIPE_BUFFER) { if (view->access & PIPE_IMAGE_ACCESS_WRITE) si_mark_image_range_valid(view); + uint32_t size = si_clamp_texture_texel_count(screen->max_texture_buffer_size, + view->format, view->u.buf.size); - si_make_buffer_descriptor(screen, res, view->format, view->u.buf.offset, view->u.buf.size, + si_make_buffer_descriptor(screen, res, view->format, view->u.buf.offset, size, desc); si_set_buf_desc_address(res, view->u.buf.offset, desc + 4); } else { diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c index 589af37..b7ed88b 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.c +++ b/src/gallium/drivers/radeonsi/si_pipe.c @@ -1141,6 +1141,9 @@ static struct pipe_screen *radeonsi_screen_create_impl(struct radeon_winsys *ws, si_init_screen_query_functions(sscreen); si_init_screen_live_shader_cache(sscreen); + sscreen->max_texture_buffer_size = sscreen->b.get_param( + &sscreen->b, PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE); + /* Set these flags in debug_flags early, so that the shader cache takes * them into account. * diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h index a3d8da2..4192ddc 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.h +++ b/src/gallium/drivers/radeonsi/si_pipe.h @@ -604,6 +604,8 @@ struct si_screen { /* Texture filter settings. */ int force_aniso; /* -1 = disabled */ + unsigned max_texture_buffer_size; + /* Auxiliary context. Mainly used to initialize resources. * It must be locked prior to using and flushed before unlocking. */ struct pipe_context *aux_context; diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index ee19553..a91145a 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -4556,8 +4556,11 @@ static struct pipe_sampler_view *si_create_sampler_view(struct pipe_context *ctx /* Buffer resource. */ if (texture->target == PIPE_BUFFER) { + uint32_t size = si_clamp_texture_texel_count(sctx->screen->max_texture_buffer_size, + state->format, state->u.buf.size); + si_make_buffer_descriptor(sctx->screen, si_resource(texture), state->format, - state->u.buf.offset, state->u.buf.size, view->state); + state->u.buf.offset, size, view->state); return &view->base; } diff --git a/src/gallium/drivers/radeonsi/si_state.h b/src/gallium/drivers/radeonsi/si_state.h index 4cbcde6..1122336 100644 --- a/src/gallium/drivers/radeonsi/si_state.h +++ b/src/gallium/drivers/radeonsi/si_state.h @@ -650,6 +650,22 @@ static inline unsigned si_get_image_slot(unsigned slot) return SI_NUM_IMAGE_SLOTS - 1 - slot; } +static inline unsigned si_clamp_texture_texel_count(unsigned max_texture_buffer_size, + enum pipe_format format, + uint32_t size) +{ + /* The spec says: + * The number of texels in the texel array is then clamped to the value of + * the implementation-dependent limit GL_MAX_TEXTURE_BUFFER_SIZE. + * + * So compute the number of texels, compare to GL_MAX_TEXTURE_BUFFER_SIZE and update it. + */ + unsigned stride = util_format_get_blocksize(format); + unsigned num_texels = MIN2(max_texture_buffer_size, + size / stride); + return num_texels * stride; +} + #ifdef __cplusplus } #endif -- 2.7.4