From 1d1c7a965c6233eec8c9bbed8704b4d38626a31b Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 10 Mar 2021 17:49:46 -0500 Subject: [PATCH] radv: use common interfaces for shader modules Reviewed-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/radv_meta_blit.c | 18 +++--- src/amd/vulkan/radv_meta_blit2d.c | 49 ++++++---------- src/amd/vulkan/radv_meta_buffer.c | 19 +++--- src/amd/vulkan/radv_meta_bufimage.c | 100 ++++++++++++++------------------ src/amd/vulkan/radv_meta_clear.c | 17 ++---- src/amd/vulkan/radv_meta_dcc_retile.c | 8 +-- src/amd/vulkan/radv_meta_decompress.c | 25 +++----- src/amd/vulkan/radv_meta_fast_clear.c | 26 ++++----- src/amd/vulkan/radv_meta_fmask_expand.c | 8 +-- src/amd/vulkan/radv_meta_resolve.c | 25 ++++---- src/amd/vulkan/radv_meta_resolve_cs.c | 19 +++--- src/amd/vulkan/radv_meta_resolve_fs.c | 31 ++++------ src/amd/vulkan/radv_pipeline.c | 8 +-- src/amd/vulkan/radv_pipeline_cache.c | 2 +- src/amd/vulkan/radv_private.h | 4 +- src/amd/vulkan/radv_query.c | 32 +++++----- src/amd/vulkan/radv_shader.c | 59 ++----------------- src/amd/vulkan/radv_shader.h | 17 ++---- 18 files changed, 175 insertions(+), 292 deletions(-) diff --git a/src/amd/vulkan/radv_meta_blit.c b/src/amd/vulkan/radv_meta_blit.c index 78e68f1..e5c1b37 100644 --- a/src/amd/vulkan/radv_meta_blit.c +++ b/src/amd/vulkan/radv_meta_blit.c @@ -782,21 +782,21 @@ build_pipeline(struct radv_device *device, return VK_SUCCESS; } - struct radv_shader_module fs = {0}; - struct radv_shader_module vs = {.nir = build_nir_vertex_shader()}; + nir_shader *fs; + nir_shader *vs = build_nir_vertex_shader(); VkRenderPass rp; switch(aspect) { case VK_IMAGE_ASPECT_COLOR_BIT: - fs.nir = build_nir_copy_fragment_shader(tex_dim); + fs = build_nir_copy_fragment_shader(tex_dim); rp = device->meta_state.blit.render_pass[fs_key][0]; break; case VK_IMAGE_ASPECT_DEPTH_BIT: - fs.nir = build_nir_copy_fragment_shader_depth(tex_dim); + fs = build_nir_copy_fragment_shader_depth(tex_dim); rp = device->meta_state.blit.depth_only_rp[0]; break; case VK_IMAGE_ASPECT_STENCIL_BIT: - fs.nir = build_nir_copy_fragment_shader_stencil(tex_dim); + fs = build_nir_copy_fragment_shader_stencil(tex_dim); rp = device->meta_state.blit.stencil_only_rp[0]; break; default: @@ -812,13 +812,13 @@ build_pipeline(struct radv_device *device, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_VERTEX_BIT, - .module = radv_shader_module_to_handle(&vs), + .module = vk_shader_module_handle_from_nir(vs), .pName = "main", .pSpecializationInfo = NULL }, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_FRAGMENT_BIT, - .module = radv_shader_module_to_handle(&fs), + .module = vk_shader_module_handle_from_nir(fs), .pName = "main", .pSpecializationInfo = NULL }, @@ -935,8 +935,8 @@ build_pipeline(struct radv_device *device, radv_pipeline_cache_to_handle(&device->meta_state.cache), &vk_pipeline_info, &radv_pipeline_info, &device->meta_state.alloc, pipeline); - ralloc_free(vs.nir); - ralloc_free(fs.nir); + ralloc_free(vs); + ralloc_free(fs); mtx_unlock(&device->meta_state.mtx); return result; } diff --git a/src/amd/vulkan/radv_meta_blit2d.c b/src/amd/vulkan/radv_meta_blit2d.c index f3ddcf3..d2bd95b 100644 --- a/src/amd/vulkan/radv_meta_blit2d.c +++ b/src/amd/vulkan/radv_meta_blit2d.c @@ -730,27 +730,22 @@ blit2d_init_color_pipeline(struct radv_device *device, } const VkPipelineVertexInputStateCreateInfo *vi_create_info; - struct radv_shader_module fs = { .nir = NULL }; + nir_shader *fs = build_nir_copy_fragment_shader(device, src_func, name, src_type == BLIT2D_SRC_TYPE_IMAGE_3D, log2_samples > 0); + nir_shader *vs = build_nir_vertex_shader(); - - fs.nir = build_nir_copy_fragment_shader(device, src_func, name, src_type == BLIT2D_SRC_TYPE_IMAGE_3D, log2_samples > 0); vi_create_info = &normal_vi_create_info; - struct radv_shader_module vs = { - .nir = build_nir_vertex_shader(), - }; - VkPipelineShaderStageCreateInfo pipeline_shader_stages[] = { { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_VERTEX_BIT, - .module = radv_shader_module_to_handle(&vs), + .module = vk_shader_module_handle_from_nir(vs), .pName = "main", .pSpecializationInfo = NULL }, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_FRAGMENT_BIT, - .module = radv_shader_module_to_handle(&fs), + .module = vk_shader_module_handle_from_nir(fs), .pName = "main", .pSpecializationInfo = NULL }, @@ -891,8 +886,8 @@ blit2d_init_color_pipeline(struct radv_device *device, &device->meta_state.blit2d[log2_samples].pipelines[src_type][fs_key]); - ralloc_free(vs.nir); - ralloc_free(fs.nir); + ralloc_free(vs); + ralloc_free(fs); mtx_unlock(&device->meta_state.mtx); return result; @@ -932,26 +927,22 @@ blit2d_init_depth_only_pipeline(struct radv_device *device, } const VkPipelineVertexInputStateCreateInfo *vi_create_info; - struct radv_shader_module fs = { .nir = NULL }; + nir_shader *fs = build_nir_copy_fragment_shader_depth(device, src_func, name, src_type == BLIT2D_SRC_TYPE_IMAGE_3D, log2_samples > 0); + nir_shader *vs = build_nir_vertex_shader(); - fs.nir = build_nir_copy_fragment_shader_depth(device, src_func, name, src_type == BLIT2D_SRC_TYPE_IMAGE_3D, log2_samples > 0); vi_create_info = &normal_vi_create_info; - struct radv_shader_module vs = { - .nir = build_nir_vertex_shader(), - }; - VkPipelineShaderStageCreateInfo pipeline_shader_stages[] = { { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_VERTEX_BIT, - .module = radv_shader_module_to_handle(&vs), + .module = vk_shader_module_handle_from_nir(vs), .pName = "main", .pSpecializationInfo = NULL }, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_FRAGMENT_BIT, - .module = radv_shader_module_to_handle(&fs), + .module = vk_shader_module_handle_from_nir(fs), .pName = "main", .pSpecializationInfo = NULL }, @@ -1085,8 +1076,8 @@ blit2d_init_depth_only_pipeline(struct radv_device *device, &device->meta_state.blit2d[log2_samples].depth_only_pipeline[src_type]); - ralloc_free(vs.nir); - ralloc_free(fs.nir); + ralloc_free(vs); + ralloc_free(fs); mtx_unlock(&device->meta_state.mtx); return result; @@ -1126,26 +1117,22 @@ blit2d_init_stencil_only_pipeline(struct radv_device *device, } const VkPipelineVertexInputStateCreateInfo *vi_create_info; - struct radv_shader_module fs = { .nir = NULL }; + nir_shader *fs = build_nir_copy_fragment_shader_stencil(device, src_func, name, src_type == BLIT2D_SRC_TYPE_IMAGE_3D, log2_samples > 0); + nir_shader *vs = build_nir_vertex_shader(); - fs.nir = build_nir_copy_fragment_shader_stencil(device, src_func, name, src_type == BLIT2D_SRC_TYPE_IMAGE_3D, log2_samples > 0); vi_create_info = &normal_vi_create_info; - struct radv_shader_module vs = { - .nir = build_nir_vertex_shader(), - }; - VkPipelineShaderStageCreateInfo pipeline_shader_stages[] = { { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_VERTEX_BIT, - .module = radv_shader_module_to_handle(&vs), + .module = vk_shader_module_handle_from_nir(vs), .pName = "main", .pSpecializationInfo = NULL }, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_FRAGMENT_BIT, - .module = radv_shader_module_to_handle(&fs), + .module = vk_shader_module_handle_from_nir(fs), .pName = "main", .pSpecializationInfo = NULL }, @@ -1296,8 +1283,8 @@ blit2d_init_stencil_only_pipeline(struct radv_device *device, &device->meta_state.blit2d[log2_samples].stencil_only_pipeline[src_type]); - ralloc_free(vs.nir); - ralloc_free(fs.nir); + ralloc_free(vs); + ralloc_free(fs); mtx_unlock(&device->meta_state.mtx); return result; diff --git a/src/amd/vulkan/radv_meta_buffer.c b/src/amd/vulkan/radv_meta_buffer.c index 20f619b..187251a 100644 --- a/src/amd/vulkan/radv_meta_buffer.c +++ b/src/amd/vulkan/radv_meta_buffer.c @@ -72,11 +72,8 @@ build_buffer_copy_shader(struct radv_device *dev) VkResult radv_device_init_meta_buffer_state(struct radv_device *device) { VkResult result; - struct radv_shader_module fill_cs = { .nir = NULL }; - struct radv_shader_module copy_cs = { .nir = NULL }; - - fill_cs.nir = build_buffer_fill_shader(device); - copy_cs.nir = build_buffer_copy_shader(device); + nir_shader *fill_cs = build_buffer_fill_shader(device); + nir_shader *copy_cs = build_buffer_copy_shader(device); VkDescriptorSetLayoutCreateInfo fill_ds_create_info = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, @@ -162,7 +159,7 @@ VkResult radv_device_init_meta_buffer_state(struct radv_device *device) VkPipelineShaderStageCreateInfo fill_pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&fill_cs), + .module = vk_shader_module_handle_from_nir(fill_cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -184,7 +181,7 @@ VkResult radv_device_init_meta_buffer_state(struct radv_device *device) VkPipelineShaderStageCreateInfo copy_pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(©_cs), + .module = vk_shader_module_handle_from_nir(copy_cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -203,13 +200,13 @@ VkResult radv_device_init_meta_buffer_state(struct radv_device *device) if (result != VK_SUCCESS) goto fail; - ralloc_free(fill_cs.nir); - ralloc_free(copy_cs.nir); + ralloc_free(fill_cs); + ralloc_free(copy_cs); return VK_SUCCESS; fail: radv_device_finish_meta_buffer_state(device); - ralloc_free(fill_cs.nir); - ralloc_free(copy_cs.nir); + ralloc_free(fill_cs); + ralloc_free(copy_cs); return result; } diff --git a/src/amd/vulkan/radv_meta_bufimage.c b/src/amd/vulkan/radv_meta_bufimage.c index b305f46..f618d96 100644 --- a/src/amd/vulkan/radv_meta_bufimage.c +++ b/src/amd/vulkan/radv_meta_bufimage.c @@ -108,12 +108,11 @@ static VkResult radv_device_init_meta_itob_state(struct radv_device *device) { VkResult result; - struct radv_shader_module cs = { .nir = NULL }; - struct radv_shader_module cs_3d = { .nir = NULL }; + nir_shader *cs = build_nir_itob_compute_shader(device, false); + nir_shader *cs_3d = NULL; - cs.nir = build_nir_itob_compute_shader(device, false); if (device->physical_device->rad_info.chip_class >= GFX9) - cs_3d.nir = build_nir_itob_compute_shader(device, true); + cs_3d = build_nir_itob_compute_shader(device, true); /* * two descriptors one for the image being sampled @@ -169,7 +168,7 @@ radv_device_init_meta_itob_state(struct radv_device *device) VkPipelineShaderStageCreateInfo pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs), + .module = vk_shader_module_handle_from_nir(cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -192,7 +191,7 @@ radv_device_init_meta_itob_state(struct radv_device *device) VkPipelineShaderStageCreateInfo pipeline_shader_stage_3d = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs_3d), + .module = vk_shader_module_handle_from_nir(cs_3d), .pName = "main", .pSpecializationInfo = NULL, }; @@ -210,14 +209,14 @@ radv_device_init_meta_itob_state(struct radv_device *device) &device->meta_state.itob.pipeline_3d); if (result != VK_SUCCESS) goto fail; - ralloc_free(cs_3d.nir); + ralloc_free(cs_3d); } - ralloc_free(cs.nir); + ralloc_free(cs); return VK_SUCCESS; fail: - ralloc_free(cs.nir); - ralloc_free(cs_3d.nir); + ralloc_free(cs); + ralloc_free(cs_3d); return result; } @@ -314,11 +313,10 @@ static VkResult radv_device_init_meta_btoi_state(struct radv_device *device) { VkResult result; - struct radv_shader_module cs = { .nir = NULL }; - struct radv_shader_module cs_3d = { .nir = NULL }; - cs.nir = build_nir_btoi_compute_shader(device, false); + nir_shader *cs = build_nir_btoi_compute_shader(device, false); + nir_shader *cs_3d = NULL; if (device->physical_device->rad_info.chip_class >= GFX9) - cs_3d.nir = build_nir_btoi_compute_shader(device, true); + cs_3d = build_nir_btoi_compute_shader(device, true); /* * two descriptors one for the image being sampled * one for the buffer being written. @@ -373,7 +371,7 @@ radv_device_init_meta_btoi_state(struct radv_device *device) VkPipelineShaderStageCreateInfo pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs), + .module = vk_shader_module_handle_from_nir(cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -396,7 +394,7 @@ radv_device_init_meta_btoi_state(struct radv_device *device) VkPipelineShaderStageCreateInfo pipeline_shader_stage_3d = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs_3d), + .module = vk_shader_module_handle_from_nir(cs_3d), .pName = "main", .pSpecializationInfo = NULL, }; @@ -412,14 +410,14 @@ radv_device_init_meta_btoi_state(struct radv_device *device) radv_pipeline_cache_to_handle(&device->meta_state.cache), 1, &vk_pipeline_info_3d, NULL, &device->meta_state.btoi.pipeline_3d); - ralloc_free(cs_3d.nir); + ralloc_free(cs_3d); } - ralloc_free(cs.nir); + ralloc_free(cs); return VK_SUCCESS; fail: - ralloc_free(cs_3d.nir); - ralloc_free(cs.nir); + ralloc_free(cs_3d); + ralloc_free(cs); return result; } @@ -530,9 +528,7 @@ static VkResult radv_device_init_meta_btoi_r32g32b32_state(struct radv_device *device) { VkResult result; - struct radv_shader_module cs = { .nir = NULL }; - - cs.nir = build_nir_btoi_r32g32b32_compute_shader(device); + nir_shader *cs = build_nir_btoi_r32g32b32_compute_shader(device); VkDescriptorSetLayoutCreateInfo ds_create_info = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, @@ -584,7 +580,7 @@ radv_device_init_meta_btoi_r32g32b32_state(struct radv_device *device) VkPipelineShaderStageCreateInfo pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs), + .module = vk_shader_module_handle_from_nir(cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -602,7 +598,7 @@ radv_device_init_meta_btoi_r32g32b32_state(struct radv_device *device) &device->meta_state.btoi_r32g32b32.pipeline); fail: - ralloc_free(cs.nir); + ralloc_free(cs); return result; } @@ -690,11 +686,10 @@ static VkResult radv_device_init_meta_itoi_state(struct radv_device *device) { VkResult result; - struct radv_shader_module cs = { .nir = NULL }; - struct radv_shader_module cs_3d = { .nir = NULL }; - cs.nir = build_nir_itoi_compute_shader(device, false); + nir_shader *cs = build_nir_itoi_compute_shader(device, false); + nir_shader *cs_3d = NULL; if (device->physical_device->rad_info.chip_class >= GFX9) - cs_3d.nir = build_nir_itoi_compute_shader(device, true); + cs_3d = build_nir_itoi_compute_shader(device, true); /* * two descriptors one for the image being sampled * one for the buffer being written. @@ -749,7 +744,7 @@ radv_device_init_meta_itoi_state(struct radv_device *device) VkPipelineShaderStageCreateInfo pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs), + .module = vk_shader_module_handle_from_nir(cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -772,7 +767,7 @@ radv_device_init_meta_itoi_state(struct radv_device *device) VkPipelineShaderStageCreateInfo pipeline_shader_stage_3d = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs_3d), + .module = vk_shader_module_handle_from_nir(cs_3d), .pName = "main", .pSpecializationInfo = NULL, }; @@ -789,14 +784,14 @@ radv_device_init_meta_itoi_state(struct radv_device *device) 1, &vk_pipeline_info_3d, NULL, &device->meta_state.itoi.pipeline_3d); - ralloc_free(cs_3d.nir); + ralloc_free(cs_3d); } - ralloc_free(cs.nir); + ralloc_free(cs); return VK_SUCCESS; fail: - ralloc_free(cs.nir); - ralloc_free(cs_3d.nir); + ralloc_free(cs); + ralloc_free(cs_3d); return result; } @@ -918,9 +913,7 @@ static VkResult radv_device_init_meta_itoi_r32g32b32_state(struct radv_device *device) { VkResult result; - struct radv_shader_module cs = { .nir = NULL }; - - cs.nir = build_nir_itoi_r32g32b32_compute_shader(device); + nir_shader *cs = build_nir_itoi_r32g32b32_compute_shader(device); VkDescriptorSetLayoutCreateInfo ds_create_info = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, @@ -972,7 +965,7 @@ radv_device_init_meta_itoi_r32g32b32_state(struct radv_device *device) VkPipelineShaderStageCreateInfo pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs), + .module = vk_shader_module_handle_from_nir(cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -990,7 +983,7 @@ radv_device_init_meta_itoi_r32g32b32_state(struct radv_device *device) &device->meta_state.itoi_r32g32b32.pipeline); fail: - ralloc_free(cs.nir); + ralloc_free(cs); return result; } @@ -1056,11 +1049,10 @@ static VkResult radv_device_init_meta_cleari_state(struct radv_device *device) { VkResult result; - struct radv_shader_module cs = { .nir = NULL }; - struct radv_shader_module cs_3d = { .nir = NULL }; - cs.nir = build_nir_cleari_compute_shader(device, false); + nir_shader *cs = build_nir_cleari_compute_shader(device, false); + nir_shader *cs_3d = NULL; if (device->physical_device->rad_info.chip_class >= GFX9) - cs_3d.nir = build_nir_cleari_compute_shader(device, true); + cs_3d = build_nir_cleari_compute_shader(device, true); /* * two descriptors one for the image being sampled @@ -1109,7 +1101,7 @@ radv_device_init_meta_cleari_state(struct radv_device *device) VkPipelineShaderStageCreateInfo pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs), + .module = vk_shader_module_handle_from_nir(cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -1134,7 +1126,7 @@ radv_device_init_meta_cleari_state(struct radv_device *device) VkPipelineShaderStageCreateInfo pipeline_shader_stage_3d = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs_3d), + .module = vk_shader_module_handle_from_nir(cs_3d), .pName = "main", .pSpecializationInfo = NULL, }; @@ -1153,13 +1145,13 @@ radv_device_init_meta_cleari_state(struct radv_device *device) if (result != VK_SUCCESS) goto fail; - ralloc_free(cs_3d.nir); + ralloc_free(cs_3d); } - ralloc_free(cs.nir); + ralloc_free(cs); return VK_SUCCESS; fail: - ralloc_free(cs.nir); - ralloc_free(cs_3d.nir); + ralloc_free(cs); + ralloc_free(cs_3d); return result; } @@ -1235,9 +1227,7 @@ static VkResult radv_device_init_meta_cleari_r32g32b32_state(struct radv_device *device) { VkResult result; - struct radv_shader_module cs = { .nir = NULL }; - - cs.nir = build_nir_cleari_r32g32b32_compute_shader(device); + nir_shader *cs = build_nir_cleari_r32g32b32_compute_shader(device); VkDescriptorSetLayoutCreateInfo ds_create_info = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, @@ -1280,7 +1270,7 @@ radv_device_init_meta_cleari_r32g32b32_state(struct radv_device *device) VkPipelineShaderStageCreateInfo pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs), + .module = vk_shader_module_handle_from_nir(cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -1298,7 +1288,7 @@ radv_device_init_meta_cleari_r32g32b32_state(struct radv_device *device) &device->meta_state.cleari_r32g32b32.pipeline); fail: - ralloc_free(cs.nir); + ralloc_free(cs); return result; } diff --git a/src/amd/vulkan/radv_meta_clear.c b/src/amd/vulkan/radv_meta_clear.c index e8db50a..57b0a3f 100644 --- a/src/amd/vulkan/radv_meta_clear.c +++ b/src/amd/vulkan/radv_meta_clear.c @@ -96,9 +96,6 @@ create_pipeline(struct radv_device *device, VkDevice device_h = radv_device_to_handle(device); VkResult result; - struct radv_shader_module vs_m = { .nir = vs_nir }; - struct radv_shader_module fs_m = { .nir = fs_nir }; - result = radv_graphics_pipeline_create(device_h, radv_pipeline_cache_to_handle(&device->meta_state.cache), &(VkGraphicsPipelineCreateInfo) { @@ -108,13 +105,13 @@ create_pipeline(struct radv_device *device, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_VERTEX_BIT, - .module = radv_shader_module_to_handle(&vs_m), + .module = vk_shader_module_handle_from_nir(vs_nir), .pName = "main", }, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_FRAGMENT_BIT, - .module = radv_shader_module_to_handle(&fs_m), + .module = vk_shader_module_handle_from_nir(fs_nir), .pName = "main", }, }, @@ -1128,10 +1125,8 @@ static VkResult init_meta_clear_htile_mask_state(struct radv_device *device) { struct radv_meta_state *state = &device->meta_state; - struct radv_shader_module cs = { .nir = NULL }; VkResult result; - - cs.nir = build_clear_htile_mask_shader(); + nir_shader *cs = build_clear_htile_mask_shader(); VkDescriptorSetLayoutCreateInfo ds_layout_info = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, @@ -1173,7 +1168,7 @@ init_meta_clear_htile_mask_state(struct radv_device *device) VkPipelineShaderStageCreateInfo shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs), + .module = vk_shader_module_handle_from_nir(cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -1190,10 +1185,10 @@ init_meta_clear_htile_mask_state(struct radv_device *device) 1, &pipeline_info, NULL, &state->clear_htile_mask_pipeline); - ralloc_free(cs.nir); + ralloc_free(cs); return result; fail: - ralloc_free(cs.nir); + ralloc_free(cs); return result; } diff --git a/src/amd/vulkan/radv_meta_dcc_retile.c b/src/amd/vulkan/radv_meta_dcc_retile.c index 7404792..6153155 100644 --- a/src/amd/vulkan/radv_meta_dcc_retile.c +++ b/src/amd/vulkan/radv_meta_dcc_retile.c @@ -117,9 +117,7 @@ VkResult radv_device_init_meta_dcc_retile_state(struct radv_device *device) { VkResult result = VK_SUCCESS; - struct radv_shader_module cs = { .nir = NULL }; - - cs.nir = build_dcc_retile_compute_shader(device); + nir_shader *cs = build_dcc_retile_compute_shader(device); VkDescriptorSetLayoutCreateInfo ds_create_info = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, @@ -177,7 +175,7 @@ radv_device_init_meta_dcc_retile_state(struct radv_device *device) VkPipelineShaderStageCreateInfo pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs), + .module = vk_shader_module_handle_from_nir(cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -199,7 +197,7 @@ radv_device_init_meta_dcc_retile_state(struct radv_device *device) cleanup: if (result != VK_SUCCESS) radv_device_finish_meta_dcc_retile_state(device); - ralloc_free(cs.nir); + ralloc_free(cs); return result; } diff --git a/src/amd/vulkan/radv_meta_decompress.c b/src/amd/vulkan/radv_meta_decompress.c index 3ab2a4b..25a3ff8 100644 --- a/src/amd/vulkan/radv_meta_decompress.c +++ b/src/amd/vulkan/radv_meta_decompress.c @@ -146,21 +146,10 @@ create_pipeline(struct radv_device *device, return VK_SUCCESS; } - struct radv_shader_module vs_module = { - .nir = radv_meta_build_nir_vs_generate_vertices() - }; - - if (!vs_module.nir) { - /* XXX: Need more accurate error */ - result = VK_ERROR_OUT_OF_HOST_MEMORY; - goto cleanup; - } - - struct radv_shader_module fs_module = { - .nir = radv_meta_build_nir_fs_noop(), - }; + nir_shader *vs_module = radv_meta_build_nir_vs_generate_vertices(); + nir_shader *fs_module = radv_meta_build_nir_fs_noop(); - if (!fs_module.nir) { + if (!vs_module || !fs_module) { /* XXX: Need more accurate error */ result = VK_ERROR_OUT_OF_HOST_MEMORY; goto cleanup; @@ -178,13 +167,13 @@ create_pipeline(struct radv_device *device, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_VERTEX_BIT, - .module = radv_shader_module_to_handle(&vs_module), + .module = vk_shader_module_handle_from_nir(vs_module), .pName = "main", }, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_FRAGMENT_BIT, - .module = radv_shader_module_to_handle(&fs_module), + .module = vk_shader_module_handle_from_nir(fs_module), .pName = "main", }, }, @@ -263,8 +252,8 @@ create_pipeline(struct radv_device *device, pipeline); cleanup: - ralloc_free(fs_module.nir); - ralloc_free(vs_module.nir); + ralloc_free(fs_module); + ralloc_free(vs_module); mtx_unlock(&device->meta_state.mtx); return result; } diff --git a/src/amd/vulkan/radv_meta_fast_clear.c b/src/amd/vulkan/radv_meta_fast_clear.c index 91eea8f..467b5b0 100644 --- a/src/amd/vulkan/radv_meta_fast_clear.c +++ b/src/amd/vulkan/radv_meta_fast_clear.c @@ -97,9 +97,7 @@ static VkResult create_dcc_compress_compute(struct radv_device *device) { VkResult result = VK_SUCCESS; - struct radv_shader_module cs = { .nir = NULL }; - - cs.nir = build_dcc_decompress_compute_shader(device); + nir_shader *cs = build_dcc_decompress_compute_shader(device); VkDescriptorSetLayoutCreateInfo ds_create_info = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, @@ -151,7 +149,7 @@ create_dcc_compress_compute(struct radv_device *device) VkPipelineShaderStageCreateInfo pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs), + .module = vk_shader_module_handle_from_nir(cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -171,7 +169,7 @@ create_dcc_compress_compute(struct radv_device *device) goto cleanup; cleanup: - ralloc_free(cs.nir); + ralloc_free(cs); return result; } @@ -272,11 +270,9 @@ create_pipeline(struct radv_device *device, VkResult result; VkDevice device_h = radv_device_to_handle(device); - struct radv_shader_module fs_module = { - .nir = radv_meta_build_nir_fs_noop(), - }; + nir_shader *fs_module = radv_meta_build_nir_fs_noop(); - if (!fs_module.nir) { + if (!fs_module) { /* XXX: Need more accurate error */ result = VK_ERROR_OUT_OF_HOST_MEMORY; goto cleanup; @@ -292,7 +288,7 @@ create_pipeline(struct radv_device *device, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_FRAGMENT_BIT, - .module = radv_shader_module_to_handle(&fs_module), + .module = vk_shader_module_handle_from_nir(fs_module), .pName = "main", }, }; @@ -472,7 +468,7 @@ create_pipeline(struct radv_device *device, goto cleanup; cleanup: - ralloc_free(fs_module.nir); + ralloc_free(fs_module); return result; } @@ -518,8 +514,8 @@ radv_device_init_meta_fast_clear_flush_state_internal(struct radv_device *device return VK_SUCCESS; } - struct radv_shader_module vs_module = { .nir = radv_meta_build_nir_vs_generate_vertices() }; - if (!vs_module.nir) { + nir_shader *vs_module = radv_meta_build_nir_vs_generate_vertices(); + if (!vs_module) { /* XXX: Need more accurate error */ res = VK_ERROR_OUT_OF_HOST_MEMORY; goto fail; @@ -534,7 +530,7 @@ radv_device_init_meta_fast_clear_flush_state_internal(struct radv_device *device if (res != VK_SUCCESS) goto fail; - VkShaderModule vs_module_h = radv_shader_module_to_handle(&vs_module); + VkShaderModule vs_module_h = vk_shader_module_handle_from_nir(vs_module); res = create_pipeline(device, vs_module_h, device->meta_state.fast_clear_flush.p_layout); if (res != VK_SUCCESS) @@ -550,7 +546,7 @@ fail: radv_device_finish_meta_fast_clear_flush_state(device); cleanup: - ralloc_free(vs_module.nir); + ralloc_free(vs_module); mtx_unlock(&device->meta_state.mtx); return res; diff --git a/src/amd/vulkan/radv_meta_fmask_expand.c b/src/amd/vulkan/radv_meta_fmask_expand.c index d134840..2cbb826 100644 --- a/src/amd/vulkan/radv_meta_fmask_expand.c +++ b/src/amd/vulkan/radv_meta_fmask_expand.c @@ -200,15 +200,13 @@ create_fmask_expand_pipeline(struct radv_device *device, VkPipeline *pipeline) { struct radv_meta_state *state = &device->meta_state; - struct radv_shader_module cs = { .nir = NULL }; VkResult result; - - cs.nir = build_fmask_expand_compute_shader(device, samples); + nir_shader *cs = build_fmask_expand_compute_shader(device, samples);; VkPipelineShaderStageCreateInfo pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs), + .module = vk_shader_module_handle_from_nir(cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -225,7 +223,7 @@ create_fmask_expand_pipeline(struct radv_device *device, 1, &vk_pipeline_info, NULL, pipeline); - ralloc_free(cs.nir); + ralloc_free(cs); return result; } diff --git a/src/amd/vulkan/radv_meta_resolve.c b/src/amd/vulkan/radv_meta_resolve.c index 78d4542..00e47f0 100644 --- a/src/amd/vulkan/radv_meta_resolve.c +++ b/src/amd/vulkan/radv_meta_resolve.c @@ -138,11 +138,8 @@ create_pipeline(struct radv_device *device, VkResult result; VkDevice device_h = radv_device_to_handle(device); - struct radv_shader_module fs_module = { - .nir = build_nir_fs(), - }; - - if (!fs_module.nir) { + nir_shader *fs_module = build_nir_fs(); + if (!fs_module) { /* XXX: Need more accurate error */ result = VK_ERROR_OUT_OF_HOST_MEMORY; goto cleanup; @@ -180,7 +177,7 @@ create_pipeline(struct radv_device *device, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_FRAGMENT_BIT, - .module = radv_shader_module_to_handle(&fs_module), + .module = vk_shader_module_handle_from_nir(fs_module), .pName = "main", }, }, @@ -255,7 +252,7 @@ create_pipeline(struct radv_device *device, goto cleanup; cleanup: - ralloc_free(fs_module.nir); + ralloc_free(fs_module); return result; } @@ -283,8 +280,8 @@ radv_device_init_meta_resolve_state(struct radv_device *device, bool on_demand) VkResult res = VK_SUCCESS; struct radv_meta_state *state = &device->meta_state; - struct radv_shader_module vs_module = { .nir = radv_meta_build_nir_vs_generate_vertices() }; - if (!vs_module.nir) { + nir_shader *vs_module = radv_meta_build_nir_vs_generate_vertices(); + if (!vs_module) { /* XXX: Need more accurate error */ res = VK_ERROR_OUT_OF_HOST_MEMORY; goto fail; @@ -297,7 +294,7 @@ radv_device_init_meta_resolve_state(struct radv_device *device, bool on_demand) if (res != VK_SUCCESS) goto fail; - VkShaderModule vs_module_h = radv_shader_module_to_handle(&vs_module); + VkShaderModule vs_module_h = vk_shader_module_handle_from_nir(vs_module); res = create_pipeline(device, vs_module_h, &state->resolve.pipeline[fs_key], state->resolve.pass[fs_key]); if (res != VK_SUCCESS) @@ -310,7 +307,7 @@ fail: radv_device_finish_meta_resolve_state(device); cleanup: - ralloc_free(vs_module.nir); + ralloc_free(vs_module); return res; } @@ -436,17 +433,17 @@ build_resolve_pipeline(struct radv_device *device, return result; } - struct radv_shader_module vs_module = { .nir = radv_meta_build_nir_vs_generate_vertices() }; + nir_shader *vs_module = radv_meta_build_nir_vs_generate_vertices(); result = create_pass(device, radv_fs_key_format_exemplars[fs_key], &device->meta_state.resolve.pass[fs_key]); if (result != VK_SUCCESS) goto fail; - VkShaderModule vs_module_h = radv_shader_module_to_handle(&vs_module); + VkShaderModule vs_module_h = vk_shader_module_handle_from_nir(vs_module); result = create_pipeline(device, vs_module_h, &device->meta_state.resolve.pipeline[fs_key], device->meta_state.resolve.pass[fs_key]); fail: - ralloc_free(vs_module.nir); + ralloc_free(vs_module); mtx_unlock(&device->meta_state.mtx); return result; } diff --git a/src/amd/vulkan/radv_meta_resolve_cs.c b/src/amd/vulkan/radv_meta_resolve_cs.c index 4a03e6b..599c054 100644 --- a/src/amd/vulkan/radv_meta_resolve_cs.c +++ b/src/amd/vulkan/radv_meta_resolve_cs.c @@ -325,7 +325,7 @@ create_resolve_pipeline(struct radv_device *device, VkPipeline *pipeline) { VkResult result; - struct radv_shader_module cs = { .nir = NULL }; + mtx_lock(&device->meta_state.mtx); if (*pipeline) { @@ -333,14 +333,14 @@ create_resolve_pipeline(struct radv_device *device, return VK_SUCCESS; } - cs.nir = build_resolve_compute_shader(device, is_integer, is_srgb, samples); + nir_shader *cs = build_resolve_compute_shader(device, is_integer, is_srgb, samples); /* compute shader */ VkPipelineShaderStageCreateInfo pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs), + .module = vk_shader_module_handle_from_nir(cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -359,11 +359,11 @@ create_resolve_pipeline(struct radv_device *device, if (result != VK_SUCCESS) goto fail; - ralloc_free(cs.nir); + ralloc_free(cs); mtx_unlock(&device->meta_state.mtx); return VK_SUCCESS; fail: - ralloc_free(cs.nir); + ralloc_free(cs); mtx_unlock(&device->meta_state.mtx); return result; } @@ -376,7 +376,6 @@ create_depth_stencil_resolve_pipeline(struct radv_device *device, VkPipeline *pipeline) { VkResult result; - struct radv_shader_module cs = { .nir = NULL }; mtx_lock(&device->meta_state.mtx); if (*pipeline) { @@ -384,14 +383,14 @@ create_depth_stencil_resolve_pipeline(struct radv_device *device, return VK_SUCCESS; } - cs.nir = build_depth_stencil_resolve_compute_shader(device, samples, + nir_shader *cs = build_depth_stencil_resolve_compute_shader(device, samples, index, resolve_mode); /* compute shader */ VkPipelineShaderStageCreateInfo pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&cs), + .module = vk_shader_module_handle_from_nir(cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -410,11 +409,11 @@ create_depth_stencil_resolve_pipeline(struct radv_device *device, if (result != VK_SUCCESS) goto fail; - ralloc_free(cs.nir); + ralloc_free(cs); mtx_unlock(&device->meta_state.mtx); return VK_SUCCESS; fail: - ralloc_free(cs.nir); + ralloc_free(cs); mtx_unlock(&device->meta_state.mtx); return result; } diff --git a/src/amd/vulkan/radv_meta_resolve_fs.c b/src/amd/vulkan/radv_meta_resolve_fs.c index 104c1b5..eae098e 100644 --- a/src/amd/vulkan/radv_meta_resolve_fs.c +++ b/src/amd/vulkan/radv_meta_resolve_fs.c @@ -161,11 +161,8 @@ create_resolve_pipeline(struct radv_device *device, if (vk_format_is_int(format)) is_integer = true; - struct radv_shader_module fs = { .nir = NULL }; - fs.nir = build_resolve_fragment_shader(device, is_integer, samples); - struct radv_shader_module vs = { - .nir = build_nir_vertex_shader(), - }; + nir_shader *fs = build_resolve_fragment_shader(device, is_integer, samples); + nir_shader *vs = build_nir_vertex_shader(); VkRenderPass *rp = &device->meta_state.resolve_fragment.rc[samples_log2].render_pass[fs_key][0]; @@ -175,13 +172,13 @@ create_resolve_pipeline(struct radv_device *device, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_VERTEX_BIT, - .module = radv_shader_module_to_handle(&vs), + .module = vk_shader_module_handle_from_nir(vs), .pName = "main", .pSpecializationInfo = NULL }, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_FRAGMENT_BIT, - .module = radv_shader_module_to_handle(&fs), + .module = vk_shader_module_handle_from_nir(fs), .pName = "main", .pSpecializationInfo = NULL }, @@ -318,8 +315,8 @@ create_resolve_pipeline(struct radv_device *device, &vk_pipeline_info, &radv_pipeline_info, &device->meta_state.alloc, pipeline); - ralloc_free(vs.nir); - ralloc_free(fs.nir); + ralloc_free(vs); + ralloc_free(fs); mtx_unlock(&device->meta_state.mtx); return result; @@ -496,25 +493,21 @@ create_depth_stencil_resolve_pipeline(struct radv_device *device, return VK_SUCCESS; } - struct radv_shader_module fs = { .nir = NULL }; - struct radv_shader_module vs = { .nir = NULL }; uint32_t samples = 1 << samples_log2; - - vs.nir = build_nir_vertex_shader(); - fs.nir = build_depth_stencil_resolve_fragment_shader(device, samples, - index, resolve_mode); + nir_shader *fs = build_depth_stencil_resolve_fragment_shader(device, samples, index, resolve_mode); + nir_shader *vs = build_nir_vertex_shader(); VkPipelineShaderStageCreateInfo pipeline_shader_stages[] = { { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_VERTEX_BIT, - .module = radv_shader_module_to_handle(&vs), + .module = vk_shader_module_handle_from_nir(vs), .pName = "main", .pSpecializationInfo = NULL }, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_FRAGMENT_BIT, - .module = radv_shader_module_to_handle(&fs), + .module = vk_shader_module_handle_from_nir(fs), .pName = "main", .pSpecializationInfo = NULL }, @@ -682,8 +675,8 @@ create_depth_stencil_resolve_pipeline(struct radv_device *device, &device->meta_state.alloc, pipeline); - ralloc_free(vs.nir); - ralloc_free(fs.nir); + ralloc_free(vs); + ralloc_free(fs); mtx_unlock(&device->meta_state.mtx); return result; diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c index f01c36c..c35816c 100644 --- a/src/amd/vulkan/radv_pipeline.c +++ b/src/amd/vulkan/radv_pipeline.c @@ -3202,8 +3202,8 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline, VkPipelineCreationFeedbackEXT *pipeline_feedback, VkPipelineCreationFeedbackEXT **stage_feedbacks) { - struct radv_shader_module fs_m = {0}; - struct radv_shader_module *modules[MESA_SHADER_STAGES] = { 0, }; + struct vk_shader_module fs_m = {0}; + struct vk_shader_module *modules[MESA_SHADER_STAGES] = { 0, }; nir_shader *nir[MESA_SHADER_STAGES] = {0}; struct radv_shader_binary *binaries[MESA_SHADER_STAGES] = {NULL}; struct radv_shader_variant_key keys[MESA_SHADER_STAGES] = {{{{{0}}}}}; @@ -3219,7 +3219,7 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline, for (unsigned i = 0; i < MESA_SHADER_STAGES; ++i) { if (pStages[i]) { - modules[i] = radv_shader_module_from_handle(pStages[i]->module); + modules[i] = vk_shader_module_from_handle(pStages[i]->module); if (modules[i]->nir) _mesa_sha1_compute(modules[i]->nir->info.name, strlen(modules[i]->nir->info.name), @@ -3259,7 +3259,7 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline, if (!modules[MESA_SHADER_FRAGMENT] && !modules[MESA_SHADER_COMPUTE]) { nir_builder fs_b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL, "noop_fs"); - fs_m.nir = fs_b.shader; + fs_m = vk_shader_module_from_nir(fs_b.shader); modules[MESA_SHADER_FRAGMENT] = &fs_m; } diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c index 7377dec..d25a12f 100644 --- a/src/amd/vulkan/radv_pipeline_cache.c +++ b/src/amd/vulkan/radv_pipeline_cache.c @@ -130,7 +130,7 @@ radv_hash_shaders(unsigned char *hash, for (int i = 0; i < MESA_SHADER_STAGES; ++i) { if (stages[i]) { - RADV_FROM_HANDLE(radv_shader_module, module, stages[i]->module); + RADV_FROM_HANDLE(vk_shader_module, module, stages[i]->module); const VkSpecializationInfo *spec_info = stages[i]->pSpecializationInfo; _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1)); diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index b79787a..25c05c4 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -60,6 +60,7 @@ #include "vk_instance.h" #include "vk_format.h" #include "vk_physical_device.h" +#include "vk_shader_module.h" #include "radv_radeon_winsys.h" #include "ac_binary.h" @@ -1627,8 +1628,6 @@ struct radv_event { uint64_t *map; }; -struct radv_shader_module; - #define RADV_HASH_SHADER_NO_NGG (1 << 0) #define RADV_HASH_SHADER_CS_WAVE32 (1 << 1) #define RADV_HASH_SHADER_PS_WAVE32 (1 << 2) @@ -2781,7 +2780,6 @@ RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool, VkQueryPool) RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_render_pass, VkRenderPass) RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler, VkSampler) RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler_ycbcr_conversion, VkSamplerYcbcrConversion) -RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_shader_module, VkShaderModule) RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_semaphore, VkSemaphore) #endif /* RADV_PRIVATE_H */ diff --git a/src/amd/vulkan/radv_query.c b/src/amd/vulkan/radv_query.c index cef6c90..b4814d2 100644 --- a/src/amd/vulkan/radv_query.c +++ b/src/amd/vulkan/radv_query.c @@ -671,20 +671,20 @@ build_timestamp_query_shader(struct radv_device *device) static VkResult radv_device_init_meta_query_state_internal(struct radv_device *device) { VkResult result; - struct radv_shader_module occlusion_cs = { .nir = NULL }; - struct radv_shader_module pipeline_statistics_cs = { .nir = NULL }; - struct radv_shader_module tfb_cs = { .nir = NULL }; - struct radv_shader_module timestamp_cs = { .nir = NULL }; + nir_shader *occlusion_cs = NULL; + nir_shader *pipeline_statistics_cs = NULL; + nir_shader *tfb_cs = NULL; + nir_shader *timestamp_cs = NULL; mtx_lock(&device->meta_state.mtx); if (device->meta_state.query.pipeline_statistics_query_pipeline) { mtx_unlock(&device->meta_state.mtx); return VK_SUCCESS; } - occlusion_cs.nir = build_occlusion_query_shader(device); - pipeline_statistics_cs.nir = build_pipeline_statistics_query_shader(device); - tfb_cs.nir = build_tfb_query_shader(device); - timestamp_cs.nir = build_timestamp_query_shader(device); + occlusion_cs = build_occlusion_query_shader(device); + pipeline_statistics_cs = build_pipeline_statistics_query_shader(device); + tfb_cs = build_tfb_query_shader(device); + timestamp_cs = build_timestamp_query_shader(device); VkDescriptorSetLayoutCreateInfo occlusion_ds_create_info = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, @@ -733,7 +733,7 @@ static VkResult radv_device_init_meta_query_state_internal(struct radv_device *d VkPipelineShaderStageCreateInfo occlusion_pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&occlusion_cs), + .module = vk_shader_module_handle_from_nir(occlusion_cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -755,7 +755,7 @@ static VkResult radv_device_init_meta_query_state_internal(struct radv_device *d VkPipelineShaderStageCreateInfo pipeline_statistics_pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&pipeline_statistics_cs), + .module = vk_shader_module_handle_from_nir(pipeline_statistics_cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -777,7 +777,7 @@ static VkResult radv_device_init_meta_query_state_internal(struct radv_device *d VkPipelineShaderStageCreateInfo tfb_pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(&tfb_cs), + .module = vk_shader_module_handle_from_nir(tfb_cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -799,7 +799,7 @@ static VkResult radv_device_init_meta_query_state_internal(struct radv_device *d VkPipelineShaderStageCreateInfo timestamp_pipeline_shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = radv_shader_module_to_handle(×tamp_cs), + .module = vk_shader_module_handle_from_nir(timestamp_cs), .pName = "main", .pSpecializationInfo = NULL, }; @@ -819,10 +819,10 @@ static VkResult radv_device_init_meta_query_state_internal(struct radv_device *d fail: if (result != VK_SUCCESS) radv_device_finish_meta_query_state(device); - ralloc_free(occlusion_cs.nir); - ralloc_free(pipeline_statistics_cs.nir); - ralloc_free(tfb_cs.nir); - ralloc_free(timestamp_cs.nir); + ralloc_free(occlusion_cs); + ralloc_free(pipeline_statistics_cs); + ralloc_free(tfb_cs); + ralloc_free(timestamp_cs); mtx_unlock(&device->meta_state.mtx); return result; } diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index 0aab6c5..680532d 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -103,7 +103,7 @@ static const struct nir_shader_compiler_options nir_options = { bool radv_can_dump_shader(struct radv_device *device, - struct radv_shader_module *module, + struct vk_shader_module *module, bool is_gs_copy_shader) { if (!(device->instance->debug_flags & RADV_DEBUG_DUMP_SHADERS)) @@ -117,60 +117,13 @@ radv_can_dump_shader(struct radv_device *device, bool radv_can_dump_shader_stats(struct radv_device *device, - struct radv_shader_module *module) + struct vk_shader_module *module) { /* Only dump non-meta shader stats. */ return device->instance->debug_flags & RADV_DEBUG_DUMP_SHADER_STATS && module && !module->nir; } -VkResult radv_CreateShaderModule( - VkDevice _device, - const VkShaderModuleCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkShaderModule* pShaderModule) -{ - RADV_FROM_HANDLE(radv_device, device, _device); - struct radv_shader_module *module; - - assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO); - assert(pCreateInfo->flags == 0); - - module = vk_alloc2(&device->vk.alloc, pAllocator, - sizeof(*module) + pCreateInfo->codeSize, 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); - if (module == NULL) - return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); - - vk_object_base_init(&device->vk, &module->base, - VK_OBJECT_TYPE_SHADER_MODULE); - - module->nir = NULL; - module->size = pCreateInfo->codeSize; - memcpy(module->data, pCreateInfo->pCode, module->size); - - _mesa_sha1_compute(module->data, module->size, module->sha1); - - *pShaderModule = radv_shader_module_to_handle(module); - - return VK_SUCCESS; -} - -void radv_DestroyShaderModule( - VkDevice _device, - VkShaderModule _module, - const VkAllocationCallbacks* pAllocator) -{ - RADV_FROM_HANDLE(radv_device, device, _device); - RADV_FROM_HANDLE(radv_shader_module, module, _module); - - if (!module) - return; - - vk_object_base_finish(&module->base); - vk_free2(&device->vk.alloc, pAllocator, module); -} - void radv_optimize_nir(const struct radv_device *device, struct nir_shader *shader, bool optimize_conservatively, bool allow_copies) @@ -267,7 +220,7 @@ shared_var_info(const struct glsl_type *type, unsigned *size, unsigned *align) struct radv_shader_debug_data { struct radv_device *device; - const struct radv_shader_module *module; + const struct vk_shader_module *module; }; static void radv_spirv_nir_debug(void *private_data, @@ -375,7 +328,7 @@ lower_intrinsics(nir_shader *nir) nir_shader * radv_shader_compile_to_nir(struct radv_device *device, - struct radv_shader_module *module, + struct vk_shader_module *module, const char *entrypoint_name, gl_shader_stage stage, const VkSpecializationInfo *spec_info, @@ -1338,7 +1291,7 @@ radv_dump_nir_shaders(struct nir_shader * const *shaders, static struct radv_shader_variant * shader_variant_compile(struct radv_device *device, - struct radv_shader_module *module, + struct vk_shader_module *module, struct nir_shader * const *shaders, int shader_count, gl_shader_stage stage, @@ -1443,7 +1396,7 @@ shader_variant_compile(struct radv_device *device, struct radv_shader_variant * radv_shader_variant_compile(struct radv_device *device, - struct radv_shader_module *module, + struct vk_shader_module *module, struct nir_shader *const *shaders, int shader_count, struct radv_pipeline_layout *layout, diff --git a/src/amd/vulkan/radv_shader.h b/src/amd/vulkan/radv_shader.h index a7d022f..7ccb9f6 100644 --- a/src/amd/vulkan/radv_shader.h +++ b/src/amd/vulkan/radv_shader.h @@ -37,6 +37,7 @@ #include "nir/nir.h" #include "vulkan/vulkan.h" #include "vulkan/util/vk_object.h" +#include "vulkan/util/vk_shader_module.h" #include "aco_interface.h" @@ -44,14 +45,6 @@ struct radv_device; -struct radv_shader_module { - struct vk_object_base base; - struct nir_shader *nir; - unsigned char sha1[20]; - uint32_t size; - char data[0]; -}; - struct radv_vs_out_key { uint32_t as_es:1; uint32_t as_ls:1; @@ -433,7 +426,7 @@ radv_nir_lower_ycbcr_textures(nir_shader *shader, nir_shader * radv_shader_compile_to_nir(struct radv_device *device, - struct radv_shader_module *module, + struct vk_shader_module *module, const char *entrypoint_name, gl_shader_stage stage, const VkSpecializationInfo *spec_info, @@ -460,7 +453,7 @@ radv_shader_variant_create(struct radv_device *device, bool keep_shader_info); struct radv_shader_variant * radv_shader_variant_compile(struct radv_device *device, - struct radv_shader_module *module, + struct vk_shader_module *module, struct nir_shader *const *shaders, int shader_count, struct radv_pipeline_layout *layout, @@ -502,12 +495,12 @@ radv_get_shader_name(struct radv_shader_info *info, bool radv_can_dump_shader(struct radv_device *device, - struct radv_shader_module *module, + struct vk_shader_module *module, bool is_gs_copy_shader); bool radv_can_dump_shader_stats(struct radv_device *device, - struct radv_shader_module *module); + struct vk_shader_module *module); VkResult radv_dump_shader_stats(struct radv_device *device, -- 2.7.4