From 025c0edc3fd3fb751b36058596a0733ac24b8939 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 22 Feb 2021 15:07:26 -0800 Subject: Add basic support for fragment shader interlock (FSI) (#1722) Both D3D "rasterizer ordered views" (ROVs) and GLSL "fragment shader interlock" (FSI) are aimed at the same basic use case: they allow for fragment shaders to contain operations that require mutual exclusion and/or deterinistics ordering between fragment shader invocations that affect the same framebuffer coordinates. The language-level exposure of the features varies greatly between the two API families, though: * ROVs define an implicit ordering and mutual exclusion constraint: certain resoure parameters are marked as `RasterizerOrdered`, and reads/writes to these resources must be sequences *as if* fragment-shader invocations ran in sequential order for each pixel. * FSI defines paired begin/end functions that mark a critical section of code. All memory operations in the critical section must be sequences *as if* fragment-shader invocations ran in sequential order for each pixel. In order to make this model tractable, only a single critical section is allowed per fragment shader, and the begin/end must appear at the top level of the shader entry point function (not under control flow or after a possible conditional `return`. The simplest way for Slang to support portable programs that run across both API families is to insist that code that cares about these ordering guarantees must use *both* mechanisms, and then each of them will only affect the API that cares about it. Slang already supports ROV resource types, and already lowers them to plain textures for GLSL/SPIR-V. This change adds the missing feature of a begin/end function pair for FSI, which will map to empty functions on non-GLSL targets. --- source/slang/core.meta.slang | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source') diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index d63311985..de78229a9 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -1943,6 +1943,18 @@ __target_intrinsic(cuda, " @ ") __target_intrinsic(cpp, " @ ") int __SyntaxError(); +/// Mark beginning of "interlocked" operations in a fragment shader. +__target_intrinsic(glsl, "beginInvocationInterlockARB") +__glsl_extension(GL_ARB_fragment_shader_interlock) +__glsl_version(420) +void beginInvocationInterlock() {} + +/// Mark end of "interlocked" operations in a fragment shader. +__target_intrinsic(glsl, "endInvocationInterlockARB") +__glsl_extension(GL_ARB_fragment_shader_interlock) +__glsl_version(420) +void endInvocationInterlock() {} + // Operators to apply to `enum` types __generic -- cgit v1.2.3