diff --git a/src/nouveau/vulkan/nvk_compute_pipeline.c b/src/nouveau/vulkan/nvk_compute_pipeline.c index ff5991d54dd..11d2959032a 100644 --- a/src/nouveau/vulkan/nvk_compute_pipeline.c +++ b/src/nouveau/vulkan/nvk_compute_pipeline.c @@ -5,7 +5,8 @@ #include "nvk_shader.h" #include "nouveau_bo.h" -#include "vk_shader_module.h" +#include "vk_nir.h" +#include "vk_pipeline.h" #include "drf.h" #include "cla0c0qmd.h" @@ -83,17 +84,22 @@ nvk_compute_pipeline_create(struct nvk_device *device, pipeline->base.type = NVK_PIPELINE_COMPUTE; assert(pCreateInfo->stage.stage == VK_SHADER_STAGE_COMPUTE_BIT); - VK_FROM_HANDLE(vk_shader_module, module, pCreateInfo->stage.module); + + const nir_shader_compiler_options *nir_options = + nvk_physical_device_nir_options(pdevice, MESA_SHADER_COMPUTE); + const struct spirv_to_nir_options *spirv_options = + nvk_physical_device_spirv_options(pdevice); nir_shader *nir; - result = nvk_shader_compile_to_nir(device, module, - pCreateInfo->stage.pName, - MESA_SHADER_COMPUTE, - pCreateInfo->stage.pSpecializationInfo, - pipeline_layout, &nir); + result = vk_pipeline_shader_stage_to_nir(&device->vk, + &pCreateInfo->stage, + spirv_options, nir_options, + NULL, &nir); if (result != VK_SUCCESS) goto fail; + nvk_lower_nir(device, nir, pipeline_layout); + result = nvk_compile_nir(pdevice, nir, &pipeline->base.shaders[MESA_SHADER_COMPUTE]); if (result != VK_SUCCESS) goto fail; diff --git a/src/nouveau/vulkan/nvk_shader.c b/src/nouveau/vulkan/nvk_shader.c index d16cefc9a57..f496866eaf3 100644 --- a/src/nouveau/vulkan/nvk_shader.c +++ b/src/nouveau/vulkan/nvk_shader.c @@ -46,6 +46,29 @@ pipe_shader_type_from_mesa(gl_shader_stage stage) } } +const nir_shader_compiler_options * +nvk_physical_device_nir_options(const struct nvk_physical_device *pdevice, + gl_shader_stage stage) +{ + enum pipe_shader_type p_stage = pipe_shader_type_from_mesa(stage); + return nv50_ir_nir_shader_compiler_options(pdevice->dev->chipset, p_stage); +} + +static const struct spirv_to_nir_options spirv_options = { + .caps = { + .image_write_without_format = true, + }, + .ssbo_addr_format = nir_address_format_64bit_global_32bit_offset, + .ubo_addr_format = nir_address_format_64bit_global_32bit_offset, + .shared_addr_format = nir_address_format_32bit_offset, +}; + +const struct spirv_to_nir_options * +nvk_physical_device_spirv_options(const struct nvk_physical_device *pdevice) +{ + return &spirv_options; +} + static bool lower_load_global_constant_offset_instr(nir_builder *b, nir_instr *instr, UNUSED void *_data) @@ -72,38 +95,10 @@ lower_load_global_constant_offset_instr(nir_builder *b, nir_instr *instr, return true; } -VkResult -nvk_shader_compile_to_nir(struct nvk_device *device, - struct vk_shader_module *module, - const char *entrypoint_name, - gl_shader_stage stage, - const VkSpecializationInfo *spec_info, - const struct nvk_pipeline_layout *layout, - nir_shader **nir_out) +void +nvk_lower_nir(struct nvk_device *device, nir_shader *nir, + const struct nvk_pipeline_layout *layout) { - struct nvk_physical_device *pdevice = nvk_device_physical(device); - const nir_shader_compiler_options *nir_options = - nv50_ir_nir_shader_compiler_options(pdevice->dev->chipset, - pipe_shader_type_from_mesa(stage)); - - const struct spirv_to_nir_options spirv_options = { - .caps = - { - .image_write_without_format = true, - }, - .ssbo_addr_format = nir_address_format_64bit_global_32bit_offset, - .ubo_addr_format = nir_address_format_64bit_global_32bit_offset, - .shared_addr_format = nir_address_format_32bit_offset, - }; - - nir_shader *nir; - VkResult result = vk_shader_module_to_nir(&device->vk, module, stage, - entrypoint_name, spec_info, - &spirv_options, nir_options, - NULL, &nir); - if (result != VK_SUCCESS) - return result; - NIR_PASS(_, nir, nir_lower_global_vars_to_local); NIR_PASS(_, nir, nir_split_struct_vars, nir_var_function_temp); @@ -140,10 +135,6 @@ nvk_shader_compile_to_nir(struct nvk_device *device, NIR_PASS(_, nir, nir_copy_prop); NIR_PASS(_, nir, nir_opt_dce); - - *nir_out = nir; - - return VK_SUCCESS; } VkResult diff --git a/src/nouveau/vulkan/nvk_shader.h b/src/nouveau/vulkan/nvk_shader.h index 3ef4426d2e1..0d17bd2e076 100644 --- a/src/nouveau/vulkan/nvk_shader.h +++ b/src/nouveau/vulkan/nvk_shader.h @@ -31,14 +31,16 @@ struct nvk_shader { struct nouveau_ws_bo *bo; }; -VkResult -nvk_shader_compile_to_nir(struct nvk_device *device, - struct vk_shader_module *module, - const char *entrypoint_name, - gl_shader_stage stage, - const VkSpecializationInfo *spec_info, - const struct nvk_pipeline_layout *layout, - nir_shader **nir_out); +const nir_shader_compiler_options * +nvk_physical_device_nir_options(const struct nvk_physical_device *pdevice, + gl_shader_stage stage); + +const struct spirv_to_nir_options * +nvk_physical_device_spirv_options(const struct nvk_physical_device *pdevice); + +void +nvk_lower_nir(struct nvk_device *device, nir_shader *nir, + const struct nvk_pipeline_layout *layout); VkResult nvk_compile_nir(struct nvk_physical_device *device, nir_shader *nir,