Module: Mesa Branch: main Commit: 68e914a4caad5132d728b9e98ef67c43c4cc4355 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=68e914a4caad5132d728b9e98ef67c43c4cc4355
Author: Mike Blumenkrantz <[email protected]> Date: Tue Jan 31 11:19:47 2023 -0500 zink: rework descriptor buffer templating to use offsets compute programs can be reused across contexts, which means storing any pointers directly like this is going to lead to desync and crash instead, make this like regular descriptor templates and calculate the offset from the current context to ensure that everything works as it should fixes #8201 Fixes: 7ab5c5d36d2 ("zink: use EXT_descriptor_buffer with ZINK_DESCRIPTORS=db") Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21020> --- src/gallium/drivers/zink/zink_descriptors.c | 20 ++++++++++---------- src/gallium/drivers/zink/zink_types.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/gallium/drivers/zink/zink_descriptors.c b/src/gallium/drivers/zink/zink_descriptors.c index 441217d54d7..bf41900856f 100644 --- a/src/gallium/drivers/zink/zink_descriptors.c +++ b/src/gallium/drivers/zink/zink_descriptors.c @@ -318,42 +318,42 @@ init_db_template_entry(struct zink_context *ctx, struct zink_shader *shader, enu switch (shader->bindings[type][idx].type) { case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: - entry->mem = (void*)&ctx->di.db.ubos[stage][index]; + entry->offset = offsetof(struct zink_context, di.db.ubos[stage][index]); entry->stride = sizeof(VkDescriptorAddressInfoEXT); entry->db_size = screen->info.db_props.robustUniformBufferDescriptorSize; break; case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: - entry->mem = (void*)&ctx->di.textures[stage][index]; + entry->offset = offsetof(struct zink_context, di.textures[stage][index]); entry->stride = sizeof(VkDescriptorImageInfo); entry->db_size = screen->info.db_props.combinedImageSamplerDescriptorSize; break; case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: - entry->mem = (void*)&ctx->di.textures[stage][index]; + entry->offset = offsetof(struct zink_context, di.textures[stage][index]); entry->stride = sizeof(VkDescriptorImageInfo); entry->db_size = screen->info.db_props.sampledImageDescriptorSize; break; case VK_DESCRIPTOR_TYPE_SAMPLER: - entry->mem = (void*)&ctx->di.textures[stage][index]; + entry->offset = offsetof(struct zink_context, di.textures[stage][index]); entry->stride = sizeof(VkDescriptorImageInfo); entry->db_size = screen->info.db_props.samplerDescriptorSize; break; case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: - entry->mem = (void*)&ctx->di.db.tbos[stage][index]; + entry->offset = offsetof(struct zink_context, di.db.tbos[stage][index]); entry->stride = sizeof(VkDescriptorAddressInfoEXT); entry->db_size = screen->info.db_props.robustUniformTexelBufferDescriptorSize; break; case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: - entry->mem = (void*)&ctx->di.db.ssbos[stage][index]; + entry->offset = offsetof(struct zink_context, di.db.ssbos[stage][index]); entry->stride = sizeof(VkDescriptorAddressInfoEXT); entry->db_size = screen->info.db_props.robustStorageBufferDescriptorSize; break; case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: - entry->mem = (void*)&ctx->di.images[stage][index]; + entry->offset = offsetof(struct zink_context, di.images[stage][index]); entry->stride = sizeof(VkDescriptorImageInfo); entry->db_size = screen->info.db_props.storageImageDescriptorSize; break; case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: - entry->mem = (void*)&ctx->di.db.texel_images[stage][index]; + entry->offset = offsetof(struct zink_context, di.db.texel_images[stage][index]); entry->stride = sizeof(VkDescriptorAddressInfoEXT); entry->db_size = screen->info.db_props.robustStorageTexelBufferDescriptorSize; break; @@ -979,7 +979,7 @@ zink_descriptors_update_masked_buffer(struct zink_context *ctx, bool is_compute, key->bindings[i].descriptorCount == 1) { for (unsigned j = 0; j < key->bindings[i].descriptorCount; j++) { /* VkDescriptorDataEXT is a union of pointers; the member doesn't matter */ - info.data.pSampler = (void*)(pg->dd.db_template[type][i].mem + j * pg->dd.db_template[type][i].stride); + info.data.pSampler = (void*)(((uint8_t*)ctx) + pg->dd.db_template[type][i].offset + j * pg->dd.db_template[type][i].stride); VKSCR(GetDescriptorEXT)(screen->dev, &info, pg->dd.db_template[type][i].db_size, bs->dd.db_map[type] + desc_offset + j * pg->dd.db_template[type][i].db_size); } } else { @@ -989,7 +989,7 @@ zink_descriptors_update_masked_buffer(struct zink_context *ctx, bool is_compute, uint8_t *samplers = db + key->bindings[i].descriptorCount * screen->info.db_props.sampledImageDescriptorSize; for (unsigned j = 0; j < key->bindings[i].descriptorCount; j++) { /* VkDescriptorDataEXT is a union of pointers; the member doesn't matter */ - info.data.pSampler = (void*)(pg->dd.db_template[ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW][i].mem + + info.data.pSampler = (void*)(((uint8_t*)ctx) + pg->dd.db_template[ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW][i].offset + j * pg->dd.db_template[ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW][i].stride); VKSCR(GetDescriptorEXT)(screen->dev, &info, pg->dd.db_template[type][ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW].db_size, buf); /* drivers that don't support combinedImageSamplerDescriptorSingleArray must have sampler arrays written in memory as diff --git a/src/gallium/drivers/zink/zink_types.h b/src/gallium/drivers/zink/zink_types.h index 1e0208c1896..eeb14ca9afe 100644 --- a/src/gallium/drivers/zink/zink_types.h +++ b/src/gallium/drivers/zink/zink_types.h @@ -378,7 +378,7 @@ struct zink_descriptor_template { uint16_t stride; //the stride between mem pointers uint16_t db_size; //the size of the entry in the buffer unsigned count; //the number of descriptors - uint8_t *mem; //the base host pointer to update from + size_t offset; //the offset of the base host pointer to update from }; /* ctx->dd; created at context creation */
