mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 07:28:11 +02:00
radv: add a struct for the retained shaders and GPL
This will be used to remove the pipeline dependency completely when compiling graphics shaders. Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24423>
This commit is contained in:
parent
2050f2fe48
commit
5be4446abe
2 changed files with 24 additions and 15 deletions
|
|
@ -2299,7 +2299,7 @@ radv_graphics_shaders_nir_to_asm(struct radv_device *device, struct vk_pipeline_
|
|||
}
|
||||
|
||||
static void
|
||||
radv_pipeline_retain_shaders(struct radv_graphics_lib_pipeline *gfx_pipeline_lib, struct radv_shader_stage *stages)
|
||||
radv_pipeline_retain_shaders(struct radv_retained_shaders *retained_shaders, struct radv_shader_stage *stages)
|
||||
{
|
||||
for (unsigned s = 0; s < MESA_VULKAN_SHADER_STAGES; s++) {
|
||||
if (!stages[s].entrypoint)
|
||||
|
|
@ -2312,10 +2312,10 @@ radv_pipeline_retain_shaders(struct radv_graphics_lib_pipeline *gfx_pipeline_lib
|
|||
|
||||
blob_init(&blob);
|
||||
nir_serialize(&blob, stages[s].nir, true);
|
||||
blob_finish_get_buffer(&blob, &gfx_pipeline_lib->retained_shaders[s].serialized_nir,
|
||||
&gfx_pipeline_lib->retained_shaders[s].serialized_nir_size);
|
||||
blob_finish_get_buffer(&blob, &retained_shaders->stages[s].serialized_nir,
|
||||
&retained_shaders->stages[s].serialized_nir_size);
|
||||
|
||||
memcpy(gfx_pipeline_lib->retained_shaders[s].shader_sha1, stages[s].shader_sha1, sizeof(stages[s].shader_sha1));
|
||||
memcpy(retained_shaders->stages[s].shader_sha1, stages[s].shader_sha1, sizeof(stages[s].shader_sha1));
|
||||
|
||||
stages[s].feedback.duration += os_time_get_nano() - stage_start;
|
||||
}
|
||||
|
|
@ -2325,6 +2325,8 @@ static void
|
|||
radv_pipeline_import_retained_shaders(const struct radv_device *device, struct radv_graphics_pipeline *pipeline,
|
||||
struct radv_graphics_lib_pipeline *lib, struct radv_shader_stage *stages)
|
||||
{
|
||||
struct radv_retained_shaders *retained_shaders = &lib->retained_shaders;
|
||||
|
||||
/* Import the stages (SPIR-V only in case of cache hits). */
|
||||
for (uint32_t i = 0; i < lib->stage_count; i++) {
|
||||
const VkPipelineShaderStageCreateInfo *sinfo = &lib->stages[i];
|
||||
|
|
@ -2339,7 +2341,7 @@ radv_pipeline_import_retained_shaders(const struct radv_device *device, struct r
|
|||
|
||||
/* Import the NIR shaders (after SPIRV->NIR). */
|
||||
for (uint32_t s = 0; s < ARRAY_SIZE(lib->base.base.shaders); s++) {
|
||||
if (!lib->retained_shaders[s].serialized_nir_size)
|
||||
if (!retained_shaders->stages[s].serialized_nir_size)
|
||||
continue;
|
||||
|
||||
int64_t stage_start = os_time_get_nano();
|
||||
|
|
@ -2347,13 +2349,13 @@ radv_pipeline_import_retained_shaders(const struct radv_device *device, struct r
|
|||
/* Deserialize the NIR shader. */
|
||||
const struct nir_shader_compiler_options *options = &device->physical_device->nir_options[s];
|
||||
struct blob_reader blob_reader;
|
||||
blob_reader_init(&blob_reader, lib->retained_shaders[s].serialized_nir,
|
||||
lib->retained_shaders[s].serialized_nir_size);
|
||||
blob_reader_init(&blob_reader, retained_shaders->stages[s].serialized_nir,
|
||||
retained_shaders->stages[s].serialized_nir_size);
|
||||
|
||||
stages[s].stage = s;
|
||||
stages[s].nir = nir_deserialize(NULL, options, &blob_reader);
|
||||
stages[s].entrypoint = nir_shader_get_entrypoint(stages[s].nir)->function->name;
|
||||
memcpy(stages[s].shader_sha1, lib->retained_shaders[s].shader_sha1, sizeof(stages[s].shader_sha1));
|
||||
memcpy(stages[s].shader_sha1, retained_shaders->stages[s].shader_sha1, sizeof(stages[s].shader_sha1));
|
||||
|
||||
stages[s].feedback.flags |= VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT;
|
||||
|
||||
|
|
@ -2599,7 +2601,8 @@ radv_graphics_pipeline_compile(struct radv_graphics_pipeline *pipeline, const Vk
|
|||
}
|
||||
|
||||
if (retain_shaders) {
|
||||
radv_pipeline_retain_shaders(radv_pipeline_to_graphics_lib(&pipeline->base), stages);
|
||||
struct radv_graphics_lib_pipeline *gfx_pipeline_lib = radv_pipeline_to_graphics_lib(&pipeline->base);
|
||||
radv_pipeline_retain_shaders(&gfx_pipeline_lib->retained_shaders, stages);
|
||||
}
|
||||
|
||||
VkShaderStageFlagBits active_nir_stages = 0;
|
||||
|
|
@ -4124,10 +4127,12 @@ radv_graphics_lib_pipeline_create(VkDevice _device, VkPipelineCache _cache,
|
|||
void
|
||||
radv_destroy_graphics_lib_pipeline(struct radv_device *device, struct radv_graphics_lib_pipeline *pipeline)
|
||||
{
|
||||
struct radv_retained_shaders *retained_shaders = &pipeline->retained_shaders;
|
||||
|
||||
radv_pipeline_layout_finish(device, &pipeline->layout);
|
||||
|
||||
for (unsigned i = 0; i < MESA_VULKAN_SHADER_STAGES; ++i) {
|
||||
free(pipeline->retained_shaders[i].serialized_nir);
|
||||
free(retained_shaders->stages[i].serialized_nir);
|
||||
}
|
||||
|
||||
ralloc_free(pipeline->mem_ctx);
|
||||
|
|
|
|||
|
|
@ -2363,6 +2363,14 @@ struct radv_ray_tracing_pipeline {
|
|||
bool traversal_uniform_robustness2 : 1;
|
||||
};
|
||||
|
||||
struct radv_retained_shaders {
|
||||
struct {
|
||||
void *serialized_nir;
|
||||
size_t serialized_nir_size;
|
||||
unsigned char shader_sha1[SHA1_DIGEST_LENGTH];
|
||||
} stages[MESA_VULKAN_SHADER_STAGES];
|
||||
};
|
||||
|
||||
struct radv_graphics_lib_pipeline {
|
||||
struct radv_graphics_pipeline base;
|
||||
|
||||
|
|
@ -2372,11 +2380,7 @@ struct radv_graphics_lib_pipeline {
|
|||
|
||||
VkGraphicsPipelineLibraryFlagsEXT lib_flags;
|
||||
|
||||
struct {
|
||||
void *serialized_nir;
|
||||
size_t serialized_nir_size;
|
||||
unsigned char shader_sha1[SHA1_DIGEST_LENGTH];
|
||||
} retained_shaders[MESA_VULKAN_SHADER_STAGES];
|
||||
struct radv_retained_shaders retained_shaders;
|
||||
|
||||
void *mem_ctx;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue