VkPipeline *pipeline)
{
VkPipelineShaderStageCreateInfo stages[3] = { 0 };
- struct vk_shader_module vs_m;
+ struct vk_shader_module vs_m = vk_shader_module_from_nir(vs_nir);
struct vk_shader_module gs_m;
struct vk_shader_module fs_m;
uint32_t stage_count = 0;
- v3dv_shader_module_internal_init(device, &vs_m, vs_nir);
stages[stage_count].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
stages[stage_count].stage = VK_SHADER_STAGE_VERTEX_BIT;
stages[stage_count].module = vk_shader_module_to_handle(&vs_m);
stage_count++;
if (gs_nir) {
- v3dv_shader_module_internal_init(device, &gs_m, gs_nir);
+ gs_m = vk_shader_module_from_nir(gs_nir);
stages[stage_count].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
stages[stage_count].stage = VK_SHADER_STAGE_GEOMETRY_BIT;
stages[stage_count].module = vk_shader_module_to_handle(&gs_m);
}
if (fs_nir) {
- v3dv_shader_module_internal_init(device, &fs_m, fs_nir);
+ fs_m = vk_shader_module_from_nir(fs_nir);
stages[stage_count].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
stages[stage_count].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
stages[stage_count].module = vk_shader_module_to_handle(&fs_m);
const VkPipelineLayout layout,
VkPipeline *pipeline)
{
- struct vk_shader_module vs_m;
+ struct vk_shader_module vs_m = vk_shader_module_from_nir(vs_nir);
+ struct vk_shader_module fs_m = vk_shader_module_from_nir(fs_nir);
struct vk_shader_module gs_m;
- struct vk_shader_module fs_m;
uint32_t num_stages = gs_nir ? 3 : 2;
- v3dv_shader_module_internal_init(device, &vs_m, vs_nir);
- v3dv_shader_module_internal_init(device, &fs_m, fs_nir);
VkPipelineShaderStageCreateInfo stages[3] = {
{
};
if (gs_nir) {
- v3dv_shader_module_internal_init(device, &gs_m, gs_nir);
+ gs_m = vk_shader_module_from_nir(gs_nir);
stages[2].module = vk_shader_module_to_handle(&gs_m);
}
#include "util/u_prim.h"
#include "util/os_time.h"
+#include "vk_pipeline.h"
#include "vulkan/util/vk_format.h"
static VkResult
}
static void
-pipeline_compute_sha1_from_nir(nir_shader *nir,
- unsigned char sha1[20])
+pipeline_compute_sha1_from_nir(struct v3dv_pipeline_stage *p_stage)
{
- assert(nir);
- struct blob blob;
- blob_init(&blob);
-
- nir_serialize(&blob, nir, false);
- if (!blob.out_of_memory)
- _mesa_sha1_compute(blob.data, blob.size, sha1);
-
- blob_finish(&blob);
-}
-
-void
-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;
+ VkPipelineShaderStageCreateInfo info = {
+ .module = vk_shader_module_handle_from_nir(p_stage->nir),
+ .pName = p_stage->entrypoint,
+ .stage = mesa_to_vk_shader_stage(p_stage->nir->info.stage),
+ };
- pipeline_compute_sha1_from_nir(nir, module->sha1);
+ vk_pipeline_hash_shader_stage(&info, p_stage->shader_sha1);
}
void
return NULL;
}
-static void
-pipeline_hash_shader(const struct vk_shader_module *module,
- const char *entrypoint,
- gl_shader_stage stage,
- const VkSpecializationInfo *spec_info,
- unsigned char *sha1_out)
-{
- struct mesa_sha1 ctx;
- _mesa_sha1_init(&ctx);
-
- _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
- _mesa_sha1_update(&ctx, entrypoint, strlen(entrypoint));
- _mesa_sha1_update(&ctx, &stage, sizeof(stage));
- if (spec_info) {
- _mesa_sha1_update(&ctx, spec_info->pMapEntries,
- spec_info->mapEntryCount *
- sizeof(*spec_info->pMapEntries));
- _mesa_sha1_update(&ctx, spec_info->pData,
- spec_info->dataSize);
- }
-
- _mesa_sha1_final(&ctx, sha1_out);
-}
-
static VkResult
pipeline_compile_vertex_shader(struct v3dv_pipeline *pipeline,
const VkAllocationCallbacks *pAllocator,
p_stage->entrypoint = "main";
p_stage->module = 0;
p_stage->nir = nir;
- pipeline_compute_sha1_from_nir(p_stage->nir, p_stage->shader_sha1);
+ pipeline_compute_sha1_from_nir(p_stage);
p_stage->program_id = p_atomic_inc_return(&physical_device->next_program_id);
pipeline->has_gs = true;
p_stage->module = vk_shader_module_from_handle(sinfo->module);
p_stage->spec_info = sinfo->pSpecializationInfo;
- pipeline_hash_shader(p_stage->module,
- p_stage->entrypoint,
- stage,
- p_stage->spec_info,
- p_stage->shader_sha1);
+ vk_pipeline_hash_shader_stage(&pCreateInfo->pStages[i], p_stage->shader_sha1);
pipeline->active_stages |= sinfo->stage;
p_stage->entrypoint = "main";
p_stage->module = 0;
p_stage->nir = b.shader;
- pipeline_compute_sha1_from_nir(p_stage->nir, p_stage->shader_sha1);
+ pipeline_compute_sha1_from_nir(p_stage);
p_stage->program_id =
p_atomic_inc_return(&physical_device->next_program_id);
p_stage->spec_info = sinfo->pSpecializationInfo;
p_stage->feedback = (VkPipelineCreationFeedbackEXT) { 0 };
- pipeline_hash_shader(p_stage->module,
- p_stage->entrypoint,
- stage,
- p_stage->spec_info,
- p_stage->shader_sha1);
+ vk_pipeline_hash_shader_stage(&info->stage, p_stage->shader_sha1);
p_stage->nir = NULL;