gallium/draw: Properly handle nr_samplers != nr_sampler_views in keys

First, make all key_size functions take nr_samplers and nr_sampler_views
separately so we ensure both get passed in.  Second, rework the offset
helpers to take MAX(nr_samplers, nr_sampler_views) so we get the image
param offset correct if nr_samplers < nr_sampler_views.  While we're
here, also re-order the size calculations to be in the same order as the
things land in memory.

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16435>
This commit is contained in:
Jason Ekstrand 2022-05-10 15:58:36 -05:00 committed by Marge Bot
parent 68f6b6cbdc
commit bbd5883c87
4 changed files with 37 additions and 25 deletions

View file

@ -888,8 +888,8 @@ draw_create_geometry_shader(struct draw_context *draw,
llvm_gs->variant_key_size =
draw_gs_llvm_variant_key_size(
MAX2(gs->info.file_max[TGSI_FILE_SAMPLER]+1,
gs->info.file_max[TGSI_FILE_SAMPLER_VIEW]+1),
gs->info.file_max[TGSI_FILE_SAMPLER]+1,
gs->info.file_max[TGSI_FILE_SAMPLER_VIEW]+1,
gs->info.file_max[TGSI_FILE_IMAGE]+1);
} else
#endif

View file

@ -577,37 +577,49 @@ struct draw_tes_llvm_variant_key
static inline size_t
draw_llvm_variant_key_size(unsigned nr_vertex_elements,
unsigned nr_samplers, unsigned nr_images)
unsigned nr_samplers,
unsigned nr_sampler_views,
unsigned nr_images)
{
return (sizeof(struct draw_llvm_variant_key) +
nr_samplers * sizeof(struct draw_sampler_static_state) +
nr_images * sizeof(struct draw_image_static_state) +
(nr_vertex_elements - 1) * sizeof(struct pipe_vertex_element));
(nr_vertex_elements - 1) * sizeof(struct pipe_vertex_element) +
MAX2(nr_samplers, nr_sampler_views) *
sizeof(struct draw_sampler_static_state) +
nr_images * sizeof(struct draw_image_static_state));
}
static inline size_t
draw_gs_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
draw_gs_llvm_variant_key_size(unsigned nr_samplers,
unsigned nr_sampler_views,
unsigned nr_images)
{
return (sizeof(struct draw_gs_llvm_variant_key) +
(nr_images) * sizeof(struct draw_sampler_static_state) +
(nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
(MAX2(nr_samplers, nr_sampler_views) - 1) *
sizeof(struct draw_sampler_static_state) +
nr_images * sizeof(struct draw_sampler_static_state));
}
static inline size_t
draw_tcs_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
draw_tcs_llvm_variant_key_size(unsigned nr_samplers,
unsigned nr_sampler_views,
unsigned nr_images)
{
return (sizeof(struct draw_tcs_llvm_variant_key) +
(nr_images) * sizeof(struct draw_sampler_static_state) +
(nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
(MAX2(nr_samplers, nr_sampler_views) - 1) *
sizeof(struct draw_sampler_static_state) +
nr_images * sizeof(struct draw_sampler_static_state));
}
static inline size_t
draw_tes_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
draw_tes_llvm_variant_key_size(unsigned nr_samplers,
unsigned nr_sampler_views,
unsigned nr_images)
{
return (sizeof(struct draw_tes_llvm_variant_key) +
(nr_images) * sizeof(struct draw_sampler_static_state) +
(nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
(MAX2(nr_samplers, nr_sampler_views) - 1) *
sizeof(struct draw_sampler_static_state) +
nr_images * sizeof(struct draw_sampler_static_state));
}
static inline struct draw_sampler_static_state *
@ -623,28 +635,28 @@ draw_llvm_variant_key_images(struct draw_llvm_variant_key *key)
struct draw_sampler_static_state *samplers = (struct draw_sampler_static_state *)
(&key->vertex_element[key->nr_vertex_elements]);
return (struct draw_image_static_state *)
&samplers[key->nr_samplers];
&samplers[MAX2(key->nr_samplers, key->nr_sampler_views)];
}
static inline struct draw_image_static_state *
draw_gs_llvm_variant_key_images(struct draw_gs_llvm_variant_key *key)
{
return (struct draw_image_static_state *)
&key->samplers[key->nr_samplers];
&key->samplers[MAX2(key->nr_samplers, key->nr_sampler_views)];
}
static inline struct draw_image_static_state *
draw_tcs_llvm_variant_key_images(struct draw_tcs_llvm_variant_key *key)
{
return (struct draw_image_static_state *)
&key->samplers[key->nr_samplers];
&key->samplers[MAX2(key->nr_samplers, key->nr_sampler_views)];
}
static inline struct draw_image_static_state *
draw_tes_llvm_variant_key_images(struct draw_tes_llvm_variant_key *key)
{
return (struct draw_image_static_state *)
&key->samplers[key->nr_samplers];
&key->samplers[MAX2(key->nr_samplers, key->nr_sampler_views)];
}
struct draw_llvm_variant_list_item

View file

@ -460,8 +460,8 @@ draw_create_tess_ctrl_shader(struct draw_context *draw,
tcs->jit_context = &draw->llvm->tcs_jit_context;
llvm_tcs->variant_key_size =
draw_tcs_llvm_variant_key_size(
MAX2(tcs->info.file_max[TGSI_FILE_SAMPLER]+1,
tcs->info.file_max[TGSI_FILE_SAMPLER_VIEW]+1),
tcs->info.file_max[TGSI_FILE_SAMPLER]+1,
tcs->info.file_max[TGSI_FILE_SAMPLER_VIEW]+1,
tcs->info.file_max[TGSI_FILE_IMAGE]+1);
}
#endif
@ -585,8 +585,8 @@ draw_create_tess_eval_shader(struct draw_context *draw,
tes->jit_context = &draw->llvm->tes_jit_context;
llvm_tes->variant_key_size =
draw_tes_llvm_variant_key_size(
MAX2(tes->info.file_max[TGSI_FILE_SAMPLER]+1,
tes->info.file_max[TGSI_FILE_SAMPLER_VIEW]+1),
tes->info.file_max[TGSI_FILE_SAMPLER]+1,
tes->info.file_max[TGSI_FILE_SAMPLER_VIEW]+1,
tes->info.file_max[TGSI_FILE_IMAGE]+1);
}
#endif

View file

@ -111,8 +111,8 @@ draw_create_vs_llvm(struct draw_context *draw,
vs->variant_key_size =
draw_llvm_variant_key_size(
vs->base.info.file_max[TGSI_FILE_INPUT]+1,
MAX2(vs->base.info.file_max[TGSI_FILE_SAMPLER]+1,
vs->base.info.file_max[TGSI_FILE_SAMPLER_VIEW]+1),
vs->base.info.file_max[TGSI_FILE_SAMPLER]+1,
vs->base.info.file_max[TGSI_FILE_SAMPLER_VIEW]+1,
vs->base.info.file_max[TGSI_FILE_IMAGE]+1);
vs->base.state.type = state->type;