summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-02-11 09:41:10 -0500
committerGitHub <noreply@github.com>2019-02-11 09:41:10 -0500
commit1c969b9a85e2e6d6981a31bb758647fc61cf6482 (patch)
tree1c5df51b207c43198f360d353108666ab234cc4b /source
parent9f8a92e468a626abf82d08a730e009321595da07 (diff)
[[vk::shader_record]] (#836)
* * Replaced ShaderRecordNVLayoutModifier with ShaderRecordAttribute * Allowed attributed [[vk::shader_record] and [[shader_record]] * Checking there is at most 1 ShaderRecord active * Small typo fixes * Slightly improve diagnostic. Replace expected file.
Diffstat (limited to 'source')
-rw-r--r--source/slang/check.cpp9
-rw-r--r--source/slang/core.meta.slang8
-rw-r--r--source/slang/core.meta.slang.h8
-rw-r--r--source/slang/diagnostic-defs.h2
-rw-r--r--source/slang/modifier-defs.h5
-rw-r--r--source/slang/parameter-binding.cpp30
-rw-r--r--source/slang/parser.cpp58
7 files changed, 76 insertions, 44 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp
index 8dfd7e640..3485afeea 100644
--- a/source/slang/check.cpp
+++ b/source/slang/check.cpp
@@ -2607,6 +2607,11 @@ namespace Slang
// Has no args
SLANG_ASSERT(attr->args.Count() == 0);
}
+ else if (as<ShaderRecordAttribute>(attr))
+ {
+ // Has no args
+ SLANG_ASSERT(attr->args.Count() == 0);
+ }
else if (as<EarlyDepthStencilAttribute>(attr))
{
// Has no args
@@ -3993,7 +3998,7 @@ namespace Slang
decl->SetCheckState(getCheckedState());
}
- void visitGlobalGenericParamDecl(GlobalGenericParamDecl * decl)
+ void visitGlobalGenericParamDecl(GlobalGenericParamDecl* decl)
{
if (decl->IsChecked(getCheckedState())) return;
if (checkingPhase == CheckingPhase::Header)
@@ -4040,7 +4045,7 @@ namespace Slang
checkModifiers(stmt);
}
- void visitFuncDecl(FuncDecl *functionNode)
+ void visitFuncDecl(FuncDecl* functionNode)
{
if (functionNode->IsChecked(getCheckedState()))
return;
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang
index bd01d679a..0c2b70e10 100644
--- a/source/slang/core.meta.slang
+++ b/source/slang/core.meta.slang
@@ -1195,6 +1195,12 @@ attribute_syntax [vk_binding(binding: int, set: int = 0)] : GLSLBindingAttribu
__attributeTarget(DeclBase)
attribute_syntax [gl_binding(binding: int, set: int = 0)] : GLSLBindingAttribute;
+
+__attributeTarget(VarDeclBase)
+attribute_syntax [vk_shader_record] : ShaderRecordAttribute;
+__attributeTarget(VarDeclBase)
+attribute_syntax [shader_record] : ShaderRecordAttribute;
+
__attributeTarget(DeclBase)
attribute_syntax [vk_push_constant] : PushConstantAttribute;
__attributeTarget(DeclBase)
@@ -1294,4 +1300,4 @@ enum _AttributeTargets
Function = $( (int) UserDefinedAttributeTargets::Function),
};
__attributeTarget(StructDecl)
-attribute_syntax [__AttributeUsage(target : _AttributeTargets)] : AttributeUsageAttribute; \ No newline at end of file
+attribute_syntax [__AttributeUsage(target : _AttributeTargets)] : AttributeUsageAttribute;
diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h
index 448fdb058..2c59689a2 100644
--- a/source/slang/core.meta.slang.h
+++ b/source/slang/core.meta.slang.h
@@ -1213,6 +1213,12 @@ SLANG_RAW("\n")
SLANG_RAW("__attributeTarget(DeclBase)\n")
SLANG_RAW("attribute_syntax [gl_binding(binding: int, set: int = 0)]\t\t\t: GLSLBindingAttribute;\n")
SLANG_RAW("\n")
+SLANG_RAW("\n")
+SLANG_RAW("__attributeTarget(VarDeclBase)\n")
+SLANG_RAW("attribute_syntax [vk_shader_record]\t\t\t : ShaderRecordAttribute;\n")
+SLANG_RAW("__attributeTarget(VarDeclBase)\n")
+SLANG_RAW("attribute_syntax [shader_record]\t\t\t : ShaderRecordAttribute;\n")
+SLANG_RAW("\n")
SLANG_RAW("__attributeTarget(DeclBase)\n")
SLANG_RAW("attribute_syntax [vk_push_constant]\t\t\t\t\t\t\t\t\t: PushConstantAttribute;\n")
SLANG_RAW("__attributeTarget(DeclBase)\n")
@@ -1321,4 +1327,4 @@ SLANG_SPLICE( (int) UserDefinedAttributeTargets::Function
SLANG_RAW(",\n")
SLANG_RAW("};\n")
SLANG_RAW("__attributeTarget(StructDecl)\n")
-SLANG_RAW("attribute_syntax [__AttributeUsage(target : _AttributeTargets)] : AttributeUsageAttribute;")
+SLANG_RAW("attribute_syntax [__AttributeUsage(target : _AttributeTargets)] : AttributeUsageAttribute;\n")
diff --git a/source/slang/diagnostic-defs.h b/source/slang/diagnostic-defs.h
index 3e9d9043c..14eb3e90d 100644
--- a/source/slang/diagnostic-defs.h
+++ b/source/slang/diagnostic-defs.h
@@ -387,6 +387,8 @@ DIAGNOSTIC(39014, Error, dontExpectInParametersForStage, "the '$0' stage does no
DIAGNOSTIC(39016, Error, globalUniformsNotSupported, "'$0' is implicitly a global uniform shader parameter, which is currently unsupported by Slang. If a uniform parameter is intended, use a constant buffer or parameter block. If a global is intended, use the 'static' modifier.")
+DIAGNOSTIC(39017, Error, tooManyShaderRecordConstantBuffers, "Can have at most one 'shader record' attributed constant buffer found $0.")
+
//
// 4xxxx - IL code generation.
//
diff --git a/source/slang/modifier-defs.h b/source/slang/modifier-defs.h
index 164621620..76d806fea 100644
--- a/source/slang/modifier-defs.h
+++ b/source/slang/modifier-defs.h
@@ -136,8 +136,6 @@ SIMPLE_SYNTAX_CLASS(GLSLLocalSizeXLayoutModifier, GLSLLocalSizeLayoutModifier
SIMPLE_SYNTAX_CLASS(GLSLLocalSizeYLayoutModifier, GLSLLocalSizeLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLLocalSizeZLayoutModifier, GLSLLocalSizeLayoutModifier)
-SIMPLE_SYNTAX_CLASS(ShaderRecordNVLayoutModifier, GLSLParsedLayoutModifier)
-
// A catch-all for single-keyword modifiers
SIMPLE_SYNTAX_CLASS(SimpleModifier, Modifier)
@@ -342,6 +340,9 @@ SIMPLE_SYNTAX_CLASS(CallAttribute, Attribute) // `[call]`
// [[vk_push_constant]] [[push_constant]]
SIMPLE_SYNTAX_CLASS(PushConstantAttribute, Attribute)
+// [[vk_shader_record]] [[shader_record]]
+SIMPLE_SYNTAX_CLASS(ShaderRecordAttribute, Attribute)
+
// [[vk_binding]]
SYNTAX_CLASS(GLSLBindingAttribute, Attribute)
FIELD(int32_t, binding = 0)
diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp
index ba5a68341..826332b15 100644
--- a/source/slang/parameter-binding.cpp
+++ b/source/slang/parameter-binding.cpp
@@ -1109,13 +1109,14 @@ RefPtr<TypeLayout> getTypeLayoutForGlobalShaderParameter(
auto layoutContext = context->layoutContext;
auto rules = layoutContext.getRulesFamily();
- if( varDecl->HasModifier<ShaderRecordNVLayoutModifier>() && as<ConstantBufferType>(type) )
+ if( varDecl->HasModifier<ShaderRecordAttribute>() && as<ConstantBufferType>(type) )
{
return CreateTypeLayout(
layoutContext.with(rules->getShaderRecordConstantBufferRules()),
type);
}
+
// We want to check for a constant-buffer type with a `push_constant` layout
// qualifier before we move on to anything else.
if (varDecl->HasModifier<PushConstantAttribute>() && as<ConstantBufferType>(type))
@@ -2741,6 +2742,21 @@ void diagnoseGlobalUniform(
getSink(sharedContext)->diagnose(varDecl, Diagnostics::globalUniformsNotSupported, varDecl->getName());
}
+static int _calcTotalNumUsedRegistersForParameterCategory(ParameterBindingContext* bindingContext, SlangParameterCategory paramCategory)
+{
+ int numUsed = 0;
+ for (auto& pair : bindingContext->shared->globalSpaceUsedRangeSets)
+ {
+ UsedRangeSet* rangeSet = pair.Value;
+ const auto& usedRanges = rangeSet->usedResourceRanges[paramCategory];
+ for (const auto& usedRange : usedRanges.ranges)
+ {
+ numUsed += int(usedRange.end - usedRange.begin);
+ }
+ }
+ return numUsed;
+}
+
void generateParameterBindings(
TargetRequest* targetReq)
{
@@ -2890,7 +2906,7 @@ void generateParameterBindings(
// in the global scope we will process the parameters
// of each entry point in order.
//
- // Note: the effect of the current implemetnation is to
+ // Note: the effect of the current implementation is to
// allocate non-overlapping registers/bindings between all
// the entry points in the compile request (e.g., if you
// have a vertex and fragment shader being compiled together,
@@ -2944,6 +2960,16 @@ void generateParameterBindings(
cbInfo->index = globalConstantBufferBinding.index;
}
programLayout->parametersLayout = globalScopeVarLayout;
+
+ {
+ const int numShaderRecordRegs = _calcTotalNumUsedRegistersForParameterCategory(&context, SLANG_PARAMETER_CATEGORY_SHADER_RECORD);
+ if (numShaderRecordRegs > 1)
+ {
+ compileReq->mSink.diagnose(SourceLoc(), Diagnostics::tooManyShaderRecordConstantBuffers, numShaderRecordRegs);
+ return;
+ }
+ }
+
}
RefPtr<ProgramLayout> specializeProgramLayout(
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp
index 3c879302c..38a28745a 100644
--- a/source/slang/parser.cpp
+++ b/source/slang/parser.cpp
@@ -4612,8 +4612,6 @@ namespace Slang
return modifier;
}
-
-
static RefPtr<RefObject> parseLayoutModifier(Parser* parser, void* /*userData*/)
{
ModifierListBuilder listBuilder;
@@ -4653,47 +4651,35 @@ namespace Slang
}
else
{
- if (nameText == "push_constant")
+ RefPtr<Modifier> modifier;
+
+#define CASE(key, type) if (nameText == #key) { modifier = new type; } else
+ CASE(push_constant, PushConstantAttribute)
+ CASE(shaderRecordNV, ShaderRecordAttribute)
+ CASE(constant_id, GLSLConstantIDLayoutModifier)
+ CASE(location, GLSLLocationLayoutModifier)
+ CASE(local_size_x, GLSLLocalSizeXLayoutModifier)
+ CASE(local_size_y, GLSLLocalSizeYLayoutModifier)
+ CASE(local_size_z, GLSLLocalSizeZLayoutModifier)
{
- RefPtr<PushConstantAttribute> modifier(new PushConstantAttribute);
-
- modifier->name = nameAndLoc.name;
- modifier->loc = nameAndLoc.loc;
-
- listBuilder.add(modifier);
+ modifier = new GLSLUnparsedLayoutModifier();
}
- else
- {
- RefPtr<GLSLLayoutModifier> modifier;
+ SLANG_ASSERT(modifier);
+#undef CASE
- // TODO: better handling of this choice (e.g., lookup in scope)
- if(0) {}
- #define CASE(KEYWORD, CLASS) \
- else if(nameText == #KEYWORD) modifier = new CLASS()
+ modifier->name = nameAndLoc.name;
+ modifier->loc = nameAndLoc.loc;
- CASE(constant_id, GLSLConstantIDLayoutModifier);
- CASE(location, GLSLLocationLayoutModifier);
- CASE(local_size_x, GLSLLocalSizeXLayoutModifier);
- CASE(local_size_y, GLSLLocalSizeYLayoutModifier);
- CASE(local_size_z, GLSLLocalSizeZLayoutModifier);
- CASE(shaderRecordNV, ShaderRecordNVLayoutModifier);
-
- #undef CASE
- else
- {
- modifier = new GLSLUnparsedLayoutModifier();
- }
-
- modifier->name = nameAndLoc.name;
- modifier->loc = nameAndLoc.loc;
-
- if(AdvanceIf(parser, TokenType::OpAssign))
+ // Special handling for GLSLLayoutModifier
+ if (auto glslModifier = as<GLSLLayoutModifier>(modifier))
+ {
+ if (AdvanceIf(parser, TokenType::OpAssign))
{
- modifier->valToken = parser->ReadToken(TokenType::IntegerLiteral);
+ glslModifier->valToken = parser->ReadToken(TokenType::IntegerLiteral);
}
-
- listBuilder.add(modifier);
}
+
+ listBuilder.add(modifier);
}
if (AdvanceIf(parser, TokenType::RParent))