lima: fix crash with sparse samplers

Fixes following piglit tests:
spec@arb_fragment_program@fp-fragment-position
spec@arb_fragment_program@sparse-samplers

Reviewed-by: Andreas Baierl <ichgeh@imkreisrum.de>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13939>
This commit is contained in:
Vasily Khoruzhick
2021-11-23 18:02:33 -08:00
committed by Marge Bot
parent e48f676835
commit 437b97de1c
2 changed files with 15 additions and 2 deletions

View File

@@ -591,15 +591,19 @@ lima_update_fs_state(struct lima_context *ctx)
memcpy(key->nir_sha1, ctx->uncomp_fs->nir_sha1,
sizeof(ctx->uncomp_fs->nir_sha1));
uint8_t identity[4] = { PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y,
PIPE_SWIZZLE_Z, PIPE_SWIZZLE_W };
for (int i = 0; i < lima_tex->num_textures; i++) {
struct lima_sampler_view *sampler = lima_sampler_view(lima_tex->textures[i]);
if (!sampler) {
memcpy(key->tex[i].swizzle, identity, 4);
continue;
}
for (int j = 0; j < 4; j++)
key->tex[i].swizzle[j] = sampler->swizzle[j];
}
/* Fill rest with identity swizzle */
uint8_t identity[4] = { PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y,
PIPE_SWIZZLE_Z, PIPE_SWIZZLE_W };
for (int i = lima_tex->num_textures; i < ARRAY_SIZE(key->tex); i++)
memcpy(key->tex[i].swizzle, identity, 4);

View File

@@ -161,6 +161,9 @@ lima_update_tex_desc(struct lima_context *ctx, struct lima_sampler_state *sample
memset(desc, 0, desc_size);
if (!texture)
return;
switch (texture->base.target) {
case PIPE_TEXTURE_1D:
desc->sampler_dim = LIMA_SAMPLER_DIM_1D;
@@ -260,6 +263,10 @@ lima_calc_tex_desc_size(struct lima_sampler_view *texture)
{
unsigned size = offsetof(lima_tex_desc, va);
unsigned va_bit_size;
if (!texture)
return lima_min_tex_desc_size;
unsigned first_level = texture->base.u.tex.first_level;
unsigned last_level = texture->base.u.tex.last_level;
@@ -288,6 +295,8 @@ lima_update_textures(struct lima_context *ctx)
/* we always need to add texture bo to job */
for (int i = 0; i < lima_tex->num_samplers; i++) {
struct lima_sampler_view *texture = lima_sampler_view(lima_tex->textures[i]);
if (!texture)
continue;
struct lima_resource *rsc = lima_resource(texture->base.texture);
lima_flush_previous_job_writing_resource(ctx, texture->base.texture);
lima_job_add_bo(job, LIMA_PIPE_PP, rsc->bo, LIMA_SUBMIT_BO_READ);