diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 97a5cff9626..f8248f137ca 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -1269,16 +1269,20 @@ panfrost_emit_texture_descriptors(struct panfrost_batch *batch, return; if (device->quirks & IS_BIFROST) { - struct bifrost_texture_descriptor *descriptors; + struct panfrost_transfer T = panfrost_pool_alloc(&batch->pool, + MALI_BIFROST_TEXTURE_LENGTH * + ctx->sampler_view_count[stage]); - descriptors = malloc(sizeof(struct bifrost_texture_descriptor) * - ctx->sampler_view_count[stage]); + struct mali_bifrost_texture_packed *out = + (struct mali_bifrost_texture_packed *) T.cpu; for (int i = 0; i < ctx->sampler_view_count[stage]; ++i) { struct panfrost_sampler_view *view = ctx->sampler_views[stage][i]; struct pipe_sampler_view *pview = &view->base; struct panfrost_resource *rsrc = pan_resource(pview->texture); + panfrost_update_sampler_view(view, &ctx->base); + out[i] = view->bifrost_descriptor; /* Add the BOs to the job so they are retained until the job is done. */ @@ -1289,16 +1293,9 @@ panfrost_emit_texture_descriptors(struct panfrost_batch *batch, panfrost_batch_add_bo(batch, view->bo, PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_READ | panfrost_bo_access_for_stage(stage)); - - memcpy(&descriptors[i], view->bifrost_descriptor, sizeof(*view->bifrost_descriptor)); } - postfix->textures = panfrost_pool_upload(&batch->pool, - descriptors, - sizeof(struct bifrost_texture_descriptor) * - ctx->sampler_view_count[stage]); - - free(descriptors); + postfix->textures = T.gpu; } else { uint64_t trampolines[PIPE_MAX_SHADER_SAMPLER_VIEWS]; diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 18e6f78cd4b..0efe0a90fc3 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -975,9 +975,8 @@ panfrost_create_sampler_view_bo(struct panfrost_sampler_view *so, so->bo = panfrost_bo_create(device, size, 0); - so->bifrost_descriptor = rzalloc(pctx, struct bifrost_texture_descriptor); panfrost_new_texture_bifrost( - so->bifrost_descriptor, + &so->bifrost_descriptor, texture->width0, texture->height0, depth, array_size, format, @@ -1078,8 +1077,6 @@ panfrost_sampler_view_destroy( pipe_resource_reference(&pview->texture, NULL); panfrost_bo_unreference(view->bo); - if (view->bifrost_descriptor) - ralloc_free(view->bifrost_descriptor); ralloc_free(view); } diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index 680ff5e64e7..390010ce695 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -277,7 +277,7 @@ struct panfrost_sampler_state { struct panfrost_sampler_view { struct pipe_sampler_view base; struct panfrost_bo *bo; - struct bifrost_texture_descriptor *bifrost_descriptor; + struct mali_bifrost_texture_packed bifrost_descriptor; mali_ptr texture_bo; uint64_t modifier; }; diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h index 20209e95dc1..09ff583ab44 100644 --- a/src/panfrost/include/panfrost-job.h +++ b/src/panfrost/include/panfrost-job.h @@ -1148,39 +1148,6 @@ struct bifrost_payload_fused { /* For each pointer, there is an address and optionally also a stride */ #define MAX_ELEMENTS (2) -/* While Midgard texture descriptors are variable length, Bifrost descriptors - * are fixed like samplers with more pointers to expand if necessary */ - -struct bifrost_texture_descriptor { - unsigned format_unk : 4; /* 2 */ - enum mali_texture_dimension type : 2; - unsigned zero : 4; - unsigned format_swizzle : 12; - enum mali_format format : 8; - unsigned srgb : 1; - unsigned format_unk3 : 1; /* 0 */ - - uint16_t width; /* MALI_POSITIVE */ - uint16_t height; /* MALI_POSITIVE */ - - /* OpenGL swizzle */ - unsigned swizzle : 12; - enum mali_texture_layout layout : 4; - uint8_t levels : 8; /* Number of levels-1 if mipmapped, 0 if not */ - unsigned unk1 : 8; - - unsigned levels_unk : 24; /* 0 */ - unsigned level_2 : 8; /* Number of levels, again? */ - - mali_ptr payload; - - uint16_t array_size; - uint16_t unk4; - - uint16_t depth; - uint16_t unk5; -} __attribute__((packed)); - /* Used for lod encoding. Thanks @urjaman for pointing out these routines can * be cleaned up a lot. */ diff --git a/src/panfrost/lib/decode.c b/src/panfrost/lib/decode.c index 4589613b4ab..b218595560b 100644 --- a/src/panfrost/lib/decode.c +++ b/src/panfrost/lib/decode.c @@ -2109,102 +2109,17 @@ pandecode_texture(mali_ptr u, static void pandecode_bifrost_texture( - const struct bifrost_texture_descriptor *t, + const void *cl, unsigned job_no, unsigned tex) { - pandecode_log("struct bifrost_texture_descriptor texture_descriptor_%d_%d = {\n", job_no, tex); - pandecode_indent++; + struct MALI_BIFROST_TEXTURE temp; + MALI_BIFROST_TEXTURE_unpack(cl, &temp); + MALI_BIFROST_TEXTURE_print(pandecode_dump_stream, &temp, 2); - pandecode_prop("format_unk = 0x%" PRIx32, t->format_unk); - pandecode_prop("type = %" PRId32, t->type); - - if (t->zero) { - pandecode_msg("XXX: zero tripped\n"); - pandecode_prop("zero = 0x%" PRIx32, t->zero); - } - - pandecode_prop("format_swizzle = 0x%" PRIx32, t->format_swizzle); - pandecode_prop("format = 0x%" PRIx32, t->format); - pandecode_prop("srgb = 0x%" PRIx32, t->srgb); - pandecode_prop("format_unk3 = 0x%" PRIx32, t->format_unk3); - pandecode_prop("width = %" PRId32, t->width); - pandecode_prop("height = %" PRId32, t->height); - pandecode_prop("swizzle = 0x%" PRIx32, t->swizzle); - pandecode_prop("levels = %" PRId32, t->levels); - pandecode_prop("unk1 = 0x%" PRIx32, t->unk1); - pandecode_prop("levels_unk = %" PRId32, t->levels_unk); - pandecode_prop("level_2 = %" PRId32, t->level_2); - pandecode_prop("payload = 0x%" PRIx64, t->payload); - pandecode_prop("array_size = %" PRId32, t->array_size); - pandecode_prop("unk4 = 0x%" PRIx32, t->unk4); - pandecode_prop("depth = %" PRId32, t->depth); - pandecode_prop("unk5 = 0x%" PRIx32, t->unk5); - pandecode_log("\n"); - - bool is_cube = t->type == MALI_TEXTURE_DIMENSION_CUBE; - unsigned dimension = is_cube ? 2 : t->type; - - /* Print the layout. Default is linear; a modifier can denote AFBC or - * u-interleaved/tiled modes */ - - if (t->layout == MALI_TEXTURE_LAYOUT_AFBC) - pandecode_log_cont("afbc"); - else if (t->layout == MALI_TEXTURE_LAYOUT_TILED) - pandecode_log_cont("tiled"); - else if (t->layout == MALI_TEXTURE_LAYOUT_LINEAR) - pandecode_log_cont("linear"); - else - pandecode_msg("XXX: invalid texture layout 0x%X\n", t->layout); - - pandecode_swizzle(t->swizzle, t->format); - pandecode_log_cont(" "); - - /* Distinguish cube/2D with modifier */ - - if (is_cube) - pandecode_log_cont("cube "); - - pandecode_format_short(t->format, t->srgb); - - /* All four width/height/depth/array_size dimensions are present - * regardless of the type of texture, but it is an error to have - * non-zero dimensions for unused dimensions. Verify this. array_size - * can always be set, as can width. */ - - if (t->height && dimension < 2) - pandecode_msg("XXX: nonzero height for <2D texture\n"); - - if (t->depth && dimension < 3) - pandecode_msg("XXX: nonzero depth for <2D texture\n"); - - /* Print only the dimensions that are actually there */ - - pandecode_log_cont(": %d", t->width + 1); - - if (dimension >= 2) - pandecode_log_cont("x%u", t->height + 1); - - if (dimension >= 3) - pandecode_log_cont("x%u", t->depth + 1); - - if (t->array_size) - pandecode_log_cont("[%u]", t->array_size + 1); - - if (t->levels) - pandecode_log_cont(" mip %u", t->levels); - - pandecode_log_cont("\n"); - - struct pandecode_mapped_memory *tmem = pandecode_find_mapped_gpu_mem_containing(t->payload); - if (t->payload) { - pandecode_texture_payload(t->payload, t->type, t->layout, - true, t->levels, t->depth, - t->array_size, tmem); - } - - pandecode_indent--; - pandecode_log("};\n"); + struct pandecode_mapped_memory *tmem = pandecode_find_mapped_gpu_mem_containing(temp.surfaces); + pandecode_texture_payload(temp.surfaces, temp.dimension, temp.texel_ordering, + true, temp.levels, 1, 1, tmem); } /* For shader properties like texture_count, we have a claimed property in the shader_meta, and the actual Truth from static analysis (this may just be an upper limit). We validate accordingly */ @@ -2270,23 +2185,21 @@ pandecode_textures(mali_ptr textures, unsigned texture_count, int job_no, bool i if (!mmem) return; + pandecode_log("Textures (%"PRIx64"):\n", textures); + if (is_bifrost) { - const struct bifrost_texture_descriptor *PANDECODE_PTR_VAR(t, mmem, textures); + const void *cl = pandecode_fetch_gpu_mem(mmem, + textures, MALI_BIFROST_TEXTURE_LENGTH * + texture_count); - pandecode_log("uint64_t textures_%"PRIx64"_%d[] = {\n", textures, job_no); - pandecode_indent++; - - for (unsigned tex = 0; tex < texture_count; ++tex) - pandecode_bifrost_texture(&t[tex], job_no, tex); - - pandecode_indent--; - pandecode_log("};\n"); + for (unsigned tex = 0; tex < texture_count; ++tex) { + pandecode_bifrost_texture(cl + + MALI_BIFROST_TEXTURE_LENGTH * tex, + job_no, tex); + } } else { mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures); - pandecode_log("uint64_t textures_%"PRIx64"_%d[] = {\n", textures, job_no); - pandecode_indent++; - for (int tex = 0; tex < texture_count; ++tex) { mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures + tex * sizeof(mali_ptr)); char *a = pointer_as_memory_reference(*u); @@ -2294,9 +2207,6 @@ pandecode_textures(mali_ptr textures, unsigned texture_count, int job_no, bool i free(a); } - pandecode_indent--; - pandecode_log("};\n"); - /* Now, finally, descend down into the texture descriptor */ for (unsigned tex = 0; tex < texture_count; ++tex) { mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures + tex * sizeof(mali_ptr)); diff --git a/src/panfrost/lib/midgard.xml b/src/panfrost/lib/midgard.xml index 9a847741056..5a9acba2c4c 100644 --- a/src/panfrost/lib/midgard.xml +++ b/src/panfrost/lib/midgard.xml @@ -129,6 +129,20 @@ + + + + + + + + + + + + + + diff --git a/src/panfrost/lib/pan_texture.c b/src/panfrost/lib/pan_texture.c index 335e143b2e8..fce120803ac 100644 --- a/src/panfrost/lib/pan_texture.c +++ b/src/panfrost/lib/pan_texture.c @@ -352,7 +352,7 @@ panfrost_new_texture( void panfrost_new_texture_bifrost( - struct bifrost_texture_descriptor *descriptor, + struct mali_bifrost_texture_packed *out, uint16_t width, uint16_t height, uint16_t depth, uint16_t array_size, enum pipe_format format, @@ -388,24 +388,22 @@ panfrost_new_texture_bifrost( base, slices); - descriptor->format_unk = 0x2; - descriptor->type = dim; - descriptor->format = mali_format; - descriptor->srgb = (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB); - descriptor->format_unk3 = 0x0; - descriptor->width = MALI_POSITIVE(u_minify(width, first_level)); - descriptor->height = MALI_POSITIVE(u_minify(height, first_level)); - descriptor->swizzle = swizzle; - descriptor->layout = panfrost_modifier_to_layout(modifier), - descriptor->levels = last_level - first_level; - descriptor->unk1 = 0x0; - descriptor->levels_unk = 0; - descriptor->level_2 = last_level - first_level; - descriptor->payload = payload->gpu; - descriptor->array_size = MALI_POSITIVE(array_size); - descriptor->unk4 = 0x0; - descriptor->depth = MALI_POSITIVE(u_minify(depth, first_level)); - descriptor->unk5 = 0x0; + bool srgb = (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB); + + pan_pack(out, BIFROST_TEXTURE, cfg) { + cfg.dimension = dim; + cfg.format = (mali_format << 12) | (srgb << 20); + cfg.width = u_minify(width, first_level); + cfg.height = u_minify(height, first_level); + cfg.swizzle = swizzle; + cfg.texel_ordering = panfrost_modifier_to_layout(modifier); + cfg.levels = last_level - first_level; + cfg.surfaces = payload->gpu; + + /* Use the sampler descriptor for LOD clamping */ + cfg.minimum_lod = 0; + cfg.maximum_lod = last_level - first_level; + } } /* Computes sizes for checksumming, which is 8 bytes per 16x16 tile. diff --git a/src/panfrost/lib/pan_texture.h b/src/panfrost/lib/pan_texture.h index af12ee1ea64..4d2d5478baa 100644 --- a/src/panfrost/lib/pan_texture.h +++ b/src/panfrost/lib/pan_texture.h @@ -113,7 +113,7 @@ panfrost_new_texture( void panfrost_new_texture_bifrost( - struct bifrost_texture_descriptor *descriptor, + struct mali_bifrost_texture_packed *out, uint16_t width, uint16_t height, uint16_t depth, uint16_t array_size, enum pipe_format format,