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: 2b4609b66c ("zink: run nir_convert_from_ssa last during compile")
Fixes: 2d98efd323 ("zink: pre-populate locations in variables")

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10269>
(cherry picked from commit a1c7aff88a)
This commit is contained in:
Mike Blumenkrantz 2021-04-15 10:24:33 -04:00 committed by Eric Engestrom
parent e624fba3b4
commit 5ecd135d03
2 changed files with 3 additions and 14 deletions

View file

@ -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"
},

View file

@ -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);