summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-type-layout.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-04-17 22:14:34 -0700
committerGitHub <noreply@github.com>2024-04-17 22:14:34 -0700
commit5dd27a26da9b6b6191f3b1eba0f38f85714c1ae3 (patch)
tree2a596911523b003746e2cfda2847ffd02d332ef3 /source/slang/slang-type-layout.cpp
parent355a8d8f923ef67f11092ae706b50d028b09f9ad (diff)
Support combined texture sampler when targeting HLSL. (#3963)
* Support combined texture sampler when targeting HLSL. * Fix glsl intrinsics. * Update source/slang/slang-ir-lower-combined-texture-sampler.cpp Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> * Update source/slang/slang-ir-lower-combined-texture-sampler.cpp Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> * Update source/slang/slang-ir-lower-combined-texture-sampler.cpp Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> * Fix., * Enhance test. * Remove unused field. * Fix indentation --------- Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-type-layout.cpp')
-rw-r--r--source/slang/slang-type-layout.cpp63
1 files changed, 47 insertions, 16 deletions
diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp
index e79c51256..a350226c8 100644
--- a/source/slang/slang-type-layout.cpp
+++ b/source/slang/slang-type-layout.cpp
@@ -741,7 +741,7 @@ static LayoutResourceKind _getHLSLLayoutResourceKind(ShaderParameterKind kind)
struct GLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl
{
- virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& options) override
+ virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& options) override
{
int slotCount = 1;
@@ -778,7 +778,7 @@ GLSLObjectLayoutRulesImpl kGLSLObjectLayoutRulesImpl;
struct GLSLPushConstantBufferObjectLayoutRulesImpl : GLSLObjectLayoutRulesImpl
{
- virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind /*kind*/, const Options& /* options */) override
+ virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind /*kind*/, const Options& /* options */) override
{
// Special-case the layout for a constant-buffer, because we don't
// want it to allocate a descriptor-table slot
@@ -789,7 +789,7 @@ GLSLPushConstantBufferObjectLayoutRulesImpl kGLSLPushConstantBufferObjectLayoutR
struct GLSLShaderRecordConstantBufferObjectLayoutRulesImpl : GLSLObjectLayoutRulesImpl
{
- virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind /*kind*/, const Options& /* options */) override
+ virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind /*kind*/, const Options& /* options */) override
{
// Special-case the layout for a constant-buffer, because we don't
// want it to allocate a descriptor-table slot
@@ -800,7 +800,7 @@ GLSLShaderRecordConstantBufferObjectLayoutRulesImpl kGLSLShaderRecordConstantBuf
struct HLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl
{
- virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */) override
+ virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */) override
{
switch( kind )
{
@@ -828,7 +828,19 @@ struct HLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl
return SimpleLayoutInfo(LayoutResourceKind::InputAttachmentIndex, 1);
case ShaderParameterKind::TextureSampler:
+ {
+ ObjectLayoutInfo info;
+ info.layoutInfos.add(SimpleLayoutInfo(LayoutResourceKind::ShaderResource, 1));
+ info.layoutInfos.add(SimpleLayoutInfo(LayoutResourceKind::SamplerState, 1));
+ return info;
+ }
case ShaderParameterKind::MutableTextureSampler:
+ {
+ ObjectLayoutInfo info;
+ info.layoutInfos.add(SimpleLayoutInfo(LayoutResourceKind::UnorderedAccess, 1));
+ info.layoutInfos.add(SimpleLayoutInfo(LayoutResourceKind::SamplerState, 1));
+ return info;
+ }
case ShaderParameterKind::InputRenderTarget:
// TODO: how to handle these?
default:
@@ -981,7 +993,7 @@ CUDALayoutRulesFamilyImpl kCUDALayoutRulesFamilyImpl;
struct CPUObjectLayoutRulesImpl : ObjectLayoutRulesImpl
{
- virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */) override
+ virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */) override
{
switch (kind)
{
@@ -1034,7 +1046,7 @@ struct CUDAObjectLayoutRulesImpl : CPUObjectLayoutRulesImpl
// of opaque handle (as opposed to a pointer) such as CUsurfObject, CUtexObject
typedef unsigned long long ObjectHandle;
- virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options & /* options */) override
+ virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options & /* options */) override
{
switch (kind)
{
@@ -1657,6 +1669,24 @@ static TypeLayoutResult createSimpleTypeLayout(
return TypeLayoutResult(typeLayout, info);
}
+static TypeLayoutResult createSimpleTypeLayout(
+ const ObjectLayoutInfo& info,
+ Type* type,
+ LayoutRulesImpl* rules)
+{
+ RefPtr<TypeLayout> typeLayout = new TypeLayout();
+
+ typeLayout->type = type;
+ typeLayout->rules = rules;
+
+ typeLayout->uniformAlignment = info.layoutInfos[0].alignment;
+
+ for (auto entry : info.layoutInfos)
+ typeLayout->addResourceUsage(entry.kind, entry.size);
+
+ return TypeLayoutResult(typeLayout, info.layoutInfos[0]);
+}
+
static SimpleLayoutInfo _getParameterGroupLayoutInfo(
TypeLayoutContext const& context,
ParameterGroupType* type,
@@ -1664,15 +1694,15 @@ static SimpleLayoutInfo _getParameterGroupLayoutInfo(
{
if( as<ConstantBufferType>(type) )
{
- return rules->GetObjectLayout(ShaderParameterKind::ConstantBuffer, context.objectLayoutOptions);
+ return rules->GetObjectLayout(ShaderParameterKind::ConstantBuffer, context.objectLayoutOptions).getSimple();
}
else if( as<TextureBufferType>(type) )
{
- return rules->GetObjectLayout(ShaderParameterKind::TextureUniformBuffer, context.objectLayoutOptions);
+ return rules->GetObjectLayout(ShaderParameterKind::TextureUniformBuffer, context.objectLayoutOptions).getSimple();
}
else if( as<GLSLShaderStorageBufferType>(type) )
{
- return rules->GetObjectLayout(ShaderParameterKind::ShaderStorageBuffer, context.objectLayoutOptions);
+ return rules->GetObjectLayout(ShaderParameterKind::ShaderStorageBuffer, context.objectLayoutOptions).getSimple();
}
else if (as<ParameterBlockType>(type))
{
@@ -2364,7 +2394,8 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// the overall layout, to account for it.
//
auto cbUsage = parameterGroupRules->GetObjectLayout(ShaderParameterKind::ConstantBuffer, context.objectLayoutOptions);
- containerTypeLayout->addResourceUsage(cbUsage.kind, cbUsage.size);
+ for (auto layoutInfo : cbUsage.layoutInfos)
+ containerTypeLayout->addResourceUsage(layoutInfo.kind, layoutInfo.size);
}
// Similarly to how we only need a constant buffer to be allocated
@@ -2870,7 +2901,7 @@ createStructuredBufferTypeLayout(
RefPtr<TypeLayout> elementTypeLayout)
{
auto rules = context.rules;
- auto info = rules->GetObjectLayout(kind, context.objectLayoutOptions);
+ auto info = rules->GetObjectLayout(kind, context.objectLayoutOptions).getSimple();
auto typeLayout = new StructuredBufferTypeLayout();
@@ -3801,7 +3832,7 @@ static TypeLayoutResult _createTypeLayout(
else if (const auto samplerStateType = as<SamplerStateType>(type))
{
return createSimpleTypeLayout(
- rules->GetObjectLayout(ShaderParameterKind::SamplerState, context.objectLayoutOptions),
+ rules->GetObjectLayout(ShaderParameterKind::SamplerState, context.objectLayoutOptions).getSimple(),
type,
rules);
}
@@ -3825,7 +3856,7 @@ static TypeLayoutResult _createTypeLayout(
}
else
{
- switch( textureType->getAccess() )
+ switch (textureType->getAccess())
{
default:
kind = ShaderParameterKind::MutableTexture;
@@ -3836,9 +3867,9 @@ static TypeLayoutResult _createTypeLayout(
break;
}
}
-
+ auto objLayout = rules->GetObjectLayout(kind, context.objectLayoutOptions);
return createSimpleTypeLayout(
- rules->GetObjectLayout(kind, context.objectLayoutOptions),
+ objLayout,
type,
rules);
}
@@ -3883,7 +3914,7 @@ static TypeLayoutResult _createTypeLayout(
// TODO: need a better way to handle this stuff...
#define CASE(TYPE, KIND) \
else if(auto type_##TYPE = as<TYPE>(type)) do { \
- auto info = rules->GetObjectLayout(ShaderParameterKind::KIND, context.objectLayoutOptions); \
+ auto info = rules->GetObjectLayout(ShaderParameterKind::KIND, context.objectLayoutOptions).getSimple(); \
auto typeLayout = createStructuredBufferTypeLayout( \
context, \
ShaderParameterKind::KIND, \