From b7b10b971aef36d074f7547428888ce1bccd2f69 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Tue, 6 Aug 2024 10:15:00 +0200 Subject: [PATCH] radeonsi: add si_screen helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a si_screen cast helper, with 2 purposes: * correctly cast from pipe_screen to si_screen using get_driver_pipe_screen * check that the result's type is correct It's only useful when intending to use pipe_resource::screen as a si_screen. Reviewed-By: Mike Blumenkrantz Reviewed-by: Marek Olšák Part-of: --- src/gallium/drivers/radeonsi/si_descriptors.c | 2 +- src/gallium/drivers/radeonsi/si_pipe.c | 2 +- src/gallium/drivers/radeonsi/si_pipe.h | 17 +++++++++++++++-- src/gallium/drivers/radeonsi/si_texture.c | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c b/src/gallium/drivers/radeonsi/si_descriptors.c index 9d323211e56..34cfa04c758 100644 --- a/src/gallium/drivers/radeonsi/si_descriptors.c +++ b/src/gallium/drivers/radeonsi/si_descriptors.c @@ -402,7 +402,7 @@ static void si_set_sampler_view_desc(struct si_context *sctx, struct si_sampler_ static bool color_needs_decompression(struct si_texture *tex) { - struct si_screen *sscreen = (struct si_screen *)tex->buffer.b.b.screen; + struct si_screen *sscreen = si_screen(tex->buffer.b.b.screen); if (sscreen->info.gfx_level >= GFX11 || tex->is_depth) return false; diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c index 33b68d05edc..9cf6f309662 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.c +++ b/src/gallium/drivers/radeonsi/si_pipe.c @@ -975,7 +975,7 @@ static struct pipe_context *si_pipe_create_context(struct pipe_screen *screen, v /* * pipe_screen */ -static void si_destroy_screen(struct pipe_screen *pscreen) +void si_destroy_screen(struct pipe_screen *pscreen) { struct si_screen *sscreen = (struct si_screen *)pscreen; struct si_shader_part *parts[] = {sscreen->ps_prologs, sscreen->ps_epilogs}; diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h index f1480f376cd..9552b910c12 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.h +++ b/src/gallium/drivers/radeonsi/si_pipe.h @@ -1625,6 +1625,7 @@ void si_init_aux_async_compute_ctx(struct si_screen *sscreen); struct si_context *si_get_aux_context(struct si_aux_context *ctx); void si_put_aux_context_flush(struct si_aux_context *ctx); void si_put_aux_shader_upload_context_flush(struct si_screen *sscreen); +void si_destroy_screen(struct pipe_screen *pscreen); /* si_perfcounters.c */ void si_init_perfcounters(struct si_screen *screen); @@ -1743,6 +1744,18 @@ void si_handle_sqtt(struct si_context *sctx, struct radeon_cmdbuf *rcs); * common helpers */ +/* Use this helper when casting pipe_resouce::screen to get a real si_screen + * instance (= this is only useful when intending to access si_screen members directly) + */ +static inline struct si_screen * +si_screen(struct pipe_screen *pscreen) +{ + struct pipe_screen *s = + pscreen->get_driver_pipe_screen ? pscreen->get_driver_pipe_screen(pscreen) : pscreen; + assert(s->destroy == si_destroy_screen); + return (struct si_screen *)s; +} + static inline void si_compute_reference(struct si_compute **dst, struct si_compute *src) { if (pipe_reference(&(*dst)->sel.base.reference, &src->sel.base.reference)) @@ -1929,7 +1942,7 @@ static inline bool si_can_sample_zs(struct si_texture *tex, bool stencil_sampler static inline bool si_htile_enabled(struct si_texture *tex, unsigned level, unsigned zs_mask) { - struct si_screen *sscreen = (struct si_screen *)tex->buffer.b.b.screen; + struct si_screen *sscreen = si_screen(tex->buffer.b.b.screen); /* Gfx12 should never call this. */ assert(sscreen->info.gfx_level < GFX12); @@ -1954,7 +1967,7 @@ static inline bool si_htile_enabled(struct si_texture *tex, unsigned level, unsi static inline bool vi_tc_compat_htile_enabled(struct si_texture *tex, unsigned level, unsigned zs_mask) { - struct si_screen *sscreen = (struct si_screen *)tex->buffer.b.b.screen; + struct si_screen *sscreen = si_screen(tex->buffer.b.b.screen); /* Gfx12 should never call this. */ assert(sscreen->info.gfx_level < GFX12); diff --git a/src/gallium/drivers/radeonsi/si_texture.c b/src/gallium/drivers/radeonsi/si_texture.c index 633a8108aa6..012b697bc68 100644 --- a/src/gallium/drivers/radeonsi/si_texture.c +++ b/src/gallium/drivers/radeonsi/si_texture.c @@ -2208,7 +2208,7 @@ bool vi_dcc_formats_are_incompatible(struct pipe_resource *tex, unsigned level, struct si_texture *stex = (struct si_texture *)tex; return vi_dcc_enabled(stex, level) && - !vi_dcc_formats_compatible((struct si_screen *)tex->screen, tex->format, view_format); + !vi_dcc_formats_compatible(si_screen(tex->screen), tex->format, view_format); } /* This can't be merged with the above function, because