v3dv: use common interfaces for shader modules

squashed changes from Alejandro Piñeiro <apinheiro@igalia.com>:

Add call to vk_object_base_init on internal shader_module: we have
some cases where internally we have some shader modules that we don't
create through CreateShaderModule, so in this case we need to manually
call base_init. Not sure why this wasn't needed before.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9508>
This commit is contained in:
Mike Blumenkrantz 2021-03-10 17:50:00 -05:00 committed by Marge Bot
parent 1d1c7a965c
commit 07c9dc54dd
4 changed files with 23 additions and 84 deletions

View file

@ -231,23 +231,23 @@ create_pipeline(struct v3dv_device *device,
const VkPipelineLayout layout,
VkPipeline *pipeline)
{
struct v3dv_shader_module vs_m;
struct v3dv_shader_module fs_m;
struct vk_shader_module vs_m;
struct vk_shader_module fs_m;
v3dv_shader_module_internal_init(&vs_m, vs_nir);
v3dv_shader_module_internal_init(&fs_m, fs_nir);
v3dv_shader_module_internal_init(device, &vs_m, vs_nir);
v3dv_shader_module_internal_init(device, &fs_m, fs_nir);
VkPipelineShaderStageCreateInfo stages[2] = {
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_VERTEX_BIT,
.module = v3dv_shader_module_to_handle(&vs_m),
.module = vk_shader_module_to_handle(&vs_m),
.pName = "main",
},
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
.module = v3dv_shader_module_to_handle(&fs_m),
.module = vk_shader_module_to_handle(&fs_m),
.pName = "main",
},
};

View file

@ -4682,23 +4682,23 @@ create_pipeline(struct v3dv_device *device,
const VkPipelineLayout layout,
VkPipeline *pipeline)
{
struct v3dv_shader_module vs_m;
struct v3dv_shader_module fs_m;
struct vk_shader_module vs_m;
struct vk_shader_module fs_m;
v3dv_shader_module_internal_init(&vs_m, vs_nir);
v3dv_shader_module_internal_init(&fs_m, fs_nir);
v3dv_shader_module_internal_init(device, &vs_m, vs_nir);
v3dv_shader_module_internal_init(device, &fs_m, fs_nir);
VkPipelineShaderStageCreateInfo stages[2] = {
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_VERTEX_BIT,
.module = v3dv_shader_module_to_handle(&vs_m),
.module = vk_shader_module_to_handle(&vs_m),
.pName = "main",
},
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
.module = v3dv_shader_module_to_handle(&fs_m),
.module = vk_shader_module_to_handle(&fs_m),
.pName = "main",
},
};

View file

