diff --git a/src/gallium/auxiliary/nir/nir_to_tgsi.c b/src/gallium/auxiliary/nir/nir_to_tgsi.c index b7be6667567..0cca381bc59 100644 --- a/src/gallium/auxiliary/nir/nir_to_tgsi.c +++ b/src/gallium/auxiliary/nir/nir_to_tgsi.c @@ -2458,6 +2458,23 @@ ntt_emit_barrier(struct ntt_compile *c, nir_intrinsic_instr *intr) if (modes & nir_var_mem_global) membar |= TGSI_MEMBAR_SHADER_BUFFER; + /* Hack for virglrenderer: the GLSL specific memory barrier functions, + * memoryBarrier{Buffer,Image,Shared,AtomicCounter}(), are only + * available in compute shaders prior to GLSL 4.30. In other stages, + * it needs to use the full memoryBarrier(). It may be possible to + * make them available via #extension directives in older versions, + * but it's confusingly underspecified, and Mesa/virglrenderer don't + * currently agree on how to do it. So, just promote partial memory + * barriers back to full ones outside of compute shaders when asked. + */ + if (membar && !compute && + c->options->non_compute_membar_needs_all_modes) { + membar |= TGSI_MEMBAR_SHADER_BUFFER | + TGSI_MEMBAR_ATOMIC_BUFFER | + TGSI_MEMBAR_SHADER_IMAGE | + TGSI_MEMBAR_SHARED; + } + /* If we only need workgroup scope (not device-scope), we might be able to * optimize a bit. */ diff --git a/src/gallium/auxiliary/nir/nir_to_tgsi.h b/src/gallium/auxiliary/nir/nir_to_tgsi.h index cfdabc57216..48c668555e0 100644 --- a/src/gallium/auxiliary/nir/nir_to_tgsi.h +++ b/src/gallium/auxiliary/nir/nir_to_tgsi.h @@ -37,6 +37,7 @@ struct nir_to_tgsi_options { bool lower_fabs; bool unoptimized_ra; bool lower_ssbo_bindings; + bool non_compute_membar_needs_all_modes; uint32_t ubo_vec4_max; }; diff --git a/src/gallium/drivers/virgl/virgl_context.c b/src/gallium/drivers/virgl/virgl_context.c index 0720561fe96..597d59e209d 100644 --- a/src/gallium/drivers/virgl/virgl_context.c +++ b/src/gallium/drivers/virgl/virgl_context.c @@ -710,7 +710,8 @@ static void *virgl_shader_encoder(struct pipe_context *ctx, .unoptimized_ra = true, .lower_fabs = true, .lower_ssbo_bindings = - rs->caps.caps.v2.host_feature_check_version >= 16 + rs->caps.caps.v2.host_feature_check_version >= 16, + .non_compute_membar_needs_all_modes = true }; if (!(rs->caps.caps.v2.capability_bits_v2 & VIRGL_CAP_V2_TEXTURE_SHADOW_LOD) &&