nvk: Pass through a shader key for fragment shaders and MSAA

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>
This commit is contained in:
Faith Ekstrand
2023-01-30 20:12:02 -06:00
committed by Marge Bot
parent a02f65809c
commit 0842cae081
4 changed files with 44 additions and 8 deletions
+2 -1
View File
@@ -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;
+28 -7
View File
@@ -47,6 +47,20 @@ emit_pipeline_rs_state(struct nv_push *p,
assert(rs->line.mode == VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT);
}
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);
+8
View File
@@ -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;
+6
View File
@@ -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