From 5ecd135d036bd92301975c3abb4b344d60701c4e Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 15 Apr 2021 10:24:33 -0400 Subject: [PATCH] zink: always copy the nir shader before compiling nir_convert_from_ssa and assign_io_locations both modify this unconditionally, the latter of which possibly re-modifies variables in ways that can break the slot map and cause stack overflows during vk driver pipeline compilation Fixes: 2b4609b66cd ("zink: run nir_convert_from_ssa last during compile") Fixes: 2d98efd3232 ("zink: pre-populate locations in variables") Reviewed-by: Erik Faye-Lund Part-of: (cherry picked from commit a1c7aff88a5390947fe4cba732ff03423e0c517d) --- .pick_status.json | 2 +- src/gallium/drivers/zink/zink_compiler.c | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index c5a14ab2171..fc59043e204 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -949,7 +949,7 @@ "description": "zink: always copy the nir shader before compiling", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "master_sha": null, "because_sha": "2b4609b66cd129d77a72ac1cc3502213d1c1640f" }, diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index 3cfb6b4dc32..7b06c19cee7 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -569,12 +569,10 @@ zink_shader_compile(struct zink_screen *screen, struct zink_shader *zs, struct z { VkShaderModule mod = VK_NULL_HANDLE; void *streamout = NULL; - nir_shader *nir = zs->nir; + nir_shader *nir = nir_shader_clone(NULL, zs->nir); if (key) { if (key->inline_uniforms) { - if (nir == zs->nir) - nir = nir_shader_clone(NULL, nir); NIR_PASS_V(nir, nir_inline_uniforms, nir->info.num_inlinable_uniforms, key->base.inlined_uniform_values, @@ -595,19 +593,15 @@ zink_shader_compile(struct zink_screen *screen, struct zink_shader *zs, struct z streamout = &zs->streamout; if (!zink_vs_key(key)->clip_halfz) { - nir = nir_shader_clone(NULL, zs->nir); NIR_PASS_V(nir, nir_lower_clip_halfz); } if (zink_vs_key(key)->push_drawid) { - if (nir == zs->nir) - nir = nir_shader_clone(NULL, zs->nir); NIR_PASS_V(nir, lower_drawid); } } } else if (zs->nir->info.stage == MESA_SHADER_FRAGMENT) { if (!zink_fs_key(key)->samples && nir->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK)) { - nir = nir_shader_clone(NULL, zs->nir); /* VK will always use gl_SampleMask[] values even if sample count is 0, * so we need to skip this write here to mimic GL's behavior of ignoring it */ @@ -620,13 +614,9 @@ zink_shader_compile(struct zink_screen *screen, struct zink_shader *zs, struct z optimize_nir(nir); } if (zink_fs_key(key)->force_dual_color_blend && nir->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_DATA1)) { - if (nir == zs->nir) - nir = nir_shader_clone(NULL, zs->nir); NIR_PASS_V(nir, lower_dual_blend); } if (zink_fs_key(key)->coord_replace_bits) { - if (nir == zs->nir) - nir = nir_shader_clone(NULL, zs->nir); NIR_PASS_V(nir, nir_lower_texcoord_replace, zink_fs_key(key)->coord_replace_bits, false, zink_fs_key(key)->coord_replace_yinvert); } @@ -660,8 +650,7 @@ zink_shader_compile(struct zink_screen *screen, struct zink_shader *zs, struct z mod = VK_NULL_HANDLE; done: - if (nir != zs->nir) - ralloc_free(nir); + ralloc_free(nir); /* TODO: determine if there's any reason to cache spirv output? */ ralloc_free(spirv);