MSL: Make rw texture fences optional

This commit is contained in:
Evan Tang 2023-08-14 15:07:44 -07:00
parent 4405dd6b28
commit 894113f55b
2 changed files with 7 additions and 1 deletions

View File

@ -8686,7 +8686,7 @@ void CompilerMSL::emit_instruction(const Instruction &instruction)
}
// Metal requires explicit fences to break up RAW hazards, even within the same shader invocation
if (p_var && !has_decoration(p_var->self, DecorationNonWritable))
if (msl_options.readwrite_texture_fences && p_var && !has_decoration(p_var->self, DecorationNonWritable))
statement(to_expression(img_id), ".fence();");
emit_texture_op(instruction, false);

View File

@ -496,6 +496,12 @@ public:
// so it can be enabled only when the bug is present.
bool sample_dref_lod_array_as_grad = false;
// MSL doesn't guarantee coherence between writes and subsequent reads of read_write textures.
// This inserts fences before each read of a read_write texture to ensure coherency.
// If you're sure you never rely on this, you can set this to false for a possible performance improvement.
// Note: Only Apple's GPU compiler takes advantage of the lack of coherency, so make sure to test on Apple GPUs if you disable this.
bool readwrite_texture_fences = true;
bool is_ios() const
{
return platform == iOS;