summaryrefslogtreecommitdiffstats
path: root/source/slang/type-layout.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-11-30 15:03:31 -0800
committerGitHub <noreply@github.com>2018-11-30 15:03:31 -0800
commit7f2d2c9a248a9413e236826a4c6473a6fc104714 (patch)
tree418d63baef8fd736e3e9ba28a3ce948451621687 /source/slang/type-layout.cpp
parente40c106d6f8c4218de5a16450f201c0e395f8167 (diff)
Allow parameter blocks to be explicitly bound to spaces (#736)
* Don't look at VK bindings when compiling for D3D and vice versa The compiler had been looking at all the modifiers on a declaration when piecing together binding information, whether or not those modifiers should apply on the chosen target API. This was working in practice because the "layout resource kinds" used by each API target were disjoint, for the most part. This change ensures that we don't even look at modifiers that don't apply on the chosen target, and furthermore adds a new warning that applies if the user is compiling a shader with explicit `register` bindings for Vulkan, if there are no corresponding `[[vk::binding(...)]]` attributes (under the assumption that if they want to be explicit in one case, they probably want to be explicit in all cases). * Allow explicit space/set bindings on parameter blocks The syntax for the D3D case is to specify a `space` in a `register` modifier, without any other register class: ```hlsl ParameterBlock<X> myBlock : regsiter(space999); ``` In the Vulkan case, the user must apply the `[[vk::binding(...)]]` attribute and is expected to use a `binding` of zero: ```hlsl [[vk::binding(0,999)]] ParameterBlock<X> myBlock; ``` This change includes a reflection test for the new capability (where we also confirm that it produces the expected output when compared with fxc), and a test for the diagnostic messages when the user messes up bindings for Vulkan. The implementation itself is fairly straightforward, since the compiler already treats registe spaces/sets as a resource that parameters can consume directly. Note: the test case for explicit parameter block space/set bindings includes some commented out code that lead to a compiler crash. I would like to fix the underlying issue, but it seemed sensible to keep the bug fix out of a change like this that is adding functionality.
Diffstat (limited to 'source/slang/type-layout.cpp')
-rw-r--r--source/slang/type-layout.cpp32
1 files changed, 17 insertions, 15 deletions
diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp
index 41476a7e5..4e9a05b53 100644
--- a/source/slang/type-layout.cpp
+++ b/source/slang/type-layout.cpp
@@ -823,7 +823,7 @@ static bool isOpenGLTarget(TargetRequest*)
return false;
}
-static bool isD3DTarget(TargetRequest* targetReq)
+bool isD3DTarget(TargetRequest* targetReq)
{
switch( targetReq->target )
{
@@ -839,6 +839,20 @@ static bool isD3DTarget(TargetRequest* targetReq)
}
}
+bool isKhronosTarget(TargetRequest* targetReq)
+{
+ switch( targetReq->target )
+ {
+ default:
+ return false;
+
+ case CodeGenTarget::GLSL:
+ case CodeGenTarget::SPIRV:
+ case CodeGenTarget::SPIRVAssembly:
+ return true;
+ }
+}
+
static bool isD3D11Target(TargetRequest*)
{
// We aren't officially supporting D3D11 right now
@@ -886,21 +900,9 @@ static bool isSM5_1OrLater(TargetRequest* targetReq)
static bool isVulkanTarget(TargetRequest* targetReq)
{
- switch( targetReq->target )
- {
- default:
- return false;
-
- case CodeGenTarget::GLSL:
- case CodeGenTarget::SPIRV:
- case CodeGenTarget::SPIRVAssembly:
- break;
- }
-
- // For right now, any GLSL-related target is assumed
+ // For right now, any Khronos-related target is assumed
// to be a Vulkan target.
-
- return true;
+ return isKhronosTarget(targetReq);
}
static bool shouldAllocateRegisterSpaceForParameterBlock(