summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slang.h3
-rw-r--r--source/slang/emit.cpp17
-rw-r--r--source/slang/modifier-defs.h2
-rw-r--r--source/slang/parameter-binding.cpp7
-rw-r--r--source/slang/parser.cpp1
-rw-r--r--source/slang/type-layout.cpp29
-rw-r--r--source/slang/type-layout.h2
-rw-r--r--tests/vkray/closesthit.slang9
-rw-r--r--tests/vkray/closesthit.slang.glsl8
9 files changed, 72 insertions, 6 deletions
diff --git a/slang.h b/slang.h
index 20ecfe3b4..ed0fb32a4 100644
--- a/slang.h
+++ b/slang.h
@@ -1394,6 +1394,7 @@ extern "C"
SLANG_PARAMETER_CATEGORY_RAY_PAYLOAD,
SLANG_PARAMETER_CATEGORY_HIT_ATTRIBUTES,
SLANG_PARAMETER_CATEGORY_CALLABLE_PAYLOAD,
+ SLANG_PARAMETER_CATEGORY_SHADER_RECORD,
//
SLANG_PARAMETER_CATEGORY_COUNT,
@@ -1712,6 +1713,8 @@ namespace slang
HitAttributes = SLANG_PARAMETER_CATEGORY_HIT_ATTRIBUTES,
CallablePayload = SLANG_PARAMETER_CATEGORY_CALLABLE_PAYLOAD,
+ ShaderRecord = SLANG_PARAMETER_CATEGORY_SHADER_RECORD,
+
// DEPRECATED:
VertexInput = SLANG_PARAMETER_CATEGORY_VERTEX_INPUT,
FragmentOutput = SLANG_PARAMETER_CATEGORY_FRAGMENT_OUTPUT,
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index 187ef29bc..fb9968232 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -1753,14 +1753,14 @@ struct EmitVisitor
emitHLSLParameterGroupFieldLayoutSemantics(&chain);
}
- void emitGLSLLayoutQualifier(
+ bool emitGLSLLayoutQualifier(
LayoutResourceKind kind,
EmitVarChain* chain)
{
if(!chain)
- return;
+ return false;
if(!chain->varLayout->FindResourceInfo(kind))
- return;
+ return false;
UInt index = getBindingOffset(chain, kind);
UInt space = getBindingSpace(chain, kind);
@@ -1828,8 +1828,12 @@ struct EmitVisitor
case LayoutResourceKind::PushConstantBuffer:
Emit("layout(push_constant)\n");
break;
+ case LayoutResourceKind::ShaderRecord:
+ Emit("layout(shaderRecordNV)\n");
+ break;
}
+ return true;
}
void emitGLSLLayoutQualifiers(
@@ -5821,8 +5825,13 @@ struct EmitVisitor
emitGLSLLayoutQualifier(LayoutResourceKind::DescriptorTableSlot, &containerChain);
emitGLSLLayoutQualifier(LayoutResourceKind::PushConstantBuffer, &containerChain);
+ bool isShaderRecord = emitGLSLLayoutQualifier(LayoutResourceKind::ShaderRecord, &containerChain);
- if(as<IRGLSLShaderStorageBufferType>(type))
+ if( isShaderRecord )
+ {
+ emit("buffer ");
+ }
+ else if(as<IRGLSLShaderStorageBufferType>(type))
{
emit("layout(std430) buffer ");
}
diff --git a/source/slang/modifier-defs.h b/source/slang/modifier-defs.h
index e8b3f0774..2276f37f8 100644
--- a/source/slang/modifier-defs.h
+++ b/source/slang/modifier-defs.h
@@ -136,6 +136,8 @@ 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)
diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp
index 58891a956..622474116 100644
--- a/source/slang/parameter-binding.cpp
+++ b/source/slang/parameter-binding.cpp
@@ -1184,6 +1184,13 @@ getTypeLayoutForGlobalShaderParameter_HLSL(
auto rules = layoutContext.getRulesFamily();
auto type = varDecl->getType();
+ if( varDecl->HasModifier<ShaderRecordNVLayoutModifier>() && type->As<ConstantBufferType>() )
+ {
+ 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>() && type->As<ConstantBufferType>())
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp
index 9ccd7b962..2e0ca5df9 100644
--- a/source/slang/parser.cpp
+++ b/source/slang/parser.cpp
@@ -4562,6 +4562,7 @@ namespace Slang
CASE(local_size_x, GLSLLocalSizeXLayoutModifier);
CASE(local_size_y, GLSLLocalSizeYLayoutModifier);
CASE(local_size_z, GLSLLocalSizeZLayoutModifier);
+ CASE(shaderRecordNV, ShaderRecordNVLayoutModifier);
#undef CASE
else
diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp
index 4e9a05b53..8fc48fe4f 100644
--- a/source/slang/type-layout.cpp
+++ b/source/slang/type-layout.cpp
@@ -350,6 +350,17 @@ struct GLSLPushConstantBufferObjectLayoutRulesImpl : GLSLObjectLayoutRulesImpl
};
GLSLPushConstantBufferObjectLayoutRulesImpl kGLSLPushConstantBufferObjectLayoutRulesImpl_;
+struct GLSLShaderRecordConstantBufferObjectLayoutRulesImpl : GLSLObjectLayoutRulesImpl
+{
+ virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind /*kind*/) override
+ {
+ // Special-case the layout for a constant-buffer, because we don't
+ // want it to allocate a descriptor-table slot
+ return SimpleLayoutInfo(LayoutResourceKind::ShaderRecord, 1);
+ }
+};
+GLSLShaderRecordConstantBufferObjectLayoutRulesImpl kGLSLShaderRecordConstantBufferObjectLayoutRulesImpl_;
+
struct HLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl
{
virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind kind) override
@@ -439,6 +450,8 @@ struct GLSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl
LayoutRulesImpl* getRayPayloadParameterRules() override;
LayoutRulesImpl* getCallablePayloadParameterRules() override;
LayoutRulesImpl* getHitAttributesParameterRules() override;
+
+ LayoutRulesImpl* getShaderRecordConstantBufferRules() override;
};
struct HLSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl
@@ -455,6 +468,8 @@ struct HLSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl
LayoutRulesImpl* getRayPayloadParameterRules() override;
LayoutRulesImpl* getCallablePayloadParameterRules() override;
LayoutRulesImpl* getHitAttributesParameterRules() override;
+
+ LayoutRulesImpl* getShaderRecordConstantBufferRules() override;
};
GLSLLayoutRulesFamilyImpl kGLSLLayoutRulesFamilyImpl;
@@ -475,6 +490,10 @@ LayoutRulesImpl kGLSLPushConstantLayoutRulesImpl_ = {
&kGLSLLayoutRulesFamilyImpl, &kStd430LayoutRulesImpl, &kGLSLPushConstantBufferObjectLayoutRulesImpl_,
};
+LayoutRulesImpl kGLSLShaderRecordLayoutRulesImpl_ = {
+ &kGLSLLayoutRulesFamilyImpl, &kStd430LayoutRulesImpl, &kGLSLShaderRecordConstantBufferObjectLayoutRulesImpl_,
+};
+
LayoutRulesImpl kGLSLVaryingInputLayoutRulesImpl_ = {
&kGLSLLayoutRulesFamilyImpl, &kGLSLVaryingInputLayoutRulesImpl, &kGLSLObjectLayoutRulesImpl,
};
@@ -547,6 +566,11 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getPushConstantBufferRules()
return &kGLSLPushConstantLayoutRulesImpl_;
}
+LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getShaderRecordConstantBufferRules()
+{
+ return &kGLSLShaderRecordLayoutRulesImpl_;
+}
+
LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getTextureBufferRules()
{
return nullptr;
@@ -606,6 +630,11 @@ LayoutRulesImpl* HLSLLayoutRulesFamilyImpl::getPushConstantBufferRules()
return &kHLSLConstantBufferLayoutRulesImpl_;
}
+LayoutRulesImpl* HLSLLayoutRulesFamilyImpl::getShaderRecordConstantBufferRules()
+{
+ return &kHLSLConstantBufferLayoutRulesImpl_;
+}
+
LayoutRulesImpl* HLSLLayoutRulesFamilyImpl::getTextureBufferRules()
{
return nullptr;
diff --git a/source/slang/type-layout.h b/source/slang/type-layout.h
index 32ee41784..fa874cb80 100644
--- a/source/slang/type-layout.h
+++ b/source/slang/type-layout.h
@@ -738,6 +738,8 @@ struct LayoutRulesFamilyImpl
virtual LayoutRulesImpl* getRayPayloadParameterRules() = 0;
virtual LayoutRulesImpl* getCallablePayloadParameterRules() = 0;
virtual LayoutRulesImpl* getHitAttributesParameterRules()= 0;
+
+ virtual LayoutRulesImpl* getShaderRecordConstantBufferRules() = 0;
};
struct TypeLayoutContext
diff --git a/tests/vkray/closesthit.slang b/tests/vkray/closesthit.slang
index 12f2dcd4a..419c22a46 100644
--- a/tests/vkray/closesthit.slang
+++ b/tests/vkray/closesthit.slang
@@ -8,6 +8,12 @@ struct ReflectionRay
StructuredBuffer<float4> colors;
+layout(shaderRecordNV)
+cbuffer ShaderRecord
+{
+ uint shaderRecordID;
+}
+
void main(
BuiltInTriangleIntersectionAttributes attributes,
in out ReflectionRay ioPayload)
@@ -15,7 +21,8 @@ void main(
uint materialID = InstanceIndex()
+ InstanceID()
+ PrimitiveIndex()
- + HitKind();
+ + HitKind()
+ + shaderRecordID;
float4 color = colors[materialID];
diff --git a/tests/vkray/closesthit.slang.glsl b/tests/vkray/closesthit.slang.glsl
index ef969ee1c..a056b7809 100644
--- a/tests/vkray/closesthit.slang.glsl
+++ b/tests/vkray/closesthit.slang.glsl
@@ -2,6 +2,12 @@
#version 460
#extension GL_NV_ray_tracing : require
+layout(shaderRecordNV)
+buffer ShaderRecord_0
+{
+ uint shaderRecordID_0;
+};
+
layout(std430, binding = 0) buffer _S1
{
vec4 colors_0[];
@@ -34,7 +40,7 @@ void main()
uint _S9 = _S7 + _S8;
uint _S10 = gl_HitKindNV;
- vec4 color_1 = colors_0[_S9 + _S10];
+ vec4 color_1 = colors_0[_S9 + _S10 + shaderRecordID_0];
float _S11 = gl_HitTNV;
float _S12 = gl_RayTminNV;