@ -57,40 +57,13 @@ v3dv_print_v3d_key(struct v3d_key *key,
fprintf(stderr, "key %p: %s\n", key, sha1buf);
}
VkResult
v3dv_CreateShaderModule(VkDevice _device,
const VkShaderModuleCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkShaderModule *pShaderModule)
{
V3DV_FROM_HANDLE(v3dv_device, device, _device);
struct v3dv_shader_module *module;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO);
assert(pCreateInfo->flags == 0);
module = vk_object_zalloc(&device->vk, pAllocator,
sizeof(*module) + pCreateInfo->codeSize,
VK_OBJECT_TYPE_SHADER_MODULE);
if (module == NULL)
return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
module->nir = NULL;
module->size = pCreateInfo->codeSize;
memcpy(module->data, pCreateInfo->pCode, module->size);
_mesa_sha1_compute(module->data, module->size, module->sha1);
*pShaderModule = v3dv_shader_module_to_handle(module);
return VK_SUCCESS;
}
void
v3dv_shader_module_internal_init(struct v3dv_shader_module *module,
v3dv_shader_module_internal_init(struct v3dv_device *device,
struct vk_shader_module *module,
nir_shader *nir)
{
vk_object_base_init(&device->vk, &module->base,
VK_OBJECT_TYPE_SHADER_MODULE);
module->nir = nir;
module->size = 0;
@ -106,27 +79,6 @@ v3dv_shader_module_internal_init(struct v3dv_shader_module *module,
}
}
void
v3dv_DestroyShaderModule(VkDevice _device,
VkShaderModule _module,
const VkAllocationCallbacks *pAllocator)
{
V3DV_FROM_HANDLE(v3dv_device, device, _device);
V3DV_FROM_HANDLE(v3dv_shader_module, module, _module);
if (!module)
return;
/* NIR modules (which are only created internally by the driver) are not
* dynamically allocated so we should never call this for them.
* Instead the driver is responsible for freeing the NIR code when it is
* no longer needed.
*/
assert(module->nir == NULL);
vk_object_free(&device->vk, pAllocator, module);
}
void
v3dv_shader_variant_destroy(struct v3dv_device *device,
struct v3dv_shader_variant *variant)
@ -1778,7 +1730,7 @@ pipeline_stage_get_nir(struct v3dv_pipeline_stage *p_stage,
}
static void
pipeline_hash_shader(const struct v3dv_shader_module *module,
pipeline_hash_shader(const struct vk_shader_module *module,
const char *entrypoint,
gl_shader_stage stage,
const VkSpecializationInfo *spec_info,
@ -1927,7 +1879,7 @@ pipeline_compile_graphics(struct v3dv_pipeline *pipeline,
if (stage == MESA_SHADER_VERTEX)
p_stage->is_coord = false;
p_stage->entrypoint = sinfo->pName;
p_stage->module = v3dv_shader_module_from_handle(sinfo->module);
p_stage->module = vk_shader_module_from_handle(sinfo->module);
p_stage->spec_info = sinfo->pSpecializationInfo;
pipeline_hash_shader(p_stage->module,
@ -3048,7 +3000,7 @@ pipeline_compile_compute(struct v3dv_pipeline *pipeline,
p_stage->pipeline = pipeline;
p_stage->stage = stage;
p_stage->entrypoint = sinfo->pName;
p_stage->module = v3dv_shader_module_from_handle(sinfo->module);
p_stage->module = vk_shader_module_from_handle(sinfo->module);
p_stage->spec_info = sinfo->pSpecializationInfo;
pipeline_hash_shader(p_stage->module,

View file

@ -39,6 +39,7 @@
#include "vk_device.h"
#include "vk_instance.h"
#include "vk_physical_device.h"
#include "vk_shader_module.h"
#include <xf86drm.h>
@ -1283,20 +1284,6 @@ struct v3dv_event {
int state;
};
struct v3dv_shader_module {
struct vk_object_base base;
/* A NIR shader. We create NIR modules for shaders that are generated
* internally by the driver.
*/
struct nir_shader *nir;
/* A SPIR-V shader */
unsigned char sha1[20];
uint32_t size;
char data[0];
};
/* FIXME: the same function at anv, radv and tu, perhaps create common
* place?
*/
@ -1365,7 +1352,7 @@ struct v3dv_pipeline_stage {
*/
bool is_coord;
const struct v3dv_shader_module *module;
const struct vk_shader_module *module;
const char *entrypoint;
const VkSpecializationInfo *spec_info;
@ -1968,7 +1955,8 @@ v3dv_pipeline_cache_upload_variant(struct v3dv_pipeline *pipeline,
struct v3dv_pipeline_cache *cache,
struct v3dv_shader_variant *variant);
void v3dv_shader_module_internal_init(struct v3dv_shader_module *module,
void v3dv_shader_module_internal_init(struct v3dv_device *device,
struct vk_shader_module *module,
nir_shader *nir);
#define V3DV_DEFINE_HANDLE_CASTS(__v3dv_type, __VkType) \
@ -2027,7 +2015,6 @@ V3DV_DEFINE_NONDISP_HANDLE_CASTS(v3dv_query_pool, VkQueryPool)
V3DV_DEFINE_NONDISP_HANDLE_CASTS(v3dv_render_pass, VkRenderPass)
V3DV_DEFINE_NONDISP_HANDLE_CASTS(v3dv_sampler, VkSampler)
V3DV_DEFINE_NONDISP_HANDLE_CASTS(v3dv_semaphore, VkSemaphore)
V3DV_DEFINE_NONDISP_HANDLE_CASTS(v3dv_shader_module, VkShaderModule)
/* This is defined as a macro so that it works for both
* VkImageSubresourceRange and VkImageSubresourceLayers