summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-hlsl.cpp
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-06-28 04:07:12 -0400
committerGitHub <noreply@github.com>2024-06-28 04:07:12 -0400
commite49419b0637a357d2e713a0435f0c5ad0c102487 (patch)
tree61f815078f7b3b6187abd28101cea76f611462a2 /source/slang/slang-emit-hlsl.cpp
parentfd32b1879c8a4de7e97a99be7e0e8093ade8b340 (diff)
Implement HLSL resource bindings and default type `float4` to `SubpassInput<T>` (#4462)
* Add case to `emitVectorReshape` for `vector<>` type, `scalar` value 1. Add new case 2. Add test * fix warning * fix warning * Implement HLSL resource bindings and default type `float4` to `SubpassInput<T>` fixes: #4440 1. Removed GLSLInputAttachmentIndexLayout modifier and the somewhat 'hacky' binding model 'Input Attachment' previously relied upon. This was changed to work with the slang-type-layout rules system. This change allows Slang automatic bindings, HLSL bindings, GLSL bindings, and translation of GLSL to and from HLSL bindings to work. 2. Added default argument `float4` to SubpassInput<T>. 3. Merged glsl.meta and hlsl.meta SubpassInput logic. * fix InputAttachment attribute checks fix InputAttachment attribute checks for HLSL and GLSL syntax * remove unused var * validate attribute correctly Attributes do not have type information. We must check the type expression to validate attribute usage. * remove hacky validation type based validation before types are fully resolved is quite hacky and unstable to changes and wrapped types * fix warning * remove redundant `!= nullptr` * remove extra `!= nullptr` * fix some warnings/errors * subpass capability to limit to dxc & remove default values in some functions * revert logic to previous logic revert logic to return if we have a binding regardless of if a VarDecl is given the binding
Diffstat (limited to 'source/slang/slang-emit-hlsl.cpp')
-rw-r--r--source/slang/slang-emit-hlsl.cpp29
1 files changed, 16 insertions, 13 deletions
diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp
index 04f5bd643..4d3830969 100644
--- a/source/slang/slang-emit-hlsl.cpp
+++ b/source/slang/slang-emit-hlsl.cpp
@@ -93,6 +93,13 @@ void HLSLSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitV
break;
case LayoutResourceKind::InputAttachmentIndex:
+ {
+ m_writer->emit("[[vk::input_attachment_index(");
+ m_writer->emit(index);
+ m_writer->emit(")]]");
+ }
+ break;
+
case LayoutResourceKind::RegisterSpace:
case LayoutResourceKind::GenericResource:
case LayoutResourceKind::ExistentialTypeParam:
@@ -141,7 +148,7 @@ void HLSLSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitV
}
}
-void HLSLSourceEmitter::_emitHLSLRegisterSemantics(EmitVarChain* chain, IRInst* inst, char const* uniformSemanticSpelling)
+void HLSLSourceEmitter::_emitHLSLRegisterSemantics(EmitVarChain* chain, IRInst* inst, char const* uniformSemanticSpelling, EmitLayoutSemanticOption layoutSemanticOption)
{
if (!chain) return;
@@ -158,17 +165,20 @@ void HLSLSourceEmitter::_emitHLSLRegisterSemantics(EmitVarChain* chain, IRInst*
for (auto rr : layout->getOffsetAttrs())
{
+ if (layoutSemanticOption == EmitLayoutSemanticOption::kPreType
+ && rr->getResourceKind() != LayoutResourceKind::InputAttachmentIndex)
+ continue;
_emitHLSLRegisterSemantic(rr->getResourceKind(), chain, inst, uniformSemanticSpelling);
}
}
-void HLSLSourceEmitter::_emitHLSLRegisterSemantics(IRVarLayout* varLayout, IRInst* inst, char const* uniformSemanticSpelling)
+void HLSLSourceEmitter::_emitHLSLRegisterSemantics(IRVarLayout* varLayout, IRInst* inst, char const* uniformSemanticSpelling, EmitLayoutSemanticOption layoutSemanticOption)
{
if (!varLayout)
return;
EmitVarChain chain(varLayout);
- _emitHLSLRegisterSemantics(&chain, inst, uniformSemanticSpelling);
+ _emitHLSLRegisterSemantics(&chain, inst, uniformSemanticSpelling, layoutSemanticOption);
}
void HLSLSourceEmitter::_emitHLSLParameterGroupFieldLayoutSemantics(EmitVarChain* chain)
@@ -220,7 +230,7 @@ void HLSLSourceEmitter::_emitHLSLParameterGroup(IRGlobalParam* varDecl, IRUnifor
typeLayout = parameterGroupTypeLayout->getElementVarLayout()->getTypeLayout();
}
- _emitHLSLRegisterSemantic(layoutResourceKind, &containerChain, varDecl);
+ _emitHLSLRegisterSemantic(layoutResourceKind, &containerChain, varDecl, "register");
auto elementType = type->getElementType();
if (shouldForceUnpackConstantBufferElements(type) || hasExplicitConstantBufferOffset(type))
@@ -320,12 +330,12 @@ void HLSLSourceEmitter::_emitHLSLSubpassInputType(IRSubpassInputType* subpassTyp
m_writer->emit(">");
}
-void HLSLSourceEmitter::emitLayoutSemanticsImpl(IRInst* inst, char const* uniformSemanticSpelling)
+void HLSLSourceEmitter::emitLayoutSemanticsImpl(IRInst* inst, char const* uniformSemanticSpelling, EmitLayoutSemanticOption layoutSemanticOption)
{
auto layout = getVarLayout(inst);
if (layout)
{
- _emitHLSLRegisterSemantics(layout, inst, uniformSemanticSpelling);
+ _emitHLSLRegisterSemantics(layout, inst, uniformSemanticSpelling, layoutSemanticOption);
}
}
@@ -1281,13 +1291,6 @@ void HLSLSourceEmitter::emitVarDecorationsImpl(IRInst* varDecl)
{
for(auto decoration : varDecl->getDecorations())
{
- if(auto glslInputAttachmentIndex = as<IRGLSLInputAttachmentIndexDecoration>(decoration))
- {
- m_writer->emit("[[vk::input_attachment_index(");
- m_writer->emit(glslInputAttachmentIndex->getIndex()->getValue());
- m_writer->emit(")]]\n");
- continue;
- }
if (auto collection = as<IRMemoryQualifierSetDecoration>(decoration))
{
auto flags = collection->getMemoryQualifierBit();