spirv: Add a workaround for OpControlBarrier on old GLSLang

As per the Vulkan memory model, the proper translation of GLSL barrier()
is an OpControlBarrier with a scope of Workgroup and semantics of
Acquire, Release, and WorkgroupMemory.  Older versions of GLSLang gave
an OpControlBarrier with semantics of None so we need to patch it up on
those versions.

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3307>
This commit is contained in:
Jason Ekstrand
2020-01-07 11:35:54 -06:00
committed by Marge Bot
parent 60097cc840
commit 2365520c9d
2 changed files with 24 additions and 1 deletions

View File

@@ -3675,11 +3675,24 @@ vtn_handle_barrier(struct vtn_builder *b, SpvOp opcode,
}
case SpvOpControlBarrier: {
SpvScope execution_scope = vtn_constant_uint(b, w[1]);
SpvScope memory_scope = vtn_constant_uint(b, w[2]);
SpvMemorySemanticsMask memory_semantics = vtn_constant_uint(b, w[3]);
/* GLSLang, prior to commit 8297936dd6eb3, emitted OpControlBarrier with
* memory semantics of None for GLSL barrier().
*/
if (b->wa_glslang_cs_barrier &&
b->nb.shader->info.stage == MESA_SHADER_COMPUTE &&
execution_scope == SpvScopeWorkgroup &&
memory_semantics == SpvMemorySemanticsMaskNone) {
memory_scope = SpvScopeWorkgroup;
memory_semantics = SpvMemorySemanticsAcquireReleaseMask |
SpvMemorySemanticsWorkgroupMemoryMask;
}
vtn_emit_memory_barrier(b, memory_scope, memory_semantics);
SpvScope execution_scope = vtn_constant_uint(b, w[1]);
if (execution_scope == SpvScopeWorkgroup)
vtn_emit_barrier(b, nir_intrinsic_barrier);
break;
@@ -5103,6 +5116,13 @@ vtn_create_builder(const uint32_t *words, size_t word_count,
*/
b->wa_glslang_179 = (generator_id == 8 && generator_version == 1);
/* In GLSLang commit 8297936dd6eb3, their handling of barrier() was fixed
* to provide correct memory semantics on compute shader barrier()
* commands. Prior to that, we need to fix them up ourselves. This
* GLSLang fix caused them to bump to generator version 3.
*/
b->wa_glslang_cs_barrier = (generator_id == 8 && generator_version < 3);
/* words[2] == generator magic */
unsigned value_id_bound = words[3];
if (words[4] != 0) {

View File

@@ -626,6 +626,9 @@ struct vtn_builder {
/* True if we should watch out for GLSLang issue #179 */
bool wa_glslang_179;
/* True if we need to fix up CS OpControlBarrier */
bool wa_glslang_cs_barrier;
gl_shader_stage entry_point_stage;
const char *entry_point_name;
struct vtn_value *entry_point;