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",
},
};
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",
},
};
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;
}
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)
{
}
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,
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,
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,
#include "vk_device.h"
#include "vk_instance.h"
#include "vk_physical_device.h"
+#include "vk_shader_module.h"
#include <xf86drm.h>
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?
*/
*/
bool is_coord;
- const struct v3dv_shader_module *module;
+ const struct vk_shader_module *module;
const char *entrypoint;
const VkSpecializationInfo *spec_info;
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) \
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