From 0842cae0818e1d35a02dc3dcb61929df87a1eccf Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 30 Jan 2023 20:12:02 -0600 Subject: [PATCH] nvk: Pass through a shader key for fragment shaders and MSAA Part-of: --- src/nouveau/vulkan/nvk_compute_pipeline.c | 3 ++- src/nouveau/vulkan/nvk_graphics_pipeline.c | 35 ++++++++++++++++++++++++------ src/nouveau/vulkan/nvk_shader.c | 8 +++++++ src/nouveau/vulkan/nvk_shader.h | 6 +++++ 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/nouveau/vulkan/nvk_compute_pipeline.c b/src/nouveau/vulkan/nvk_compute_pipeline.c index a8a053c..5a1ccd4 100644 --- a/src/nouveau/vulkan/nvk_compute_pipeline.c +++ b/src/nouveau/vulkan/nvk_compute_pipeline.c @@ -103,7 +103,8 @@ nvk_compute_pipeline_create(struct nvk_device *device, nvk_lower_nir(device, nir, &robustness, pipeline_layout); - result = nvk_compile_nir(pdevice, nir, &pipeline->base.shaders[MESA_SHADER_COMPUTE]); + result = nvk_compile_nir(pdevice, nir, NULL, + &pipeline->base.shaders[MESA_SHADER_COMPUTE]); ralloc_free(nir); if (result != VK_SUCCESS) goto fail; diff --git a/src/nouveau/vulkan/nvk_graphics_pipeline.c b/src/nouveau/vulkan/nvk_graphics_pipeline.c index 8843432..8fa9a93 100644 --- a/src/nouveau/vulkan/nvk_graphics_pipeline.c +++ b/src/nouveau/vulkan/nvk_graphics_pipeline.c @@ -48,6 +48,20 @@ emit_pipeline_rs_state(struct nv_push *p, } static void +nvk_populate_fs_key(struct nvk_fs_key *key, + const struct vk_multisample_state *ms) +{ + memset(key, 0, sizeof(*key)); + if (ms == NULL || ms->rasterization_samples <= 1) + return; + + key->msaa = ms->rasterization_samples; + if (ms->sample_shading_enable && + (ms->rasterization_samples * ms->min_sample_shading) > 1.0) + key->force_per_sample = true; +} + +static void emit_pipeline_ms_state(struct nv_push *p, const struct vk_multisample_state *ms) { @@ -172,6 +186,12 @@ nvk_graphics_pipeline_create(struct nvk_device *device, pipeline->base.type = NVK_PIPELINE_GRAPHICS; + struct vk_graphics_pipeline_all_state all; + struct vk_graphics_pipeline_state state = {}; + result = vk_graphics_pipeline_state_fill(&device->vk, &state, pCreateInfo, + NULL, &all, NULL, 0, NULL); + assert(result == VK_SUCCESS); + for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) { const VkPipelineShaderStageCreateInfo *sinfo = &pCreateInfo->pStages[i]; gl_shader_stage stage = vk_to_mesa_shader_stage(sinfo->stage); @@ -194,7 +214,14 @@ nvk_graphics_pipeline_create(struct nvk_device *device, nvk_lower_nir(device, nir, &robustness, pipeline_layout); - result = nvk_compile_nir(pdevice, nir, &pipeline->base.shaders[stage]); + struct nvk_fs_key fs_key_tmp, *fs_key = NULL; + if (stage == MESA_SHADER_FRAGMENT) { + nvk_populate_fs_key(&fs_key_tmp, state.ms); + fs_key = &fs_key_tmp; + } + + result = nvk_compile_nir(pdevice, nir, fs_key, + &pipeline->base.shaders[stage]); ralloc_free(nir); if (result != VK_SUCCESS) goto fail; @@ -293,12 +320,6 @@ nvk_graphics_pipeline_create(struct nvk_device *device, CONTROL_V_SELECTS_LAYER, }); - struct vk_graphics_pipeline_all_state all; - struct vk_graphics_pipeline_state state = {}; - result = vk_graphics_pipeline_state_fill(&device->vk, &state, pCreateInfo, - NULL, &all, NULL, 0, NULL); - assert(result == VK_SUCCESS); - if (state.ts) emit_pipeline_ts_state(&push, state.ts); if (state.vp) emit_pipeline_vp_state(&push, state.vp); if (state.rs) emit_pipeline_rs_state(&push, state.rs); diff --git a/src/nouveau/vulkan/nvk_shader.c b/src/nouveau/vulkan/nvk_shader.c index eeb5d99..df89676 100644 --- a/src/nouveau/vulkan/nvk_shader.c +++ b/src/nouveau/vulkan/nvk_shader.c @@ -640,6 +640,7 @@ nvk_fs_gen_header(struct nvk_shader *fs, struct nv50_ir_prog_info_out *info) VkResult nvk_compile_nir(struct nvk_physical_device *device, nir_shader *nir, + const struct nvk_fs_key *fs_key, struct nvk_shader *shader) { struct nv50_ir_prog_info *info; @@ -672,6 +673,13 @@ nvk_compile_nir(struct nvk_physical_device *device, nir_shader *nir, if (ret) return VK_ERROR_UNKNOWN; + if (info_out.bin.fixupData) { + nv50_ir_apply_fixups(info_out.bin.fixupData, info_out.bin.code, + fs_key && fs_key->force_per_sample, + false /* flatshade */, false /* alphatest */, + fs_key && fs_key->msaa); + } + shader->stage = nir->info.stage; shader->code_ptr = (uint8_t *)info_out.bin.code; shader->code_size = info_out.bin.codeSize; diff --git a/src/nouveau/vulkan/nvk_shader.h b/src/nouveau/vulkan/nvk_shader.h index 31d10a8..d5125f5 100644 --- a/src/nouveau/vulkan/nvk_shader.h +++ b/src/nouveau/vulkan/nvk_shader.h @@ -16,6 +16,11 @@ struct nvk_physical_device; #define TU102_SHADER_HEADER_SIZE (32 * 4) #define NVC0_MAX_SHADER_HEADER_SIZE TU102_SHADER_HEADER_SIZE +struct nvk_fs_key { + bool msaa; + bool force_per_sample; +}; + struct nvk_shader { gl_shader_stage stage; @@ -101,6 +106,7 @@ nvk_lower_nir(struct nvk_device *device, nir_shader *nir, VkResult nvk_compile_nir(struct nvk_physical_device *device, nir_shader *nir, + const struct nvk_fs_key *fs_key, struct nvk_shader *shader); VkResult -- 2.7.4