summaryrefslogtreecommitdiff
path: root/source/slang/slang-type-layout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-type-layout.cpp')
-rw-r--r--source/slang/slang-type-layout.cpp1927
1 files changed, 1012 insertions, 915 deletions
diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp
index 2fe16188c..2b8117afa 100644
--- a/source/slang/slang-type-layout.cpp
+++ b/source/slang/slang-type-layout.cpp
@@ -1,15 +1,15 @@
// slang-type-layout.cpp
#include "slang-type-layout.h"
-#include "slang-syntax.h"
-#include "slang-ir-insts.h"
-#include "slang-check-impl.h"
-
#include "../compiler-core/slang-artifact-desc-util.h"
+#include "slang-check-impl.h"
+#include "slang-ir-insts.h"
+#include "slang-syntax.h"
#include <assert.h>
-namespace Slang {
+namespace Slang
+{
static bool _isPow2(size_t v)
{
@@ -28,13 +28,13 @@ static size_t _roundToAlignment(size_t offset, size_t alignment)
static LayoutSize _roundToAlignment(LayoutSize offset, size_t alignment)
{
// An infinite size is assumed to be maximally aligned.
- if(offset.isInfinite())
+ if (offset.isInfinite())
return LayoutSize::infinite();
return _roundToAlignment(offset.getFiniteValue(), alignment);
}
-static size_t _roundUpToPowerOfTwo( size_t value )
+static size_t _roundUpToPowerOfTwo(size_t value)
{
// TODO(tfoley): I know this isn't a fast approach
size_t result = 1;
@@ -49,7 +49,8 @@ static bool _isAligned(size_t size, size_t alignment)
return ((alignment - 1) & size) == 0;
}
-// This is a workaround to keep functions from causing warnings in release builds, and therefore causing compilation to fail.
+// This is a workaround to keep functions from causing warnings in release builds, and therefore
+// causing compilation to fail.
void _typeLayout_keepFunctions()
{
auto a = _isAligned;
@@ -67,7 +68,7 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl
{
switch (baseType)
{
- case BaseType::Void: return SimpleLayoutInfo();
+ case BaseType::Void: return SimpleLayoutInfo();
// Note: By convention, a `bool` in a constant buffer is stored as an `int.
// This default may eventually change, at which point this logic will need
@@ -76,28 +77,36 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl
// TODO: We should probably warn in this case, since storing a `bool` in
// a constant buffer seems like a Bad Idea anyway.
//
- case BaseType::Bool: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 4, 4 );
-
-
- case BaseType::Int8: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 1,1);
- case BaseType::Int16: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 2,2);
- case BaseType::Int: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 4,4);
- case BaseType::Int64: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 8,8);
- case BaseType::IntPtr: return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(intptr_t), sizeof(intptr_t));
-
- case BaseType::UInt8: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 1,1);
- case BaseType::UInt16: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 2,2);
- case BaseType::UInt: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 4,4);
- case BaseType::UInt64: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 8,8);
- case BaseType::UIntPtr: return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(intptr_t), sizeof(intptr_t));
-
- case BaseType::Half: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 2,2);
- case BaseType::Float: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 4,4);
- case BaseType::Double: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 8,8);
+ case BaseType::Bool: return SimpleLayoutInfo(LayoutResourceKind::Uniform, 4, 4);
+
+
+ case BaseType::Int8: return SimpleLayoutInfo(LayoutResourceKind::Uniform, 1, 1);
+ case BaseType::Int16: return SimpleLayoutInfo(LayoutResourceKind::Uniform, 2, 2);
+ case BaseType::Int: return SimpleLayoutInfo(LayoutResourceKind::Uniform, 4, 4);
+ case BaseType::Int64: return SimpleLayoutInfo(LayoutResourceKind::Uniform, 8, 8);
+ case BaseType::IntPtr:
+ return SimpleLayoutInfo(
+ LayoutResourceKind::Uniform,
+ sizeof(intptr_t),
+ sizeof(intptr_t));
+
+ case BaseType::UInt8: return SimpleLayoutInfo(LayoutResourceKind::Uniform, 1, 1);
+ case BaseType::UInt16: return SimpleLayoutInfo(LayoutResourceKind::Uniform, 2, 2);
+ case BaseType::UInt: return SimpleLayoutInfo(LayoutResourceKind::Uniform, 4, 4);
+ case BaseType::UInt64: return SimpleLayoutInfo(LayoutResourceKind::Uniform, 8, 8);
+ case BaseType::UIntPtr:
+ return SimpleLayoutInfo(
+ LayoutResourceKind::Uniform,
+ sizeof(intptr_t),
+ sizeof(intptr_t));
+
+ case BaseType::Half: return SimpleLayoutInfo(LayoutResourceKind::Uniform, 2, 2);
+ case BaseType::Float: return SimpleLayoutInfo(LayoutResourceKind::Uniform, 4, 4);
+ case BaseType::Double: return SimpleLayoutInfo(LayoutResourceKind::Uniform, 8, 8);
default:
SLANG_UNEXPECTED("uhandled scalar type");
- UNREACHABLE_RETURN(SimpleLayoutInfo( LayoutResourceKind::Uniform, 0, 1 ));
+ UNREACHABLE_RETURN(SimpleLayoutInfo(LayoutResourceKind::Uniform, 0, 1));
}
}
@@ -107,7 +116,8 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl
return SimpleLayoutInfo(LayoutResourceKind::Uniform, 8, 8);
}
- SimpleArrayLayoutInfo GetArrayLayout( SimpleLayoutInfo elementInfo, LayoutSize elementCount) override
+ SimpleArrayLayoutInfo GetArrayLayout(SimpleLayoutInfo elementInfo, LayoutSize elementCount)
+ override
{
SLANG_RELEASE_ASSERT(elementInfo.size.isFinite());
auto elementSize = elementInfo.size.getFiniteValue();
@@ -123,7 +133,7 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl
// the constraints that there must be `elementStride` bytes
// between consecutive elements.
//
- if( elementCount > 0 )
+ if (elementCount > 0)
{
// We can think of this as either allocating (N-1)
// chunks of size `elementStride` (for most of the elements)
@@ -132,7 +142,7 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl
// N chunks of size `elementStride` and then "giving back"
// the final `elementStride - elementSize` bytes.
//
- arraySize = (elementStride * (elementCount-1)) + elementSize;
+ arraySize = (elementStride * (elementCount - 1)) + elementSize;
}
SimpleArrayLayoutInfo arrayInfo;
@@ -143,7 +153,10 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl
return arrayInfo;
}
- SimpleLayoutInfo GetVectorLayout(BaseType elementType, SimpleLayoutInfo elementInfo, size_t elementCount) override
+ SimpleLayoutInfo GetVectorLayout(
+ BaseType elementType,
+ SimpleLayoutInfo elementInfo,
+ size_t elementCount) override
{
SLANG_UNUSED(elementType);
SimpleLayoutInfo vectorInfo;
@@ -153,7 +166,11 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl
return vectorInfo;
}
- SimpleArrayLayoutInfo GetMatrixLayout(BaseType elementType, SimpleLayoutInfo elementInfo, size_t rowCount, size_t columnCount) override
+ SimpleArrayLayoutInfo GetMatrixLayout(
+ BaseType elementType,
+ SimpleLayoutInfo elementInfo,
+ size_t rowCount,
+ size_t columnCount) override
{
// The default behavior here is to lay out a matrix
// as an array of row vectors (that is row-major).
@@ -162,9 +179,7 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl
// potentially transpose the row/column counts in order
// to get layouts with a different convention.
//
- return GetArrayLayout(
- GetVectorLayout(elementType, elementInfo, columnCount),
- rowCount);
+ return GetArrayLayout(GetVectorLayout(elementType, elementInfo, columnCount), rowCount);
}
UniformLayoutInfo BeginStructLayout() override
@@ -176,7 +191,7 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl
LayoutSize AddStructField(UniformLayoutInfo* ioStructInfo, UniformLayoutInfo fieldInfo) override
{
// Skip zero-size fields
- if(fieldInfo.size == 0)
+ if (fieldInfo.size == 0)
return ioStructInfo->size;
// A struct type must be at least as aligned as its most-aligned field.
@@ -230,18 +245,18 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl
// that require it.
}
- bool DoStructuredBuffersNeedSeparateCounterBuffer() override
- {
- return true;
- }
+ bool DoStructuredBuffersNeedSeparateCounterBuffer() override { return true; }
};
- /// Common behavior for GLSL-family layout.
+/// Common behavior for GLSL-family layout.
struct GLSLBaseLayoutRulesImpl : DefaultLayoutRulesImpl
{
typedef DefaultLayoutRulesImpl Super;
- SimpleLayoutInfo GetVectorLayout(BaseType elementType, SimpleLayoutInfo elementInfo, size_t elementCount) override
+ SimpleLayoutInfo GetVectorLayout(
+ BaseType elementType,
+ SimpleLayoutInfo elementInfo,
+ size_t elementCount) override
{
SLANG_UNUSED(elementType);
// The `std140` and `std430` rules require vectors to be aligned to the next power of
@@ -255,23 +270,21 @@ struct GLSLBaseLayoutRulesImpl : DefaultLayoutRulesImpl
SLANG_RELEASE_ASSERT(elementInfo.size.isFinite());
auto size = elementInfo.size.getFiniteValue() * elementCount;
- SimpleLayoutInfo vectorInfo(
- LayoutResourceKind::Uniform,
- size,
- _roundUpToPowerOfTwo(size));
+ SimpleLayoutInfo vectorInfo(LayoutResourceKind::Uniform, size, _roundUpToPowerOfTwo(size));
return vectorInfo;
}
SimpleLayoutInfo GetPointerLayout() override
{
- // TODO(JS):
- // We'll assume 64 bit "pointer". If we are using these extensions...
+ // TODO(JS):
+ // We'll assume 64 bit "pointer". If we are using these extensions...
// https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_buffer_reference.txt
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_buffer_device_address.html.
return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(int64_t), sizeof(int64_t));
}
- SimpleArrayLayoutInfo GetArrayLayout(SimpleLayoutInfo elementInfo, LayoutSize elementCount) override
+ SimpleArrayLayoutInfo GetArrayLayout(SimpleLayoutInfo elementInfo, LayoutSize elementCount)
+ override
{
// The size of an array must be rounded up to be a multiple of its alignment.
//
@@ -288,24 +301,25 @@ struct GLSLBaseLayoutRulesImpl : DefaultLayoutRulesImpl
}
};
- /// The GLSL `std430` layout rules.
+/// The GLSL `std430` layout rules.
struct Std430LayoutRulesImpl : GLSLBaseLayoutRulesImpl
{
// These rules don't actually need any differences from our
// base/common GLSL layout rules.
};
- /// The GLSL `std430` layout rules.
+/// The GLSL `std430` layout rules.
struct Std140LayoutRulesImpl : GLSLBaseLayoutRulesImpl
{
typedef GLSLBaseLayoutRulesImpl Super;
- SimpleArrayLayoutInfo GetArrayLayout(SimpleLayoutInfo elementInfo, LayoutSize elementCount) override
+ SimpleArrayLayoutInfo GetArrayLayout(SimpleLayoutInfo elementInfo, LayoutSize elementCount)
+ override
{
// The `std140` rules require that array elements
// be aligned on 16-byte boundaries.
//
- if(elementInfo.kind == LayoutResourceKind::Uniform)
+ if (elementInfo.kind == LayoutResourceKind::Uniform)
{
if (elementInfo.alignment < 16)
elementInfo.alignment = 16;
@@ -341,9 +355,10 @@ struct HLSLConstantBufferLayoutRulesImpl : DefaultLayoutRulesImpl
// the space after the last array element and the overall structure
// will have a size of 32 bytes.
- SimpleArrayLayoutInfo GetArrayLayout(SimpleLayoutInfo elementInfo, LayoutSize elementCount) override
+ SimpleArrayLayoutInfo GetArrayLayout(SimpleLayoutInfo elementInfo, LayoutSize elementCount)
+ override
{
- if(elementInfo.kind == LayoutResourceKind::Uniform)
+ if (elementInfo.kind == LayoutResourceKind::Uniform)
{
if (elementInfo.alignment < 16)
elementInfo.alignment = 16;
@@ -357,10 +372,7 @@ struct HLSLConstantBufferLayoutRulesImpl : DefaultLayoutRulesImpl
return SimpleLayoutInfo();
}
- UniformLayoutInfo BeginStructLayout() override
- {
- return UniformLayoutInfo(0, 16);
- }
+ UniformLayoutInfo BeginStructLayout() override { return UniformLayoutInfo(0, 16); }
// HLSL layout rules do *not* impose additional alignment
// constraints on vectors (e.g., all of `float`, `float2`,
@@ -376,7 +388,7 @@ struct HLSLConstantBufferLayoutRulesImpl : DefaultLayoutRulesImpl
LayoutSize AddStructField(UniformLayoutInfo* ioStructInfo, UniformLayoutInfo fieldInfo) override
{
// Skip zero-size fields
- if(fieldInfo.size == 0)
+ if (fieldInfo.size == 0)
return ioStructInfo->size;
ioStructInfo->alignment = std::max(ioStructInfo->alignment, fieldInfo.alignment);
@@ -407,7 +419,7 @@ struct FXCShaderResourceLayoutRulesImpl : DefaultLayoutRulesImpl
};
/* CPU layout requires that all sizes are a multiple of alignment.
-*/
+ */
struct CPULayoutRulesImpl : DefaultLayoutRulesImpl
{
typedef DefaultLayoutRulesImpl Super;
@@ -416,30 +428,31 @@ struct CPULayoutRulesImpl : DefaultLayoutRulesImpl
{
switch (baseType)
{
- case BaseType::Bool:
+ case BaseType::Bool:
{
- // TODO(JS): Much like ptr this is a problem - in knowing how to return this value. In the past it's been a word
- // on some compilers for example.
- // On checking though current compilers (clang, g++, visual studio) it is a single byte
- return SimpleLayoutInfo( LayoutResourceKind::Uniform, 1, 1 );
+ // TODO(JS): Much like ptr this is a problem - in knowing how to return this value.
+ // In the past it's been a word on some compilers for example. On checking though
+ // current compilers (clang, g++, visual studio) it is a single byte
+ return SimpleLayoutInfo(LayoutResourceKind::Uniform, 1, 1);
}
- // This always returns a layout where the size is the same as the alignment.
- default: return Super::GetScalarLayout(baseType);
+ // This always returns a layout where the size is the same as the alignment.
+ default: return Super::GetScalarLayout(baseType);
}
}
SimpleLayoutInfo GetPointerLayout() override
{
// TODO(JS):
- // NOTE! We are assuming that the layout is the same for the *target* that it is for
+ // NOTE! We are assuming that the layout is the same for the *target* that it is for
// the compilation.
- // If we are emitting C++, then there is no way in general to know how that C++ will be compiled
- // it could be 32 or 64 (or other) sizes. For now we just assume they are the same.
+ // If we are emitting C++, then there is no way in general to know how that C++ will be
+ // compiled it could be 32 or 64 (or other) sizes. For now we just assume they are the same.
return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*));
}
- SimpleArrayLayoutInfo GetArrayLayout( SimpleLayoutInfo elementInfo, LayoutSize elementCount) override
+ SimpleArrayLayoutInfo GetArrayLayout(SimpleLayoutInfo elementInfo, LayoutSize elementCount)
+ override
{
if (elementCount.isInfinite())
{
@@ -458,10 +471,7 @@ struct CPULayoutRulesImpl : DefaultLayoutRulesImpl
}
}
- UniformLayoutInfo BeginStructLayout() override
- {
- return Super::BeginStructLayout();
- }
+ UniformLayoutInfo BeginStructLayout() override { return Super::BeginStructLayout(); }
void EndStructLayout(UniformLayoutInfo* ioStructInfo) override
{
@@ -473,11 +483,11 @@ struct CPULayoutRulesImpl : DefaultLayoutRulesImpl
// The CUDA compiler NVRTC only works on 64 bit operating systems.
// So instead of using native host type sizes we use these types instead
//
-// NOTE! This implies that our CUDA reflection (even if produced on 32 bit host environment) is always 64 bit.
-// This is unlikely to be a problem in practice.
+// NOTE! This implies that our CUDA reflection (even if produced on 32 bit host environment) is
+// always 64 bit. This is unlikely to be a problem in practice.
-// NOTE! For the moment the CUDA prelude we use size_t - but that's ok as we currently use these types for
-// sizes
+// NOTE! For the moment the CUDA prelude we use size_t - but that's ok as we currently use these
+// types for sizes
// Memory sizes, and memory offsets (signed)
typedef int64_t CUDASize;
@@ -491,7 +501,8 @@ typedef CUDASize CUDAPtr;
// For CUtexObject and CUsurfObject
typedef CUDAPtr CUDAHandle;
-// This is not strictly speaking needed - but exists to be consistent with cuda-prelude.h and the current CUDA emit.
+// This is not strictly speaking needed - but exists to be consistent with cuda-prelude.h and the
+// current CUDA emit.
typedef CUDAPtr CUDASamplerState;
// TODO(JS): Perhaps there is an argument these should be 32 bit?
@@ -506,13 +517,17 @@ struct CUDALayoutRulesImpl : DefaultLayoutRulesImpl
{
switch (baseType)
{
- case BaseType::Bool:
+ case BaseType::Bool:
{
- // In memory a bool is a byte. BUT when in a vector or matrix it will actually be a int32_t
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(uint8_t), SLANG_ALIGN_OF(uint8_t));
+ // In memory a bool is a byte. BUT when in a vector or matrix it will actually be a
+ // int32_t
+ return SimpleLayoutInfo(
+ LayoutResourceKind::Uniform,
+ sizeof(uint8_t),
+ SLANG_ALIGN_OF(uint8_t));
}
- default: return Super::GetScalarLayout(baseType);
+ default: return Super::GetScalarLayout(baseType);
}
}
@@ -522,10 +537,11 @@ struct CUDALayoutRulesImpl : DefaultLayoutRulesImpl
return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(int64_t), sizeof(int64_t));
}
- SimpleArrayLayoutInfo GetArrayLayout(SimpleLayoutInfo elementInfo, LayoutSize elementCount) override
+ SimpleArrayLayoutInfo GetArrayLayout(SimpleLayoutInfo elementInfo, LayoutSize elementCount)
+ override
{
SLANG_RELEASE_ASSERT(elementInfo.size.isFinite());
-
+
if (elementCount.isInfinite())
{
// This is an unsized array, get information for element
@@ -536,15 +552,19 @@ struct CUDALayoutRulesImpl : DefaultLayoutRulesImpl
info.alignment = sizeof(CUDAPtr);
return info;
}
-
- // It's fine to use the Default impl, as long as any elements size is alignment rounded (as happen in EndStructLayout).
- // If that weren't the case the array may be smaller than elementSize * elementCount which would be wrong for CUDA.
+
+ // It's fine to use the Default impl, as long as any elements size is alignment rounded (as
+ // happen in EndStructLayout). If that weren't the case the array may be smaller than
+ // elementSize * elementCount which would be wrong for CUDA.
SLANG_ASSERT(_isAligned(elementInfo.size.getFiniteValue(), elementInfo.alignment));
return Super::GetArrayLayout(elementInfo, elementCount);
}
- SimpleLayoutInfo GetVectorLayout(BaseType elementType, SimpleLayoutInfo elementInfo, size_t elementCount) override
+ SimpleLayoutInfo GetVectorLayout(
+ BaseType elementType,
+ SimpleLayoutInfo elementInfo,
+ size_t elementCount) override
{
// Special case bool
if (elementType == BaseType::Bool)
@@ -554,7 +574,7 @@ struct CUDALayoutRulesImpl : DefaultLayoutRulesImpl
fixInfo.alignment = sizeof(int32_t);
return GetVectorLayout(BaseType::Int, fixInfo, elementCount);
}
-
+
const auto elementSize = elementInfo.size.getFiniteValue();
// These rules can largely be determines by looking at
@@ -575,7 +595,8 @@ struct CUDALayoutRulesImpl : DefaultLayoutRulesImpl
// Nothing is aligned more than 16
alignment = std::min(alignment, size_t(16));
- // For CUDA the size must be a multiple of alignment, as this is the amount of bytes used 'exclusively' by the type.
+ // For CUDA the size must be a multiple of alignment, as this is the amount of bytes used
+ // 'exclusively' by the type.
// The size must be a multiple of the alignment
SLANG_ASSERT(_isAligned(size, alignment));
@@ -584,20 +605,22 @@ struct CUDALayoutRulesImpl : DefaultLayoutRulesImpl
vectorInfo.kind = elementInfo.kind;
vectorInfo.size = size;
vectorInfo.alignment = alignment;
-
+
return vectorInfo;
}
- SimpleArrayLayoutInfo GetMatrixLayout(BaseType elementType, SimpleLayoutInfo elementInfo, size_t rowCount, size_t columnCount) override
+ SimpleArrayLayoutInfo GetMatrixLayout(
+ BaseType elementType,
+ SimpleLayoutInfo elementInfo,
+ size_t rowCount,
+ size_t columnCount) override
{
- // The default behavior is to calculate the size as an array of rowCount vectors, which is correct here
+ // The default behavior is to calculate the size as an array of rowCount vectors, which is
+ // correct here
return Super::GetMatrixLayout(elementType, elementInfo, rowCount, columnCount);
}
- UniformLayoutInfo BeginStructLayout() override
- {
- return Super::BeginStructLayout();
- }
+ UniformLayoutInfo BeginStructLayout() override { return Super::BeginStructLayout(); }
void EndStructLayout(UniformLayoutInfo* ioStructInfo) override
{
@@ -608,7 +631,10 @@ struct CUDALayoutRulesImpl : DefaultLayoutRulesImpl
struct MetalLayoutRulesImpl : public CPULayoutRulesImpl
{
- SimpleLayoutInfo GetVectorLayout(BaseType elementType, SimpleLayoutInfo elementInfo, size_t elementCount) override
+ SimpleLayoutInfo GetVectorLayout(
+ BaseType elementType,
+ SimpleLayoutInfo elementInfo,
+ size_t elementCount) override
{
SLANG_UNUSED(elementType);
@@ -623,7 +649,7 @@ struct MetalLayoutRulesImpl : public CPULayoutRulesImpl
vectorInfo.kind = elementInfo.kind;
vectorInfo.size = size;
vectorInfo.alignment = alignment;
-
+
return vectorInfo;
}
};
@@ -638,10 +664,7 @@ struct HLSLStructuredBufferLayoutRulesImpl : DefaultLayoutRulesImpl
// DirectX does however allow transparently managing the counter buffer
// resource for StructuredBuffers.
- bool DoStructuredBuffersNeedSeparateCounterBuffer() override
- {
- return false;
- }
+ bool DoStructuredBuffersNeedSeparateCounterBuffer() override { return false; }
};
struct DefaultVaryingLayoutRulesImpl : DefaultLayoutRulesImpl
@@ -650,28 +673,22 @@ struct DefaultVaryingLayoutRulesImpl : DefaultLayoutRulesImpl
DefaultVaryingLayoutRulesImpl(LayoutResourceKind kind)
: kind(kind)
- {}
+ {
+ }
// hook to allow differentiating for input/output
- virtual LayoutResourceKind getKind()
- {
- return kind;
- }
+ virtual LayoutResourceKind getKind() { return kind; }
SimpleLayoutInfo GetScalarLayout(BaseType) override
{
// Assume that all scalars take up one "slot"
- return SimpleLayoutInfo(
- getKind(),
- 1);
+ return SimpleLayoutInfo(getKind(), 1);
}
SimpleLayoutInfo GetPointerLayout() override
{
// For pointers assume same logic as for scalars
- return SimpleLayoutInfo(
- getKind(),
- 1);
+ return SimpleLayoutInfo(getKind(), 1);
}
SimpleLayoutInfo GetVectorLayout(BaseType elementType, SimpleLayoutInfo, size_t) override
@@ -681,9 +698,7 @@ struct DefaultVaryingLayoutRulesImpl : DefaultLayoutRulesImpl
//
// TODO: some platforms may decide that vectors of `double` need
// special handling
- return SimpleLayoutInfo(
- getKind(),
- 1);
+ return SimpleLayoutInfo(getKind(), 1);
}
};
@@ -691,98 +706,90 @@ struct GLSLVaryingLayoutRulesImpl : DefaultVaryingLayoutRulesImpl
{
GLSLVaryingLayoutRulesImpl(LayoutResourceKind kind)
: DefaultVaryingLayoutRulesImpl(kind)
- {}
+ {
+ }
};
struct HLSLVaryingLayoutRulesImpl : DefaultVaryingLayoutRulesImpl
{
HLSLVaryingLayoutRulesImpl(LayoutResourceKind kind)
: DefaultVaryingLayoutRulesImpl(kind)
- {}
+ {
+ }
};
struct MetalVaryingLayoutRulesImpl : DefaultVaryingLayoutRulesImpl
{
MetalVaryingLayoutRulesImpl(LayoutResourceKind kind)
: DefaultVaryingLayoutRulesImpl(kind)
- {}
+ {
+ }
};
//
struct GLSLSpecializationConstantLayoutRulesImpl : DefaultLayoutRulesImpl
{
- LayoutResourceKind getKind()
- {
- return LayoutResourceKind::SpecializationConstant;
- }
+ LayoutResourceKind getKind() { return LayoutResourceKind::SpecializationConstant; }
SimpleLayoutInfo GetScalarLayout(BaseType) override
{
// Assume that all scalars take up one "slot"
- return SimpleLayoutInfo(
- getKind(),
- 1);
+ return SimpleLayoutInfo(getKind(), 1);
}
SimpleLayoutInfo GetPointerLayout() override
{
// In a sense pointer are just like ScalarLayout, so we'll use the same logic...
- return SimpleLayoutInfo(
- getKind(),
- 1);
+ return SimpleLayoutInfo(getKind(), 1);
}
- SimpleLayoutInfo GetVectorLayout(BaseType elementType, SimpleLayoutInfo, size_t elementCount) override
+ SimpleLayoutInfo GetVectorLayout(BaseType elementType, SimpleLayoutInfo, size_t elementCount)
+ override
{
SLANG_UNUSED(elementType);
// GLSL doesn't support vectors of specialization constants,
// but we will assume that, if supported, they would use one slot per element.
- return SimpleLayoutInfo(
- getKind(),
- elementCount);
+ return SimpleLayoutInfo(getKind(), elementCount);
}
};
GLSLSpecializationConstantLayoutRulesImpl kGLSLSpecializationConstantLayoutRulesImpl;
-// Given a ShaderParamKind returns the equivalent LayoutResourceKind/ParameterCategory/SlangParameterCategory
+// Given a ShaderParamKind returns the equivalent
+// LayoutResourceKind/ParameterCategory/SlangParameterCategory
static LayoutResourceKind _getHLSLLayoutResourceKind(ShaderParameterKind kind)
{
switch (kind)
{
- case ShaderParameterKind::SubpassInput:
- return LayoutResourceKind::InputAttachmentIndex;
+ case ShaderParameterKind::SubpassInput: return LayoutResourceKind::InputAttachmentIndex;
- case ShaderParameterKind::ConstantBuffer:
- return LayoutResourceKind::ConstantBuffer;
+ case ShaderParameterKind::ConstantBuffer: return LayoutResourceKind::ConstantBuffer;
- case ShaderParameterKind::TextureUniformBuffer:
- case ShaderParameterKind::StructuredBuffer:
- case ShaderParameterKind::RawBuffer:
- case ShaderParameterKind::Buffer:
- case ShaderParameterKind::Texture:
- return LayoutResourceKind::ShaderResource;
+ case ShaderParameterKind::TextureUniformBuffer:
+ case ShaderParameterKind::StructuredBuffer:
+ case ShaderParameterKind::RawBuffer:
+ case ShaderParameterKind::Buffer:
+ case ShaderParameterKind::Texture: return LayoutResourceKind::ShaderResource;
- case ShaderParameterKind::MutableStructuredBuffer:
- case ShaderParameterKind::MutableRawBuffer:
- case ShaderParameterKind::MutableBuffer:
- case ShaderParameterKind::MutableTexture:
- case ShaderParameterKind::AppendConsumeStructuredBuffer:
- return LayoutResourceKind::UnorderedAccess;
+ case ShaderParameterKind::MutableStructuredBuffer:
+ case ShaderParameterKind::MutableRawBuffer:
+ case ShaderParameterKind::MutableBuffer:
+ case ShaderParameterKind::MutableTexture:
+ case ShaderParameterKind::AppendConsumeStructuredBuffer:
+ return LayoutResourceKind::UnorderedAccess;
- case ShaderParameterKind::SamplerState:
- return LayoutResourceKind::SamplerState;
- default:
- return LayoutResourceKind::None;
+ case ShaderParameterKind::SamplerState: return LayoutResourceKind::SamplerState;
+ default: return LayoutResourceKind::None;
}
}
struct GLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl
{
- virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& options) override
+ virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& options)
+ override
{
int slotCount = 1;
-
+
// In Vulkan GLSL, pretty much every object is just a descriptor-table slot.
// Except for AppendConsumeStructuredBuffer, which takes two slots.
// This, however, is added in 'createStructuredBufferWithCounterTypeLayout'
@@ -800,7 +807,8 @@ struct GLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl
if (hlslToVulkanKind != HLSLToVulkanLayoutOptions::Kind::Invalid)
{
// Is this kind enabled for shift?
- if (options.hlslToVulkanKindFlags & HLSLToVulkanLayoutOptions::getKindFlag(hlslToVulkanKind))
+ if (options.hlslToVulkanKindFlags &
+ HLSLToVulkanLayoutOptions::getKindFlag(hlslToVulkanKind))
{
// We are going to consume a HLSL layout kind
// Later we will do shifting as necessary
@@ -813,8 +821,7 @@ struct GLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl
{
case ShaderParameterKind::SubpassInput:
return SimpleLayoutInfo(LayoutResourceKind::InputAttachmentIndex, slotCount);
- default:
- break;
+ default: break;
}
return SimpleLayoutInfo(LayoutResourceKind::DescriptorTableSlot, slotCount);
}
@@ -823,7 +830,10 @@ GLSLObjectLayoutRulesImpl kGLSLObjectLayoutRulesImpl;
struct GLSLPushConstantBufferObjectLayoutRulesImpl : GLSLObjectLayoutRulesImpl
{
- virtual ObjectLayoutInfo 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
@@ -834,20 +844,25 @@ GLSLPushConstantBufferObjectLayoutRulesImpl kGLSLPushConstantBufferObjectLayoutR
struct GLSLShaderRecordConstantBufferObjectLayoutRulesImpl : GLSLObjectLayoutRulesImpl
{
- virtual ObjectLayoutInfo 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
return SimpleLayoutInfo(LayoutResourceKind::ShaderRecord, 1);
}
};
-GLSLShaderRecordConstantBufferObjectLayoutRulesImpl kGLSLShaderRecordConstantBufferObjectLayoutRulesImpl_;
+GLSLShaderRecordConstantBufferObjectLayoutRulesImpl
+ kGLSLShaderRecordConstantBufferObjectLayoutRulesImpl_;
struct HLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl
{
- virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */) override
+ virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */)
+ override
{
- switch( kind )
+ switch (kind)
{
case ShaderParameterKind::ConstantBuffer:
return SimpleLayoutInfo(LayoutResourceKind::ConstantBuffer, 1);
@@ -898,7 +913,8 @@ HLSLObjectLayoutRulesImpl kHLSLObjectLayoutRulesImpl;
struct WGSLObjectLayoutRulesImpl : GLSLObjectLayoutRulesImpl
{
- virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& options) override
+ virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& options)
+ override
{
ObjectLayoutInfo info = GLSLObjectLayoutRulesImpl::GetObjectLayout(kind, options);
@@ -923,19 +939,22 @@ struct GLSLRayTracingLayoutRulesImpl : DefaultVaryingLayoutRulesImpl
{
GLSLRayTracingLayoutRulesImpl(LayoutResourceKind kind)
: DefaultVaryingLayoutRulesImpl(kind)
- {}
+ {
+ }
};
struct HLSLRayTracingLayoutRulesImpl : DefaultVaryingLayoutRulesImpl
{
HLSLRayTracingLayoutRulesImpl(LayoutResourceKind kind)
: DefaultVaryingLayoutRulesImpl(kind)
- {}
+ {
+ }
};
struct CUDARayTracingLayoutRulesImpl : DefaultVaryingLayoutRulesImpl
{
CUDARayTracingLayoutRulesImpl(LayoutResourceKind kind)
: DefaultVaryingLayoutRulesImpl(kind)
- {}
+ {
+ }
};
DefaultLayoutRulesImpl kDefaultLayoutRulesImpl;
@@ -948,24 +967,33 @@ HLSLStructuredBufferLayoutRulesImpl kHLSLStructuredBufferLayoutRulesImpl;
GLSLVaryingLayoutRulesImpl kGLSLVaryingInputLayoutRulesImpl(LayoutResourceKind::VertexInput);
GLSLVaryingLayoutRulesImpl kGLSLVaryingOutputLayoutRulesImpl(LayoutResourceKind::FragmentOutput);
-GLSLRayTracingLayoutRulesImpl kGLSLRayPayloadParameterLayoutRulesImpl(LayoutResourceKind::RayPayload);
-GLSLRayTracingLayoutRulesImpl kGLSLCallablePayloadParameterLayoutRulesImpl(LayoutResourceKind::CallablePayload);
-GLSLRayTracingLayoutRulesImpl kGLSLHitAttributesParameterLayoutRulesImpl(LayoutResourceKind::HitAttributes);
+GLSLRayTracingLayoutRulesImpl kGLSLRayPayloadParameterLayoutRulesImpl(
+ LayoutResourceKind::RayPayload);
+GLSLRayTracingLayoutRulesImpl kGLSLCallablePayloadParameterLayoutRulesImpl(
+ LayoutResourceKind::CallablePayload);
+GLSLRayTracingLayoutRulesImpl kGLSLHitAttributesParameterLayoutRulesImpl(
+ LayoutResourceKind::HitAttributes);
HLSLVaryingLayoutRulesImpl kHLSLVaryingInputLayoutRulesImpl(LayoutResourceKind::VertexInput);
HLSLVaryingLayoutRulesImpl kHLSLVaryingOutputLayoutRulesImpl(LayoutResourceKind::FragmentOutput);
-HLSLRayTracingLayoutRulesImpl kHLSLRayPayloadParameterLayoutRulesImpl(LayoutResourceKind::RayPayload);
-HLSLRayTracingLayoutRulesImpl kHLSLCallablePayloadParameterLayoutRulesImpl(LayoutResourceKind::CallablePayload);
-HLSLRayTracingLayoutRulesImpl kHLSLHitAttributesParameterLayoutRulesImpl(LayoutResourceKind::HitAttributes);
+HLSLRayTracingLayoutRulesImpl kHLSLRayPayloadParameterLayoutRulesImpl(
+ LayoutResourceKind::RayPayload);
+HLSLRayTracingLayoutRulesImpl kHLSLCallablePayloadParameterLayoutRulesImpl(
+ LayoutResourceKind::CallablePayload);
+HLSLRayTracingLayoutRulesImpl kHLSLHitAttributesParameterLayoutRulesImpl(
+ LayoutResourceKind::HitAttributes);
// Just copying what was done above for now, but for CUDA...
-//CUDAVaryingLayoutRulesImpl kCUDAVaryingInputLayoutRulesImpl(LayoutResourceKind::VertexInput);
-//CUDAVaryingLayoutRulesImpl kCUDAVaryingOutputLayoutRulesImpl(LayoutResourceKind::FragmentOutput);
+// CUDAVaryingLayoutRulesImpl kCUDAVaryingInputLayoutRulesImpl(LayoutResourceKind::VertexInput);
+// CUDAVaryingLayoutRulesImpl kCUDAVaryingOutputLayoutRulesImpl(LayoutResourceKind::FragmentOutput);
//
-CUDARayTracingLayoutRulesImpl kCUDARayPayloadParameterLayoutRulesImpl(LayoutResourceKind::RayPayload);
-//CUDARayTracingLayoutRulesImpl kCUDACallablePayloadParameterLayoutRulesImpl(LayoutResourceKind::CallablePayload);
-CUDARayTracingLayoutRulesImpl kCUDAHitAttributesParameterLayoutRulesImpl(LayoutResourceKind::HitAttributes);
+CUDARayTracingLayoutRulesImpl kCUDARayPayloadParameterLayoutRulesImpl(
+ LayoutResourceKind::RayPayload);
+// CUDARayTracingLayoutRulesImpl
+// kCUDACallablePayloadParameterLayoutRulesImpl(LayoutResourceKind::CallablePayload);
+CUDARayTracingLayoutRulesImpl kCUDAHitAttributesParameterLayoutRulesImpl(
+ LayoutResourceKind::HitAttributes);
MetalVaryingLayoutRulesImpl kMetalVaryingInputLayoutRulesImpl(LayoutResourceKind::VertexInput);
MetalVaryingLayoutRulesImpl kMetalVaryingOutputLayoutRulesImpl(LayoutResourceKind::FragmentOutput);
@@ -979,12 +1007,13 @@ struct GLSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl
virtual LayoutRulesImpl* getVaryingInputRules() override;
virtual LayoutRulesImpl* getVaryingOutputRules() override;
virtual LayoutRulesImpl* getSpecializationConstantRules() override;
- virtual LayoutRulesImpl* getShaderStorageBufferRules(CompilerOptionSet& compilerOptions) override;
+ virtual LayoutRulesImpl* getShaderStorageBufferRules(
+ CompilerOptionSet& compilerOptions) override;
virtual LayoutRulesImpl* getParameterBlockRules(CompilerOptionSet& compilerOptions) override;
- LayoutRulesImpl* getRayPayloadParameterRules() override;
+ LayoutRulesImpl* getRayPayloadParameterRules() override;
LayoutRulesImpl* getCallablePayloadParameterRules() override;
- LayoutRulesImpl* getHitAttributesParameterRules() override;
+ LayoutRulesImpl* getHitAttributesParameterRules() override;
LayoutRulesImpl* getShaderRecordConstantBufferRules() override;
@@ -1000,15 +1029,16 @@ struct HLSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl
virtual LayoutRulesImpl* getVaryingInputRules() override;
virtual LayoutRulesImpl* getVaryingOutputRules() override;
virtual LayoutRulesImpl* getSpecializationConstantRules() override;
- virtual LayoutRulesImpl* getShaderStorageBufferRules(CompilerOptionSet& compilerOptions) override;
+ virtual LayoutRulesImpl* getShaderStorageBufferRules(
+ CompilerOptionSet& compilerOptions) override;
virtual LayoutRulesImpl* getParameterBlockRules(CompilerOptionSet& compilerOptions) override;
- LayoutRulesImpl* getRayPayloadParameterRules() override;
+ LayoutRulesImpl* getRayPayloadParameterRules() override;
LayoutRulesImpl* getCallablePayloadParameterRules() override;
- LayoutRulesImpl* getHitAttributesParameterRules() override;
+ LayoutRulesImpl* getHitAttributesParameterRules() override;
LayoutRulesImpl* getShaderRecordConstantBufferRules() override;
-
+
LayoutRulesImpl* getStructuredBufferRules(CompilerOptionSet& compilerOptions) override;
};
@@ -1021,12 +1051,13 @@ struct CPULayoutRulesFamilyImpl : LayoutRulesFamilyImpl
virtual LayoutRulesImpl* getVaryingInputRules() override;
virtual LayoutRulesImpl* getVaryingOutputRules() override;
virtual LayoutRulesImpl* getSpecializationConstantRules() override;
- virtual LayoutRulesImpl* getShaderStorageBufferRules(CompilerOptionSet& compilerOptions) override;
+ virtual LayoutRulesImpl* getShaderStorageBufferRules(
+ CompilerOptionSet& compilerOptions) override;
virtual LayoutRulesImpl* getParameterBlockRules(CompilerOptionSet& compilerOptions) override;
- LayoutRulesImpl* getRayPayloadParameterRules() override;
+ LayoutRulesImpl* getRayPayloadParameterRules() override;
LayoutRulesImpl* getCallablePayloadParameterRules() override;
- LayoutRulesImpl* getHitAttributesParameterRules() override;
+ LayoutRulesImpl* getHitAttributesParameterRules() override;
LayoutRulesImpl* getShaderRecordConstantBufferRules() override;
LayoutRulesImpl* getStructuredBufferRules(CompilerOptionSet& compilerOptions) override;
@@ -1041,12 +1072,13 @@ struct CUDALayoutRulesFamilyImpl : LayoutRulesFamilyImpl
virtual LayoutRulesImpl* getVaryingInputRules() override;
virtual LayoutRulesImpl* getVaryingOutputRules() override;
virtual LayoutRulesImpl* getSpecializationConstantRules() override;
- virtual LayoutRulesImpl* getShaderStorageBufferRules(CompilerOptionSet& compilerOptions) override;
+ virtual LayoutRulesImpl* getShaderStorageBufferRules(
+ CompilerOptionSet& compilerOptions) override;
virtual LayoutRulesImpl* getParameterBlockRules(CompilerOptionSet& compilerOptions) override;
- LayoutRulesImpl* getRayPayloadParameterRules() override;
+ LayoutRulesImpl* getRayPayloadParameterRules() override;
LayoutRulesImpl* getCallablePayloadParameterRules() override;
- LayoutRulesImpl* getHitAttributesParameterRules() override;
+ LayoutRulesImpl* getHitAttributesParameterRules() override;
LayoutRulesImpl* getShaderRecordConstantBufferRules() override;
LayoutRulesImpl* getStructuredBufferRules(CompilerOptionSet& compilerOptions) override;
@@ -1061,12 +1093,13 @@ struct MetalLayoutRulesFamilyImpl : LayoutRulesFamilyImpl
virtual LayoutRulesImpl* getVaryingInputRules() override;
virtual LayoutRulesImpl* getVaryingOutputRules() override;
virtual LayoutRulesImpl* getSpecializationConstantRules() override;
- virtual LayoutRulesImpl* getShaderStorageBufferRules(CompilerOptionSet& compilerOptions) override;
+ virtual LayoutRulesImpl* getShaderStorageBufferRules(
+ CompilerOptionSet& compilerOptions) override;
virtual LayoutRulesImpl* getParameterBlockRules(CompilerOptionSet& compilerOptions) override;
- LayoutRulesImpl* getRayPayloadParameterRules() override;
+ LayoutRulesImpl* getRayPayloadParameterRules() override;
LayoutRulesImpl* getCallablePayloadParameterRules() override;
- LayoutRulesImpl* getHitAttributesParameterRules() override;
+ LayoutRulesImpl* getHitAttributesParameterRules() override;
LayoutRulesImpl* getShaderRecordConstantBufferRules() override;
LayoutRulesImpl* getStructuredBufferRules(CompilerOptionSet& compilerOptions) override;
@@ -1081,12 +1114,13 @@ struct WGSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl
virtual LayoutRulesImpl* getVaryingInputRules() override;
virtual LayoutRulesImpl* getVaryingOutputRules() override;
virtual LayoutRulesImpl* getSpecializationConstantRules() override;
- virtual LayoutRulesImpl* getShaderStorageBufferRules(CompilerOptionSet& compilerOptions) override;
+ virtual LayoutRulesImpl* getShaderStorageBufferRules(
+ CompilerOptionSet& compilerOptions) override;
virtual LayoutRulesImpl* getParameterBlockRules(CompilerOptionSet& compilerOptions) override;
- LayoutRulesImpl* getRayPayloadParameterRules() override;
+ LayoutRulesImpl* getRayPayloadParameterRules() override;
LayoutRulesImpl* getCallablePayloadParameterRules() override;
- LayoutRulesImpl* getHitAttributesParameterRules() override;
+ LayoutRulesImpl* getHitAttributesParameterRules() override;
LayoutRulesImpl* getShaderRecordConstantBufferRules() override;
LayoutRulesImpl* getStructuredBufferRules(CompilerOptionSet& compilerOptions) override;
@@ -1103,50 +1137,72 @@ WGSLLayoutRulesFamilyImpl kWGSLLayoutRulesFamilyImpl;
struct CPUObjectLayoutRulesImpl : ObjectLayoutRulesImpl
{
- virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */) override
+ virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */)
+ override
{
switch (kind)
{
- case ShaderParameterKind::ConstantBuffer:
- // It's a pointer to the actual uniform data
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*));
-
- case ShaderParameterKind::MutableTexture:
- case ShaderParameterKind::TextureUniformBuffer:
- case ShaderParameterKind::Texture:
- // It's a pointer to a texture interface
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*));
-
- case ShaderParameterKind::StructuredBuffer:
- case ShaderParameterKind::MutableStructuredBuffer:
- case ShaderParameterKind::AppendConsumeStructuredBuffer:
- // It's a ptr and a size of the amount of elements
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*) * 2, SLANG_ALIGN_OF(void*));
-
- case ShaderParameterKind::RawBuffer:
- case ShaderParameterKind::Buffer:
- case ShaderParameterKind::MutableRawBuffer:
- case ShaderParameterKind::MutableBuffer:
- // It's a pointer and a size in bytes
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*) * 2, SLANG_ALIGN_OF(void*));
-
- case ShaderParameterKind::SamplerState:
- // It's a pointer
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*));
-
- case ShaderParameterKind::TextureSampler:
- case ShaderParameterKind::MutableTextureSampler:
+ case ShaderParameterKind::ConstantBuffer:
+ // It's a pointer to the actual uniform data
+ return SimpleLayoutInfo(
+ LayoutResourceKind::Uniform,
+ sizeof(void*),
+ SLANG_ALIGN_OF(void*));
+
+ case ShaderParameterKind::MutableTexture:
+ case ShaderParameterKind::TextureUniformBuffer:
+ case ShaderParameterKind::Texture:
+ // It's a pointer to a texture interface
+ return SimpleLayoutInfo(
+ LayoutResourceKind::Uniform,
+ sizeof(void*),
+ SLANG_ALIGN_OF(void*));
+
+ case ShaderParameterKind::StructuredBuffer:
+ case ShaderParameterKind::MutableStructuredBuffer:
+ case ShaderParameterKind::AppendConsumeStructuredBuffer:
+ // It's a ptr and a size of the amount of elements
+ return SimpleLayoutInfo(
+ LayoutResourceKind::Uniform,
+ sizeof(void*) * 2,
+ SLANG_ALIGN_OF(void*));
+
+ case ShaderParameterKind::RawBuffer:
+ case ShaderParameterKind::Buffer:
+ case ShaderParameterKind::MutableRawBuffer:
+ case ShaderParameterKind::MutableBuffer:
+ // It's a pointer and a size in bytes
+ return SimpleLayoutInfo(
+ LayoutResourceKind::Uniform,
+ sizeof(void*) * 2,
+ SLANG_ALIGN_OF(void*));
+
+ case ShaderParameterKind::SamplerState:
+ // It's a pointer
+ return SimpleLayoutInfo(
+ LayoutResourceKind::Uniform,
+ sizeof(void*),
+ SLANG_ALIGN_OF(void*));
+
+ case ShaderParameterKind::TextureSampler:
+ case ShaderParameterKind::MutableTextureSampler:
{
ObjectLayoutInfo info;
- info.layoutInfos.add(SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*)));
- info.layoutInfos.add(SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*)));
+ info.layoutInfos.add(SimpleLayoutInfo(
+ LayoutResourceKind::Uniform,
+ sizeof(void*),
+ SLANG_ALIGN_OF(void*)));
+ info.layoutInfos.add(SimpleLayoutInfo(
+ LayoutResourceKind::Uniform,
+ sizeof(void*),
+ SLANG_ALIGN_OF(void*)));
return info;
}
- case ShaderParameterKind::InputRenderTarget:
- // TODO: how to handle these?
- default:
- SLANG_UNEXPECTED("unhandled shader parameter kind");
- UNREACHABLE_RETURN(SimpleLayoutInfo());
+ case ShaderParameterKind::InputRenderTarget:
+ // TODO: how to handle these?
+ default:
+ SLANG_UNEXPECTED("unhandled shader parameter kind");
+ UNREACHABLE_RETURN(SimpleLayoutInfo());
}
}
};
@@ -1157,75 +1213,90 @@ struct CUDAObjectLayoutRulesImpl : CPUObjectLayoutRulesImpl
{
typedef CPUObjectLayoutRulesImpl Super;
- // cuda.h defines a variety of handle types. We don't want to have to include cuda.h though - as it may not be available
- // on a build target. So for we define this handle type, that matches cuda.h and is used for types that use this kind
- // of opaque handle (as opposed to a pointer) such as CUsurfObject, CUtexObject
+ // cuda.h defines a variety of handle types. We don't want to have to include cuda.h though - as
+ // it may not be available on a build target. So for we define this handle type, that matches
+ // cuda.h and is used for types that use this kind of opaque handle (as opposed to a pointer)
+ // such as CUsurfObject, CUtexObject
typedef unsigned long long ObjectHandle;
- virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options & /* options */) override
+ virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */)
+ override
{
switch (kind)
{
- case ShaderParameterKind::ConstantBuffer:
+ case ShaderParameterKind::ConstantBuffer:
{
// It's a pointer to the actual uniform data
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(CUDAPtr), sizeof(CUDAPtr));
+ return SimpleLayoutInfo(
+ LayoutResourceKind::Uniform,
+ sizeof(CUDAPtr),
+ sizeof(CUDAPtr));
}
- case ShaderParameterKind::TextureSampler:
- case ShaderParameterKind::MutableTextureSampler:
- // That there is no distinct Sampler on CUDA, so TextureSampler is the same as a Texture
- // which is an ObjectHandle.
- case ShaderParameterKind::MutableTexture:
- case ShaderParameterKind::TextureUniformBuffer:
- case ShaderParameterKind::Texture:
+ case ShaderParameterKind::TextureSampler:
+ case ShaderParameterKind::MutableTextureSampler:
+ // That there is no distinct Sampler on CUDA, so TextureSampler is the same as a
+ // Texture which is an ObjectHandle.
+ case ShaderParameterKind::MutableTexture:
+ case ShaderParameterKind::TextureUniformBuffer:
+ case ShaderParameterKind::Texture:
{
// It's a CUtexObject or CUsurfObject which is an opaque CUDAHandle sized
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(CUDAHandle), sizeof(CUDAPtr));
+ return SimpleLayoutInfo(
+ LayoutResourceKind::Uniform,
+ sizeof(CUDAHandle),
+ sizeof(CUDAPtr));
}
- case ShaderParameterKind::StructuredBuffer:
- case ShaderParameterKind::MutableStructuredBuffer:
- case ShaderParameterKind::AppendConsumeStructuredBuffer:
+ case ShaderParameterKind::StructuredBuffer:
+ case ShaderParameterKind::MutableStructuredBuffer:
+ case ShaderParameterKind::AppendConsumeStructuredBuffer:
{
// It's a ptr and a count of the amount of elements
- const size_t size = _roundToAlignment(sizeof(CUDAPtr) + sizeof(CUDACount), sizeof(CUDAPtr));
+ const size_t size =
+ _roundToAlignment(sizeof(CUDAPtr) + sizeof(CUDACount), sizeof(CUDAPtr));
return SimpleLayoutInfo(LayoutResourceKind::Uniform, size, sizeof(CUDAPtr));
}
- case ShaderParameterKind::RawBuffer:
- case ShaderParameterKind::Buffer:
- case ShaderParameterKind::MutableRawBuffer:
- case ShaderParameterKind::MutableBuffer:
+ case ShaderParameterKind::RawBuffer:
+ case ShaderParameterKind::Buffer:
+ case ShaderParameterKind::MutableRawBuffer:
+ case ShaderParameterKind::MutableBuffer:
{
// It's a ptr and a count of the amount of elements
- const size_t size = _roundToAlignment(sizeof(CUDAPtr) + sizeof(CUDACount), sizeof(CUDAPtr));
+ const size_t size =
+ _roundToAlignment(sizeof(CUDAPtr) + sizeof(CUDACount), sizeof(CUDAPtr));
return SimpleLayoutInfo(LayoutResourceKind::Uniform, size, sizeof(CUDAPtr));
}
- case ShaderParameterKind::SamplerState:
+ case ShaderParameterKind::SamplerState:
{
// In CUDA it seems that sampler states are combined into texture objects.
- // So it's a binding issue to combine a sampler with a texture - and sampler are ignored
- // For simplicity here though - we do create a variable and that variable takes up
- // uniform binding space.
- // TODO(JS): If we wanted to remove these variables we'd want to do it as a pass. The pass
- // would presumably have to remove use of variables of this kind throughout IR.
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(CUDASamplerState), sizeof(CUDAPtr));
+ // So it's a binding issue to combine a sampler with a texture - and sampler are
+ // ignored For simplicity here though - we do create a variable and that variable
+ // takes up uniform binding space.
+ // TODO(JS): If we wanted to remove these variables we'd want to do it as a pass.
+ // The pass would presumably have to remove use of variables of this kind throughout
+ // IR.
+ return SimpleLayoutInfo(
+ LayoutResourceKind::Uniform,
+ sizeof(CUDASamplerState),
+ sizeof(CUDAPtr));
}
- case ShaderParameterKind::InputRenderTarget:
- // TODO: how to handle these?
- default:
- SLANG_UNEXPECTED("unhandled shader parameter kind");
- UNREACHABLE_RETURN(SimpleLayoutInfo());
+ case ShaderParameterKind::InputRenderTarget:
+ // TODO: how to handle these?
+ default:
+ SLANG_UNEXPECTED("unhandled shader parameter kind");
+ UNREACHABLE_RETURN(SimpleLayoutInfo());
}
}
-
};
static CPUObjectLayoutRulesImpl kCPUObjectLayoutRulesImpl;
static CPULayoutRulesImpl kCPULayoutRulesImpl;
LayoutRulesImpl kCPULayoutRulesImpl_ = {
- &kCPULayoutRulesFamilyImpl, &kCPULayoutRulesImpl, &kCPUObjectLayoutRulesImpl,
+ &kCPULayoutRulesFamilyImpl,
+ &kCPULayoutRulesImpl,
+ &kCPUObjectLayoutRulesImpl,
};
LayoutRulesImpl kCPUAnyValueLayoutRulesImpl_ = {
@@ -1240,7 +1311,9 @@ static CUDAObjectLayoutRulesImpl kCUDAObjectLayoutRulesImpl;
static CUDALayoutRulesImpl kCUDALayoutRulesImpl;
LayoutRulesImpl kCUDALayoutRulesImpl_ = {
- &kCUDALayoutRulesFamilyImpl, &kCUDALayoutRulesImpl, &kCUDAObjectLayoutRulesImpl,
+ &kCUDALayoutRulesFamilyImpl,
+ &kCUDALayoutRulesImpl,
+ &kCUDAObjectLayoutRulesImpl,
};
LayoutRulesImpl kCUDAAnyValueLayoutRulesImpl_ = {
@@ -1252,21 +1325,29 @@ LayoutRulesImpl kCUDAAnyValueLayoutRulesImpl_ = {
// We want a custom layout for ray payloads to handle the logic of
// copying payload registers vs reading / writing to and from memory
LayoutRulesImpl kCUDARayPayloadParameterLayoutRulesImpl_ = {
- &kCUDALayoutRulesFamilyImpl, &kCUDARayPayloadParameterLayoutRulesImpl, &kCUDAObjectLayoutRulesImpl,
+ &kCUDALayoutRulesFamilyImpl,
+ &kCUDARayPayloadParameterLayoutRulesImpl,
+ &kCUDAObjectLayoutRulesImpl,
};
LayoutRulesImpl kCUDAHitAttributesParameterLayoutRulesImpl_ = {
- &kCUDALayoutRulesFamilyImpl, &kCUDAHitAttributesParameterLayoutRulesImpl, &kCUDAObjectLayoutRulesImpl,
+ &kCUDALayoutRulesFamilyImpl,
+ &kCUDAHitAttributesParameterLayoutRulesImpl,
+ &kCUDAObjectLayoutRulesImpl,
};
// GLSL cases
LayoutRulesImpl kStd140LayoutRulesImpl_ = {
- &kGLSLLayoutRulesFamilyImpl, &kStd140LayoutRulesImpl, &kGLSLObjectLayoutRulesImpl,
+ &kGLSLLayoutRulesFamilyImpl,
+ &kStd140LayoutRulesImpl,
+ &kGLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kStd430LayoutRulesImpl_ = {
- &kGLSLLayoutRulesFamilyImpl, &kStd430LayoutRulesImpl, &kGLSLObjectLayoutRulesImpl,
+ &kGLSLLayoutRulesFamilyImpl,
+ &kStd430LayoutRulesImpl,
+ &kGLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kScalarLayoutRulesImpl_ = {
@@ -1294,39 +1375,57 @@ LayoutRulesImpl kGLSLAnyValueLayoutRulesImpl_ = {
};
LayoutRulesImpl kGLSLPushConstantLayoutRulesImpl_ = {
- &kGLSLLayoutRulesFamilyImpl, &kStd430LayoutRulesImpl, &kGLSLPushConstantBufferObjectLayoutRulesImpl_,
+ &kGLSLLayoutRulesFamilyImpl,
+ &kStd430LayoutRulesImpl,
+ &kGLSLPushConstantBufferObjectLayoutRulesImpl_,
};
LayoutRulesImpl kGLSLShaderRecordLayoutRulesImpl_ = {
- &kGLSLLayoutRulesFamilyImpl, &kStd430LayoutRulesImpl, &kGLSLShaderRecordConstantBufferObjectLayoutRulesImpl_,
+ &kGLSLLayoutRulesFamilyImpl,
+ &kStd430LayoutRulesImpl,
+ &kGLSLShaderRecordConstantBufferObjectLayoutRulesImpl_,
};
LayoutRulesImpl kGLSLVaryingInputLayoutRulesImpl_ = {
- &kGLSLLayoutRulesFamilyImpl, &kGLSLVaryingInputLayoutRulesImpl, &kGLSLObjectLayoutRulesImpl,
+ &kGLSLLayoutRulesFamilyImpl,
+ &kGLSLVaryingInputLayoutRulesImpl,
+ &kGLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kGLSLVaryingOutputLayoutRulesImpl_ = {
- &kGLSLLayoutRulesFamilyImpl, &kGLSLVaryingOutputLayoutRulesImpl, &kGLSLObjectLayoutRulesImpl,
+ &kGLSLLayoutRulesFamilyImpl,
+ &kGLSLVaryingOutputLayoutRulesImpl,
+ &kGLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kGLSLSpecializationConstantLayoutRulesImpl_ = {
- &kGLSLLayoutRulesFamilyImpl, &kGLSLSpecializationConstantLayoutRulesImpl, &kGLSLObjectLayoutRulesImpl,
+ &kGLSLLayoutRulesFamilyImpl,
+ &kGLSLSpecializationConstantLayoutRulesImpl,
+ &kGLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kGLSLRayPayloadParameterLayoutRulesImpl_ = {
- &kGLSLLayoutRulesFamilyImpl, &kGLSLRayPayloadParameterLayoutRulesImpl, &kGLSLObjectLayoutRulesImpl,
+ &kGLSLLayoutRulesFamilyImpl,
+ &kGLSLRayPayloadParameterLayoutRulesImpl,
+ &kGLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kGLSLCallablePayloadParameterLayoutRulesImpl_ = {
- &kGLSLLayoutRulesFamilyImpl, &kGLSLCallablePayloadParameterLayoutRulesImpl, &kGLSLObjectLayoutRulesImpl,
+ &kGLSLLayoutRulesFamilyImpl,
+ &kGLSLCallablePayloadParameterLayoutRulesImpl,
+ &kGLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kGLSLHitAttributesParameterLayoutRulesImpl_ = {
- &kGLSLLayoutRulesFamilyImpl, &kGLSLHitAttributesParameterLayoutRulesImpl, &kGLSLObjectLayoutRulesImpl,
+ &kGLSLLayoutRulesFamilyImpl,
+ &kGLSLHitAttributesParameterLayoutRulesImpl,
+ &kGLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kGLSLStructuredBufferLayoutRulesImpl_ = {
- &kGLSLLayoutRulesFamilyImpl, &kStd430LayoutRulesImpl, &kGLSLObjectLayoutRulesImpl,
+ &kGLSLLayoutRulesFamilyImpl,
+ &kStd430LayoutRulesImpl,
+ &kGLSLObjectLayoutRulesImpl,
};
@@ -1339,35 +1438,51 @@ LayoutRulesImpl kHLSLAnyValueLayoutRulesImpl_ = {
};
LayoutRulesImpl kHLSLConstantBufferLayoutRulesImpl_ = {
- &kHLSLLayoutRulesFamilyImpl, &kHLSLConstantBufferLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl,
+ &kHLSLLayoutRulesFamilyImpl,
+ &kHLSLConstantBufferLayoutRulesImpl,
+ &kHLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kHLSLStructuredBufferLayoutRulesImpl_ = {
- &kHLSLLayoutRulesFamilyImpl, &kHLSLStructuredBufferLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl,
+ &kHLSLLayoutRulesFamilyImpl,
+ &kHLSLStructuredBufferLayoutRulesImpl,
+ &kHLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kHLSLTextureBufferLayoutRulesImpl_ = {
- &kHLSLLayoutRulesFamilyImpl, &kHLSLConstantBufferLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl,
+ &kHLSLLayoutRulesFamilyImpl,
+ &kHLSLConstantBufferLayoutRulesImpl,
+ &kHLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kHLSLVaryingInputLayoutRulesImpl_ = {
- &kHLSLLayoutRulesFamilyImpl, &kHLSLVaryingInputLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl,
+ &kHLSLLayoutRulesFamilyImpl,
+ &kHLSLVaryingInputLayoutRulesImpl,
+ &kHLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kHLSLVaryingOutputLayoutRulesImpl_ = {
- &kHLSLLayoutRulesFamilyImpl, &kHLSLVaryingOutputLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl,
+ &kHLSLLayoutRulesFamilyImpl,
+ &kHLSLVaryingOutputLayoutRulesImpl,
+ &kHLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kHLSLRayPayloadParameterLayoutRulesImpl_ = {
- &kHLSLLayoutRulesFamilyImpl, &kHLSLRayPayloadParameterLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl,
+ &kHLSLLayoutRulesFamilyImpl,
+ &kHLSLRayPayloadParameterLayoutRulesImpl,
+ &kHLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kHLSLCallablePayloadParameterLayoutRulesImpl_ = {
- &kHLSLLayoutRulesFamilyImpl, &kHLSLCallablePayloadParameterLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl,
+ &kHLSLLayoutRulesFamilyImpl,
+ &kHLSLCallablePayloadParameterLayoutRulesImpl,
+ &kHLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kHLSLHitAttributesParameterLayoutRulesImpl_ = {
- &kHLSLLayoutRulesFamilyImpl, &kHLSLHitAttributesParameterLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl,
+ &kHLSLLayoutRulesFamilyImpl,
+ &kHLSLHitAttributesParameterLayoutRulesImpl,
+ &kHLSLObjectLayoutRulesImpl,
};
// GLSL Family
@@ -1377,7 +1492,8 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getAnyValueRules()
return &kGLSLAnyValueLayoutRulesImpl_;
}
-LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getConstantBufferRules(CompilerOptionSet& compilerOptions)
+LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getConstantBufferRules(
+ CompilerOptionSet& compilerOptions)
{
if (compilerOptions.shouldUseScalarLayout())
return &kScalarLayoutRulesImpl_;
@@ -1387,7 +1503,8 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getConstantBufferRules(CompilerOptio
return &kStd140LayoutRulesImpl_;
}
-LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getParameterBlockRules(CompilerOptionSet& compilerOptions)
+LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getParameterBlockRules(
+ CompilerOptionSet& compilerOptions)
{
if (compilerOptions.shouldUseScalarLayout())
return &kScalarLayoutRulesImpl_;
@@ -1407,7 +1524,8 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getShaderRecordConstantBufferRules()
return &kGLSLShaderRecordLayoutRulesImpl_;
}
-LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getTextureBufferRules(CompilerOptionSet& compilerOptions)
+LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getTextureBufferRules(
+ CompilerOptionSet& compilerOptions)
{
if (compilerOptions.shouldUseScalarLayout())
return &kScalarLayoutRulesImpl_;
@@ -1415,7 +1533,6 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getTextureBufferRules(CompilerOption
return &kFXCConstantBufferLayoutRulesFamilyImpl;
return &kStd430LayoutRulesImpl_;
-
}
LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getVaryingInputRules()
@@ -1433,7 +1550,8 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getSpecializationConstantRules()
return &kGLSLSpecializationConstantLayoutRulesImpl_;
}
-LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getShaderStorageBufferRules(CompilerOptionSet& compilerOptions)
+LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getShaderStorageBufferRules(
+ CompilerOptionSet& compilerOptions)
{
if (compilerOptions.shouldUseScalarLayout())
return &kScalarLayoutRulesImpl_;
@@ -1458,7 +1576,8 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getHitAttributesParameterRules()
return &kGLSLHitAttributesParameterLayoutRulesImpl_;
}
-LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getStructuredBufferRules(CompilerOptionSet& compilerOptions)
+LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getStructuredBufferRules(
+ CompilerOptionSet& compilerOptions)
{
if (compilerOptions.shouldUseScalarLayout())
return &kScalarLayoutRulesImpl_;
@@ -1582,7 +1701,7 @@ LayoutRulesImpl* CPULayoutRulesFamilyImpl::getShaderStorageBufferRules(CompilerO
}
LayoutRulesImpl* CPULayoutRulesFamilyImpl::getParameterBlockRules(CompilerOptionSet&)
{
- // Not clear - just use similar to CPU
+ // Not clear - just use similar to CPU
return &kCPULayoutRulesImpl_;
}
LayoutRulesImpl* CPULayoutRulesFamilyImpl::getRayPayloadParameterRules()
@@ -1648,12 +1767,12 @@ LayoutRulesImpl* CUDALayoutRulesFamilyImpl::getShaderStorageBufferRules(Compiler
}
LayoutRulesImpl* CUDALayoutRulesFamilyImpl::getParameterBlockRules(CompilerOptionSet&)
{
- // Not clear - just use similar to CPU
+ // Not clear - just use similar to CPU
return &kCUDALayoutRulesImpl_;
}
LayoutRulesImpl* CUDALayoutRulesFamilyImpl::getRayPayloadParameterRules()
{
- // Mimicking HLSL
+ // Mimicking HLSL
return &kCUDARayPayloadParameterLayoutRulesImpl_;
}
LayoutRulesImpl* CUDALayoutRulesFamilyImpl::getCallablePayloadParameterRules()
@@ -1679,7 +1798,8 @@ LayoutRulesImpl* CUDALayoutRulesFamilyImpl::getStructuredBufferRules(CompilerOpt
struct MetalObjectLayoutRulesImpl : ObjectLayoutRulesImpl
{
- virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */) override
+ virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */)
+ override
{
switch (kind)
{
@@ -1703,12 +1823,12 @@ struct MetalObjectLayoutRulesImpl : ObjectLayoutRulesImpl
case ShaderParameterKind::TextureSampler:
case ShaderParameterKind::MutableTextureSampler:
- {
- ObjectLayoutInfo info;
- info.layoutInfos.add(SimpleLayoutInfo(LayoutResourceKind::MetalTexture, 1));
- info.layoutInfos.add(SimpleLayoutInfo(LayoutResourceKind::SamplerState, 1));
- return info;
- }
+ {
+ ObjectLayoutInfo info;
+ info.layoutInfos.add(SimpleLayoutInfo(LayoutResourceKind::MetalTexture, 1));
+ info.layoutInfos.add(SimpleLayoutInfo(LayoutResourceKind::SamplerState, 1));
+ return info;
+ }
default:
SLANG_UNEXPECTED("unhandled shader parameter kind");
UNREACHABLE_RETURN(SimpleLayoutInfo());
@@ -1721,11 +1841,13 @@ struct MetalArgumentBufferElementLayoutRulesImpl : ObjectLayoutRulesImpl, Defaul
SimpleLayoutInfo GetScalarLayout(BaseType baseType) override
{
SLANG_UNUSED(baseType);
- // Everything in a metal argument buffer, including basic scalar values, occupy one `[[id]]` slot.
+ // Everything in a metal argument buffer, including basic scalar values, occupy one `[[id]]`
+ // slot.
return SimpleLayoutInfo(LayoutResourceKind::MetalArgumentBufferElement, 1);
}
- virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */) override
+ virtual ObjectLayoutInfo GetObjectLayout(ShaderParameterKind kind, const Options& /* options */)
+ override
{
switch (kind)
{
@@ -1740,15 +1862,15 @@ struct MetalArgumentBufferElementLayoutRulesImpl : ObjectLayoutRulesImpl, Defaul
case ShaderParameterKind::TextureUniformBuffer:
case ShaderParameterKind::Texture:
case ShaderParameterKind::SamplerState:
- {
- return SimpleLayoutInfo(LayoutResourceKind::MetalArgumentBufferElement, 1);
- }
+ {
+ return SimpleLayoutInfo(LayoutResourceKind::MetalArgumentBufferElement, 1);
+ }
case ShaderParameterKind::TextureSampler:
case ShaderParameterKind::AppendConsumeStructuredBuffer:
case ShaderParameterKind::MutableTextureSampler:
- {
- return SimpleLayoutInfo(LayoutResourceKind::MetalArgumentBufferElement, 2);
- }
+ {
+ return SimpleLayoutInfo(LayoutResourceKind::MetalArgumentBufferElement, 2);
+ }
default:
SLANG_UNEXPECTED("unhandled shader parameter kind");
UNREACHABLE_RETURN(SimpleLayoutInfo());
@@ -1767,23 +1889,33 @@ LayoutRulesImpl kMetalAnyValueLayoutRulesImpl_ = {
};
LayoutRulesImpl kMetalConstantBufferLayoutRulesImpl_ = {
- &kMetalLayoutRulesFamilyImpl, & kMetalLayoutRulesImpl, &kMetalObjectLayoutRulesImpl,
+ &kMetalLayoutRulesFamilyImpl,
+ &kMetalLayoutRulesImpl,
+ &kMetalObjectLayoutRulesImpl,
};
LayoutRulesImpl kMetalParameterBlockLayoutRulesImpl_ = {
- &kMetalLayoutRulesFamilyImpl, &kMetalArgumentBufferElementLayoutRulesImpl, &kMetalArgumentBufferElementLayoutRulesImpl,
+ &kMetalLayoutRulesFamilyImpl,
+ &kMetalArgumentBufferElementLayoutRulesImpl,
+ &kMetalArgumentBufferElementLayoutRulesImpl,
};
LayoutRulesImpl kMetalStructuredBufferLayoutRulesImpl_ = {
- &kMetalLayoutRulesFamilyImpl, &kMetalLayoutRulesImpl, & kMetalObjectLayoutRulesImpl,
+ &kMetalLayoutRulesFamilyImpl,
+ &kMetalLayoutRulesImpl,
+ &kMetalObjectLayoutRulesImpl,
};
LayoutRulesImpl kMetalVaryingInputLayoutRulesImpl_ = {
- &kMetalLayoutRulesFamilyImpl, &kMetalVaryingInputLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl,
+ &kMetalLayoutRulesFamilyImpl,
+ &kMetalVaryingInputLayoutRulesImpl,
+ &kHLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl kMetalVaryingOutputLayoutRulesImpl_ = {
- &kMetalLayoutRulesFamilyImpl, &kMetalVaryingOutputLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl,
+ &kMetalLayoutRulesFamilyImpl,
+ &kMetalVaryingOutputLayoutRulesImpl,
+ &kHLSLObjectLayoutRulesImpl,
};
LayoutRulesImpl* MetalLayoutRulesFamilyImpl::getAnyValueRules()
@@ -1859,7 +1991,9 @@ LayoutRulesImpl* MetalLayoutRulesFamilyImpl::getHitAttributesParameterRules()
// WGSL Family
LayoutRulesImpl kWGSLConstantBufferLayoutRulesImpl_ = {
- &kWGSLLayoutRulesFamilyImpl, &kStd140LayoutRulesImpl, &kWGSLObjectLayoutRulesImpl,
+ &kWGSLLayoutRulesFamilyImpl,
+ &kStd140LayoutRulesImpl,
+ &kWGSLObjectLayoutRulesImpl,
};
LayoutRulesImpl* WGSLLayoutRulesFamilyImpl::getAnyValueRules()
@@ -1941,18 +2075,15 @@ LayoutRulesFamilyImpl* getDefaultLayoutRulesFamilyForTarget(TargetRequest* targe
case CodeGenTarget::DXBytecode:
case CodeGenTarget::DXBytecodeAssembly:
case CodeGenTarget::DXIL:
- case CodeGenTarget::DXILAssembly:
- return &kHLSLLayoutRulesFamilyImpl;
+ case CodeGenTarget::DXILAssembly: return &kHLSLLayoutRulesFamilyImpl;
case CodeGenTarget::GLSL:
case CodeGenTarget::SPIRV:
- case CodeGenTarget::SPIRVAssembly:
- return &kGLSLLayoutRulesFamilyImpl;
+ case CodeGenTarget::SPIRVAssembly: return &kGLSLLayoutRulesFamilyImpl;
case CodeGenTarget::WGSL:
case CodeGenTarget::WGSLSPIRV:
- case CodeGenTarget::WGSLSPIRVAssembly:
- return &kWGSLLayoutRulesFamilyImpl;
+ case CodeGenTarget::WGSLSPIRVAssembly: return &kWGSLLayoutRulesFamilyImpl;
case CodeGenTarget::HostHostCallable:
case CodeGenTarget::ShaderHostCallable:
@@ -1961,35 +2092,36 @@ LayoutRulesFamilyImpl* getDefaultLayoutRulesFamilyForTarget(TargetRequest* targe
case CodeGenTarget::ShaderSharedLibrary:
case CodeGenTarget::CPPSource:
case CodeGenTarget::CSource:
- {
- // For now lets use some fairly simple CPU binding rules
+ {
+ // For now lets use some fairly simple CPU binding rules
- // We just need to decide here what style of layout is appropriate, in terms of memory
- // and binding. That in terms of the actual binding that will be injected into functions
- // in the form of a BindContext. For now we'll go with HLSL layout -
- // that we may want to rethink that with the use of arrays and binding VK style binding might be
- // more appropriate in some ways.
+ // We just need to decide here what style of layout is appropriate, in terms of memory
+ // and binding. That in terms of the actual binding that will be injected into functions
+ // in the form of a BindContext. For now we'll go with HLSL layout -
+ // that we may want to rethink that with the use of arrays and binding VK style binding
+ // might be more appropriate in some ways.
- return &kCPULayoutRulesFamilyImpl;
- }
+ return &kCPULayoutRulesFamilyImpl;
+ }
case CodeGenTarget::Metal:
case CodeGenTarget::MetalLib:
- case CodeGenTarget::MetalLibAssembly:
- return &kMetalLayoutRulesFamilyImpl;
+ case CodeGenTarget::MetalLibAssembly: return &kMetalLayoutRulesFamilyImpl;
case CodeGenTarget::PTX:
case CodeGenTarget::CUDASource:
- {
- return &kCUDALayoutRulesFamilyImpl;
- }
+ {
+ return &kCUDALayoutRulesFamilyImpl;
+ }
- default:
- return nullptr;
+ default: return nullptr;
}
}
-TypeLayoutContext getInitialLayoutContextForTarget(TargetRequest* targetReq, ProgramLayout* programLayout, slang::LayoutRules rules)
+TypeLayoutContext getInitialLayoutContextForTarget(
+ TargetRequest* targetReq,
+ ProgramLayout* programLayout,
+ slang::LayoutRules rules)
{
auto astBuilder = targetReq->getLinkage()->getASTBuilder();
@@ -1997,9 +2129,7 @@ TypeLayoutContext getInitialLayoutContextForTarget(TargetRequest* targetReq, Pro
switch (rules)
{
case slang::LayoutRules::Default:
- default:
- rulesFamily = getDefaultLayoutRulesFamilyForTarget(targetReq);
- break;
+ default: rulesFamily = getDefaultLayoutRulesFamilyForTarget(targetReq); break;
case slang::LayoutRules::MetalArgumentBufferTier2:
rulesFamily = &kCPULayoutRulesFamilyImpl;
break;
@@ -2008,16 +2138,17 @@ TypeLayoutContext getInitialLayoutContextForTarget(TargetRequest* targetReq, Pro
TypeLayoutContext context;
context.astBuilder = astBuilder;
context.targetReq = targetReq;
- context.programLayout = programLayout;
+ context.programLayout = programLayout;
context.rules = nullptr;
context.matrixLayoutMode = targetReq->getOptionSet().getMatrixLayoutMode();
if (auto hlslToVulkanLayoutOptions = targetReq->getHLSLToVulkanLayoutOptions())
{
- context.objectLayoutOptions.hlslToVulkanKindFlags = hlslToVulkanLayoutOptions->getKindShiftEnabledFlags();
+ context.objectLayoutOptions.hlslToVulkanKindFlags =
+ hlslToVulkanLayoutOptions->getKindShiftEnabledFlags();
}
- if( rulesFamily )
+ if (rulesFamily)
{
context.rules = rulesFamily->getConstantBufferRules(targetReq->getOptionSet());
}
@@ -2029,7 +2160,7 @@ TypeLayoutContext getInitialLayoutContextForTarget(TargetRequest* targetReq, Pro
static LayoutSize GetElementCount(IntVal* val)
{
// Lack of a size indicates an unbounded array.
- if(!val)
+ if (!val)
return LayoutSize::infinite();
if (auto constantVal = as<ConstantIntVal>(val))
@@ -2038,7 +2169,7 @@ static LayoutSize GetElementCount(IntVal* val)
return LayoutSize::infinite();
return LayoutSize(LayoutSize::RawValue(constantVal->getValue()));
}
- else if(const auto varRefVal = as<GenericParamIntVal>(val))
+ else if (const auto varRefVal = as<GenericParamIntVal>(val))
{
// TODO: We want to treat the case where the number of
// elements in an array depends on a generic parameter
@@ -2063,24 +2194,21 @@ bool IsResourceKind(LayoutResourceKind kind)
switch (kind)
{
case LayoutResourceKind::None:
- case LayoutResourceKind::Uniform:
- return false;
+ case LayoutResourceKind::Uniform: return false;
- default:
- return true;
+ default: return true;
}
-
}
- /// Create a type layout for a type that has simple layout needs.
- ///
- /// This handles any type that can express its layout in `SimpleLayoutInfo`,
- /// and that only needs a `TypeLayout` and not a refined subclass.
- ///
+/// Create a type layout for a type that has simple layout needs.
+///
+/// This handles any type that can express its layout in `SimpleLayoutInfo`,
+/// and that only needs a `TypeLayout` and not a refined subclass.
+///
static TypeLayoutResult createSimpleTypeLayout(
- SimpleLayoutInfo info,
- Type* type,
- LayoutRulesImpl* rules)
+ SimpleLayoutInfo info,
+ Type* type,
+ LayoutRulesImpl* rules)
{
RefPtr<TypeLayout> typeLayout = new TypeLayout();
@@ -2117,17 +2245,25 @@ static SimpleLayoutInfo _getParameterGroupLayoutInfo(
ParameterGroupType* type,
LayoutRulesImpl* rules)
{
- if( as<ConstantBufferType>(type) )
+ if (as<ConstantBufferType>(type))
{
- return rules->GetObjectLayout(ShaderParameterKind::ConstantBuffer, context.objectLayoutOptions).getSimple();
+ return rules
+ ->GetObjectLayout(ShaderParameterKind::ConstantBuffer, context.objectLayoutOptions)
+ .getSimple();
}
- else if( as<TextureBufferType>(type) )
+ else if (as<TextureBufferType>(type))
{
- return rules->GetObjectLayout(ShaderParameterKind::TextureUniformBuffer, context.objectLayoutOptions).getSimple();
+ return rules
+ ->GetObjectLayout(
+ ShaderParameterKind::TextureUniformBuffer,
+ context.objectLayoutOptions)
+ .getSimple();
}
- else if( as<GLSLShaderStorageBufferType>(type) )
+ else if (as<GLSLShaderStorageBufferType>(type))
{
- return rules->GetObjectLayout(ShaderParameterKind::ShaderStorageBuffer, context.objectLayoutOptions).getSimple();
+ return rules
+ ->GetObjectLayout(ShaderParameterKind::ShaderStorageBuffer, context.objectLayoutOptions)
+ .getSimple();
}
else if (as<ParameterBlockType>(type))
{
@@ -2147,11 +2283,11 @@ static SimpleLayoutInfo _getParameterGroupLayoutInfo(
// TODO: the vertex-input and fragment-output cases should
// only actually apply when we are at the appropriate stage in
// the pipeline...
- else if( as<GLSLInputParameterGroupType>(type) )
+ else if (as<GLSLInputParameterGroupType>(type))
{
return SimpleLayoutInfo(LayoutResourceKind::VertexInput, 0);
}
- else if( as<GLSLOutputParameterGroupType>(type) )
+ else if (as<GLSLOutputParameterGroupType>(type))
{
return SimpleLayoutInfo(LayoutResourceKind::FragmentOutput, 0);
}
@@ -2170,17 +2306,15 @@ static bool isOpenGLTarget(TargetRequest*)
bool isD3DTarget(TargetRequest* targetReq)
{
- switch( targetReq->getTarget() )
+ switch (targetReq->getTarget())
{
case CodeGenTarget::HLSL:
case CodeGenTarget::DXBytecode:
case CodeGenTarget::DXBytecodeAssembly:
case CodeGenTarget::DXIL:
- case CodeGenTarget::DXILAssembly:
- return true;
+ case CodeGenTarget::DXILAssembly: return true;
- default:
- return false;
+ default: return false;
}
}
@@ -2188,45 +2322,40 @@ bool isMetalTarget(TargetRequest* targetReq)
{
switch (targetReq->getTarget())
{
- default:
- return false;
+ default: return false;
case CodeGenTarget::Metal:
case CodeGenTarget::MetalLib:
- case CodeGenTarget::MetalLibAssembly:
- return true;
+ case CodeGenTarget::MetalLibAssembly: return true;
}
}
bool isKhronosTarget(TargetRequest* targetReq)
{
- switch( targetReq->getTarget() )
+ switch (targetReq->getTarget())
{
- default:
- return false;
+ default: return false;
case CodeGenTarget::GLSL:
case CodeGenTarget::SPIRV:
- case CodeGenTarget::SPIRVAssembly:
- return true;
+ case CodeGenTarget::SPIRVAssembly: return true;
}
}
bool isCPUTarget(TargetRequest* targetReq)
{
- return ArtifactDescUtil::isCpuLikeTarget(ArtifactDescUtil::makeDescForCompileTarget(asExternal(targetReq->getTarget())));
+ return ArtifactDescUtil::isCpuLikeTarget(
+ ArtifactDescUtil::makeDescForCompileTarget(asExternal(targetReq->getTarget())));
}
bool isCUDATarget(TargetRequest* targetReq)
{
- switch( targetReq->getTarget() )
+ switch (targetReq->getTarget())
{
- default:
- return false;
+ default: return false;
case CodeGenTarget::CUDASource:
- case CodeGenTarget::PTX:
- return true;
+ case CodeGenTarget::PTX: return true;
}
}
@@ -2240,56 +2369,56 @@ SourceLanguage getIntermediateSourceLanguageForTarget(TargetProgram* targetProgr
switch (targetProgram->getTargetReq()->getTarget())
{
- case CodeGenTarget::GLSL:
- // If we aren't emitting directly we are going to output GLSL to feed to GLSLANG
- case CodeGenTarget::SPIRV:
- case CodeGenTarget::SPIRVAssembly:
+ case CodeGenTarget::GLSL:
+ // If we aren't emitting directly we are going to output GLSL to feed to GLSLANG
+ case CodeGenTarget::SPIRV:
+ case CodeGenTarget::SPIRVAssembly:
{
return SourceLanguage::GLSL;
}
- case CodeGenTarget::HLSL:
- case CodeGenTarget::DXBytecode:
- case CodeGenTarget::DXBytecodeAssembly:
- case CodeGenTarget::DXIL:
- case CodeGenTarget::DXILAssembly:
+ case CodeGenTarget::HLSL:
+ case CodeGenTarget::DXBytecode:
+ case CodeGenTarget::DXBytecodeAssembly:
+ case CodeGenTarget::DXIL:
+ case CodeGenTarget::DXILAssembly:
{
// Currently DXBytecode and DXIL are generated via HLSL
return SourceLanguage::HLSL;
}
- case CodeGenTarget::Metal:
- case CodeGenTarget::MetalLib:
- case CodeGenTarget::MetalLibAssembly:
+ case CodeGenTarget::Metal:
+ case CodeGenTarget::MetalLib:
+ case CodeGenTarget::MetalLibAssembly:
{
return SourceLanguage::Metal;
}
- case CodeGenTarget::WGSL:
+ case CodeGenTarget::WGSL:
{
return SourceLanguage::WGSL;
}
- case CodeGenTarget::CSource:
+ case CodeGenTarget::CSource:
{
return SourceLanguage::C;
}
- case CodeGenTarget::ShaderSharedLibrary:
- case CodeGenTarget::HostSharedLibrary:
- case CodeGenTarget::ObjectCode:
- case CodeGenTarget::HostExecutable:
- case CodeGenTarget::HostHostCallable:
- case CodeGenTarget::ShaderHostCallable:
- case CodeGenTarget::CPPSource:
- case CodeGenTarget::HostCPPSource:
- case CodeGenTarget::PyTorchCppBinding:
+ case CodeGenTarget::ShaderSharedLibrary:
+ case CodeGenTarget::HostSharedLibrary:
+ case CodeGenTarget::ObjectCode:
+ case CodeGenTarget::HostExecutable:
+ case CodeGenTarget::HostHostCallable:
+ case CodeGenTarget::ShaderHostCallable:
+ case CodeGenTarget::CPPSource:
+ case CodeGenTarget::HostCPPSource:
+ case CodeGenTarget::PyTorchCppBinding:
{
// For CPU based scenarios are generated via C++
return SourceLanguage::CPP;
}
- case CodeGenTarget::CUDAObjectCode:
- case CodeGenTarget::CUDASource:
- case CodeGenTarget::PTX:
+ case CodeGenTarget::CUDAObjectCode:
+ case CodeGenTarget::CUDASource:
+ case CodeGenTarget::PTX:
{
return SourceLanguage::CUDA;
}
- default: break;
+ default: break;
}
return SourceLanguage::Unknown;
@@ -2315,14 +2444,14 @@ static bool isD3D12Target(TargetRequest* targetReq)
static bool isSM5OrEarlier(TargetRequest* targetReq)
{
- if(!isD3DTarget(targetReq))
+ if (!isD3DTarget(targetReq))
return false;
auto profile = targetReq->getOptionSet().getProfile();
- if(profile.getFamily() == ProfileFamily::DX)
+ if (profile.getFamily() == ProfileFamily::DX)
{
- if(profile.getVersion() <= ProfileVersion::DX_5_0)
+ if (profile.getVersion() <= ProfileVersion::DX_5_0)
return true;
}
@@ -2331,14 +2460,14 @@ static bool isSM5OrEarlier(TargetRequest* targetReq)
static bool isSM5_1OrLater(TargetRequest* targetReq)
{
- if(!isD3DTarget(targetReq))
+ if (!isD3DTarget(targetReq))
return false;
auto profile = targetReq->getOptionSet().getProfile();
- if(profile.getFamily() == ProfileFamily::DX)
+ if (profile.getFamily() == ProfileFamily::DX)
{
- if(profile.getVersion() >= ProfileVersion::DX_5_1)
+ if (profile.getVersion() >= ProfileVersion::DX_5_1)
return true;
}
@@ -2352,27 +2481,26 @@ static bool isVulkanTarget(TargetRequest* targetReq)
return isKhronosTarget(targetReq);
}
-static bool shouldAllocateRegisterSpaceForParameterBlock(
- TypeLayoutContext const& context)
+static bool shouldAllocateRegisterSpaceForParameterBlock(TypeLayoutContext const& context)
{
auto targetReq = context.targetReq;
// We *never* want to use register spaces/sets under
// OpenGL, D3D11, or for Shader Model 5.0 or earlier.
- if(isOpenGLTarget(targetReq) || isD3D11Target(targetReq) || isSM5OrEarlier(targetReq))
+ if (isOpenGLTarget(targetReq) || isD3D11Target(targetReq) || isSM5OrEarlier(targetReq))
return false;
// If we know that we are targetting Vulkan, then
// the only way to effectively use parameter blocks
// is by using descriptor sets.
- if(isVulkanTarget(targetReq))
+ if (isVulkanTarget(targetReq))
return true;
// If none of the above passed, then it seems like we
// are generating code for D3D12, and using SM5.1 or later.
// We will use a register space for parameter blocks *if*
// the target options tell us to:
- if( isD3D12Target(targetReq) && isSM5_1OrLater(targetReq) )
+ if (isD3D12Target(targetReq) && isSM5_1OrLater(targetReq))
{
return true;
}
@@ -2400,8 +2528,8 @@ bool canTypeDirectlyUseRegisterSpace(TypeLayout* layout)
// Given an existing type layout `oldTypeLayout`, apply offsets
// to any contained fields based on the resource infos in `offsetVarLayout`.
RefPtr<TypeLayout> applyOffsetToTypeLayout(
- RefPtr<TypeLayout> oldTypeLayout,
- RefPtr<VarLayout> offsetVarLayout)
+ RefPtr<TypeLayout> oldTypeLayout,
+ RefPtr<VarLayout> offsetVarLayout)
{
// There is no need to apply offsets if the old type and the offset
// don't share any resource infos in common.
@@ -2414,13 +2542,14 @@ RefPtr<TypeLayout> applyOffsetToTypeLayout(
break;
}
}
- if( auto oldPendingTypeLayout = oldTypeLayout->pendingDataTypeLayout )
+ if (auto oldPendingTypeLayout = oldTypeLayout->pendingDataTypeLayout)
{
- if( auto pendingOffsetVarLayout = offsetVarLayout->pendingVarLayout )
+ if (auto pendingOffsetVarLayout = offsetVarLayout->pendingVarLayout)
{
for (auto oldResInfo : oldPendingTypeLayout->resourceInfos)
{
- if (const auto offsetResInfo = pendingOffsetVarLayout->FindResourceInfo(oldResInfo.kind))
+ if (const auto offsetResInfo =
+ pendingOffsetVarLayout->FindResourceInfo(oldResInfo.kind))
{
anyHit = true;
break;
@@ -2465,17 +2594,18 @@ RefPtr<TypeLayout> applyOffsetToTypeLayout(
}
}
- if( auto oldPendingField = oldField->pendingVarLayout )
+ if (auto oldPendingField = oldField->pendingVarLayout)
{
RefPtr<VarLayout> newPendingField = new VarLayout();
- newPendingField->varDecl = oldPendingField->varDecl;
- newPendingField->typeLayout = oldPendingField->typeLayout;
- newPendingField->flags = oldPendingField->flags;
- newPendingField->semanticIndex = oldPendingField->semanticIndex;
- newPendingField->semanticName = oldPendingField->semanticName;
- newPendingField->stage = oldPendingField->stage;
- newPendingField->systemValueSemantic = oldPendingField->systemValueSemantic;
- newPendingField->systemValueSemanticIndex = oldPendingField->systemValueSemanticIndex;
+ newPendingField->varDecl = oldPendingField->varDecl;
+ newPendingField->typeLayout = oldPendingField->typeLayout;
+ newPendingField->flags = oldPendingField->flags;
+ newPendingField->semanticIndex = oldPendingField->semanticIndex;
+ newPendingField->semanticName = oldPendingField->semanticName;
+ newPendingField->stage = oldPendingField->stage;
+ newPendingField->systemValueSemantic = oldPendingField->systemValueSemantic;
+ newPendingField->systemValueSemanticIndex =
+ oldPendingField->systemValueSemanticIndex;
newField->pendingVarLayout = newPendingField;
@@ -2484,9 +2614,10 @@ RefPtr<TypeLayout> applyOffsetToTypeLayout(
auto newResInfo = newPendingField->findOrAddResourceInfo(oldResInfo.kind);
newResInfo->index = oldResInfo.index;
newResInfo->space = oldResInfo.space;
- if( auto pendingOffsetVarLayout = offsetVarLayout->pendingVarLayout )
+ if (auto pendingOffsetVarLayout = offsetVarLayout->pendingVarLayout)
{
- if (auto offsetResInfo = pendingOffsetVarLayout->FindResourceInfo(oldResInfo.kind))
+ if (auto offsetResInfo =
+ pendingOffsetVarLayout->FindResourceInfo(oldResInfo.kind))
{
newResInfo->index += offsetResInfo->index;
}
@@ -2524,11 +2655,12 @@ RefPtr<TypeLayout> applyOffsetToTypeLayout(
newResInfo->count = oldResInfo.count;
}
- if( auto oldPendingTypeLayout = oldTypeLayout->pendingDataTypeLayout )
+ if (auto oldPendingTypeLayout = oldTypeLayout->pendingDataTypeLayout)
{
- if( auto pendingOffsetVarLayout = offsetVarLayout->pendingVarLayout )
+ if (auto pendingOffsetVarLayout = offsetVarLayout->pendingVarLayout)
{
- newTypeLayout->pendingDataTypeLayout = applyOffsetToTypeLayout(oldPendingTypeLayout, pendingOffsetVarLayout);
+ newTypeLayout->pendingDataTypeLayout =
+ applyOffsetToTypeLayout(oldPendingTypeLayout, pendingOffsetVarLayout);
}
}
@@ -2536,9 +2668,9 @@ RefPtr<TypeLayout> applyOffsetToTypeLayout(
}
IRTypeLayout* applyOffsetToTypeLayout(
- IRBuilder* irBuilder,
- IRTypeLayout* oldTypeLayout,
- IRVarLayout* offsetVarLayout)
+ IRBuilder* irBuilder,
+ IRTypeLayout* oldTypeLayout,
+ IRVarLayout* offsetVarLayout)
{
// The body of this function is derived from the AST case defined above.
//
@@ -2552,7 +2684,8 @@ IRTypeLayout* applyOffsetToTypeLayout(
bool anyHit = false;
for (auto oldResInfo : oldTypeLayout->getSizeAttrs())
{
- if (const auto offsetResInfo = offsetVarLayout->findOffsetAttr(oldResInfo->getResourceKind()))
+ if (const auto offsetResInfo =
+ offsetVarLayout->findOffsetAttr(oldResInfo->getResourceKind()))
{
anyHit = true;
break;
@@ -2605,33 +2738,30 @@ IRTypeLayout* applyOffsetToTypeLayout(
}
IRVarLayout* applyOffsetToVarLayout(
- IRBuilder* irBuilder,
- IRVarLayout* baseLayout,
- IRVarLayout* offsetLayout)
+ IRBuilder* irBuilder,
+ IRVarLayout* baseLayout,
+ IRVarLayout* offsetLayout)
{
IRVarLayout::Builder adjustedLayoutBuilder(irBuilder, baseLayout->getTypeLayout());
adjustedLayoutBuilder.cloneEverythingButOffsetsFrom(baseLayout);
- if( auto basePendingLayout = baseLayout->getPendingVarLayout() )
+ if (auto basePendingLayout = baseLayout->getPendingVarLayout())
{
- if( auto offsetPendingLayout = offsetLayout->getPendingVarLayout() )
+ if (auto offsetPendingLayout = offsetLayout->getPendingVarLayout())
{
adjustedLayoutBuilder.setPendingVarLayout(
- applyOffsetToVarLayout(
- irBuilder,
- basePendingLayout,
- offsetPendingLayout));
+ applyOffsetToVarLayout(irBuilder, basePendingLayout, offsetPendingLayout));
}
}
- for( auto baseResInfo : baseLayout->getOffsetAttrs() )
+ for (auto baseResInfo : baseLayout->getOffsetAttrs())
{
auto kind = baseResInfo->getResourceKind();
auto adjustedResInfo = adjustedLayoutBuilder.findOrAddResourceInfo(kind);
adjustedResInfo->offset = baseResInfo->getOffset();
adjustedResInfo->space = baseResInfo->getSpace();
- if( auto offsetResInfo = offsetLayout->findOffsetAttr(baseResInfo->getResourceKind()) )
+ if (auto offsetResInfo = offsetLayout->findOffsetAttr(baseResInfo->getResourceKind()))
{
adjustedResInfo->offset += offsetResInfo->getOffset();
adjustedResInfo->space += offsetResInfo->getSpace();
@@ -2657,23 +2787,23 @@ static bool _usesExistentialData(RefPtr<TypeLayout> typeLayout)
return _usesResourceKind(typeLayout, LayoutResourceKind::ExistentialObjectParam);
}
- /// Add resource usage from `srcTypeLayout` to `dstTypeLayout` unless it would be "masked."
- ///
- /// This function is appropriate for applying resource usage from an element type
- /// to the resource usage of a container like a `ConstantBuffer<X>` or
- /// `ParameterBlock<X>`.
- ///
- /// TODO: letUnformBleedThrough is (hopefully temporary) a hack that was added to enable CPU targets to
- /// produce workable layout. CPU targets have all bindings/variables laid out as uniforms
+/// Add resource usage from `srcTypeLayout` to `dstTypeLayout` unless it would be "masked."
+///
+/// This function is appropriate for applying resource usage from an element type
+/// to the resource usage of a container like a `ConstantBuffer<X>` or
+/// `ParameterBlock<X>`.
+///
+/// TODO: letUnformBleedThrough is (hopefully temporary) a hack that was added to enable CPU targets
+/// to produce workable layout. CPU targets have all bindings/variables laid out as uniforms
static void _addUnmaskedResourceUsage(
- bool letUniformBleedThrough,
+ bool letUniformBleedThrough,
TypeLayout* dstTypeLayout,
TypeLayout* srcTypeLayout,
- bool haveFullRegisterSpaceOrSet)
+ bool haveFullRegisterSpaceOrSet)
{
- for( auto resInfo : srcTypeLayout->resourceInfos )
+ for (auto resInfo : srcTypeLayout->resourceInfos)
{
- switch( resInfo.kind )
+ switch (resInfo.kind)
{
case LayoutResourceKind::Uniform:
// Ordinary/uniform resource usage will always be masked.
@@ -2704,7 +2834,7 @@ static void _addUnmaskedResourceUsage(
// Otherwise, the resource usage of the group must
// include the resource usage of the element.
//
- if( !haveFullRegisterSpaceOrSet )
+ if (!haveFullRegisterSpaceOrSet)
{
dstTypeLayout->addResourceUsage(resInfo);
}
@@ -2714,9 +2844,9 @@ static void _addUnmaskedResourceUsage(
}
static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
- TypeLayoutContext const& context,
- ParameterGroupType* parameterGroupType,
- RefPtr<TypeLayout> rawElementTypeLayout)
+ TypeLayoutContext const& context,
+ ParameterGroupType* parameterGroupType,
+ RefPtr<TypeLayout> rawElementTypeLayout)
{
// We are being asked to create a layout for a parameter group,
// which is curently either a `ParameterBlock<T>` or a `ConstantBuffer<T>`
@@ -2829,12 +2959,11 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// if a wrapping constant buffer is needed based on an element
// type and layout context; we should be using that here.
//
- bool wantConstantBuffer = _usesOrdinaryData(rawElementTypeLayout)
- || _usesExistentialData(rawElementTypeLayout)
- || isCUDATarget(context.targetReq)
- || isCPUTarget(context.targetReq)
- || isMetalTarget(context.targetReq);
- if( wantConstantBuffer )
+ bool wantConstantBuffer = _usesOrdinaryData(rawElementTypeLayout) ||
+ _usesExistentialData(rawElementTypeLayout) ||
+ isCUDATarget(context.targetReq) || isCPUTarget(context.targetReq) ||
+ isMetalTarget(context.targetReq);
+ if (wantConstantBuffer)
{
// If there is any ordinary data, then we'll need to
// allocate a constant buffer or tbuffer (if we have a tbuffer parameter group type)
@@ -2845,7 +2974,8 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
{
parameterKind = ShaderParameterKind::TextureUniformBuffer;
}
- auto bufferUsage = parameterGroupRules->GetObjectLayout(parameterKind, context.objectLayoutOptions);
+ auto bufferUsage =
+ parameterGroupRules->GetObjectLayout(parameterKind, context.objectLayoutOptions);
for (auto layoutInfo : bufferUsage.layoutInfos)
containerTypeLayout->addResourceUsage(layoutInfo.kind, layoutInfo.size);
}
@@ -2864,12 +2994,12 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// is fine because the case will just return null in that case anyway.
//
auto parameterBlockType = as<ParameterBlockType>(parameterGroupType);
- if( parameterBlockType )
+ if (parameterBlockType)
{
// We also can't allocate a `space` or `set` unless the compilation
// target actually supports them.
//
- if( shouldAllocateRegisterSpaceForParameterBlock(context) )
+ if (shouldAllocateRegisterSpaceForParameterBlock(context))
{
canUseSpaceOrSet = true;
}
@@ -2884,7 +3014,7 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// for all such data.
//
bool wantSpaceOrSet = false;
- if( canUseSpaceOrSet )
+ if (canUseSpaceOrSet)
{
// Note that if we are allocating a constant buffer to hold
// some ordinary/uniform (or existential) data then we
@@ -2893,9 +3023,9 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// to special-case that because the loop here will also detect
// the `LayoutResourceKind::Uniform` usage.
- for( auto elementResourceInfo : rawElementTypeLayout->resourceInfos )
+ for (auto elementResourceInfo : rawElementTypeLayout->resourceInfos)
{
- if(elementResourceInfo.kind != LayoutResourceKind::SubElementRegisterSpace)
+ if (elementResourceInfo.kind != LayoutResourceKind::SubElementRegisterSpace)
{
wantSpaceOrSet = true;
break;
@@ -2907,15 +3037,15 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// then we allocate one as part of the overall resource usage for
// the parameter group type.
//
- if( wantSpaceOrSet )
+ if (wantSpaceOrSet)
{
containerTypeLayout->addResourceUsage(LayoutResourceKind::SubElementRegisterSpace, 1);
- // Add a RegisterSpace entry to containerVarLayout to signal that this ParameterGroupTypeLayout
- // initiates a new space for its element. This allows us to distinguish between the ConstantBuffer
- // and ParameterBlock cases. The index of this entry is set to 0 since there is already a
- // SubElementRegisterSpace entry stored in `typeLayout` that corresponds to the space used by
- // this parameter group.
+ // Add a RegisterSpace entry to containerVarLayout to signal that this
+ // ParameterGroupTypeLayout initiates a new space for its element. This allows us to
+ // distinguish between the ConstantBuffer and ParameterBlock cases. The index of this entry
+ // is set to 0 since there is already a SubElementRegisterSpace entry stored in `typeLayout`
+ // that corresponds to the space used by this parameter group.
containerVarLayout->findOrAddResourceInfo(LayoutResourceKind::RegisterSpace);
}
@@ -2924,7 +3054,7 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// let's go ahead and assign the container variable a relative offset
// of zero for each of the kinds of resources that it consumes.
//
- for( auto typeResInfo : containerTypeLayout->resourceInfos )
+ for (auto typeResInfo : containerTypeLayout->resourceInfos)
{
containerVarLayout->findOrAddResourceInfo(typeResInfo.kind);
}
@@ -2933,7 +3063,7 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// first in the overall group, the element needs to have a layout
// such that it comes *after* the container in the relative order.
//
- for( auto elementTypeResInfo : rawElementTypeLayout->resourceInfos )
+ for (auto elementTypeResInfo : rawElementTypeLayout->resourceInfos)
{
auto kind = elementTypeResInfo.kind;
@@ -2952,7 +3082,7 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// as the element type, then the element needs to start at an offset
// after the container.
//
- if( auto containerTypeResInfo = containerTypeLayout->FindResourceInfo(kind) )
+ if (auto containerTypeResInfo = containerTypeLayout->FindResourceInfo(kind))
{
SLANG_RELEASE_ASSERT(containerTypeResInfo->count.isFinite());
elementVarResInfo->index += containerTypeResInfo->count.getFiniteValue();
@@ -3005,7 +3135,7 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// All of this is extra work we only have to do if there is
// "pending" data in the element type layout.
//
- if( auto pendingElementTypeLayout = rawElementTypeLayout->pendingDataTypeLayout )
+ if (auto pendingElementTypeLayout = rawElementTypeLayout->pendingDataTypeLayout)
{
auto rules = rawElementTypeLayout->rules;
@@ -3037,7 +3167,7 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// field in a structure type, after the original data.
//
UniformLayoutInfo uniformLayout = rules->BeginStructLayout();
- if( auto resInfo = rawElementTypeLayout->FindResourceInfo(LayoutResourceKind::Uniform) )
+ if (auto resInfo = rawElementTypeLayout->FindResourceInfo(LayoutResourceKind::Uniform))
{
uniformLayout.alignment = rawElementTypeLayout->uniformAlignment;
uniformLayout.size = resInfo->count;
@@ -3045,9 +3175,9 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// Now we can scan through the resources used by the pending data.
//
- for( auto resInfo : pendingElementTypeLayout->resourceInfos )
+ for (auto resInfo : pendingElementTypeLayout->resourceInfos)
{
- if( resInfo.kind == LayoutResourceKind::Uniform )
+ if (resInfo.kind == LayoutResourceKind::Uniform)
{
// For the ordinary/uniform resource kind, we will add the resource
// usage as if it was a structure field, and then write the resulting
@@ -3055,10 +3185,9 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
//
auto offset = rules->AddStructField(
&uniformLayout,
- UniformLayoutInfo(
- resInfo.count,
- pendingElementTypeLayout->uniformAlignment));
- pendingElementVarLayout->findOrAddResourceInfo(resInfo.kind)->index = offset.getFiniteValue();
+ UniformLayoutInfo(resInfo.count, pendingElementTypeLayout->uniformAlignment));
+ pendingElementVarLayout->findOrAddResourceInfo(resInfo.kind)->index =
+ offset.getFiniteValue();
}
else
{
@@ -3080,7 +3209,11 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// up the hierarchy.
//
RefPtr<TypeLayout> unmaskedPendingDataTypeLayout = new TypeLayout();
- _addUnmaskedResourceUsage(false, unmaskedPendingDataTypeLayout, pendingElementTypeLayout, wantSpaceOrSet);
+ _addUnmaskedResourceUsage(
+ false,
+ unmaskedPendingDataTypeLayout,
+ pendingElementTypeLayout,
+ wantSpaceOrSet);
// TODO: we should probably optimize for the case where there is no unmasked
// usage that needs to be reported out, since it should be a common case.
@@ -3105,20 +3238,20 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// Because the offsets are currently all set to zero, we only
// need to check for case (1).
//
- for( auto pendingVarResInfo : pendingElementVarLayout->resourceInfos )
+ for (auto pendingVarResInfo : pendingElementVarLayout->resourceInfos)
{
auto kind = pendingVarResInfo.kind;
// If we are looking at uniform resource usage, we already
// handled it easlier.
//
- if(kind == LayoutResourceKind::Uniform)
+ if (kind == LayoutResourceKind::Uniform)
continue;
// If the usage is unmasked, the nwe are in case (2) and should
// skip out.
//
- if(unmaskedPendingDataTypeLayout->FindResourceInfo(kind))
+ if (unmaskedPendingDataTypeLayout->FindResourceInfo(kind))
continue;
// Okay, we have resource info for somethign that is going
@@ -3127,18 +3260,18 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// of the same kind.
//
auto existingVarResInfo = elementVarLayout->FindResourceInfo(kind);
- if(!existingVarResInfo)
+ if (!existingVarResInfo)
continue;
auto existingTypeResInfo = elementVarLayout->typeLayout->FindResourceInfo(kind);
- if(!existingTypeResInfo)
+ if (!existingTypeResInfo)
continue;
// TODO: We need a more robust solution than just calling
// `getFiniteValue` here.
//
- pendingVarResInfo.index = existingVarResInfo->index
- + existingTypeResInfo->count.getFiniteValue();
+ pendingVarResInfo.index =
+ existingVarResInfo->index + existingTypeResInfo->count.getFiniteValue();
}
// TODO: we should probably adjust the size reported by the element type
@@ -3174,27 +3307,28 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
// handles `struct` types which are the 99% case for
// parameter blocks.
//
- typeLayout->offsetElementTypeLayout = applyOffsetToTypeLayout(rawElementTypeLayout, elementVarLayout);
+ typeLayout->offsetElementTypeLayout =
+ applyOffsetToTypeLayout(rawElementTypeLayout, elementVarLayout);
return typeLayout;
}
- /// Do we need to wrap the given element type in a constant buffer layout?
+/// Do we need to wrap the given element type in a constant buffer layout?
static bool needsConstantBuffer(
- TypeLayoutContext const& context,
- RefPtr<TypeLayout> elementTypeLayout)
+ TypeLayoutContext const& context,
+ RefPtr<TypeLayout> elementTypeLayout)
{
// We need a constant buffer if the element type has ordinary/uniform data.
//
- if(_usesOrdinaryData(elementTypeLayout))
+ if (_usesOrdinaryData(elementTypeLayout))
return true;
// We also need a constant buffer if there is any "pending"
// data that need ordinary/uniform data allocated to them.
//
- if(auto pendingDataTypeLayout = elementTypeLayout->pendingDataTypeLayout)
+ if (auto pendingDataTypeLayout = elementTypeLayout->pendingDataTypeLayout)
{
- if(_usesOrdinaryData(pendingDataTypeLayout))
+ if (_usesOrdinaryData(pendingDataTypeLayout))
return true;
}
@@ -3203,76 +3337,69 @@ static bool needsConstantBuffer(
// data whatsoever.
//
auto targetReq = context.targetReq;
- if( isCPUTarget(targetReq) || isCUDATarget(targetReq) )
+ if (isCPUTarget(targetReq) || isCUDATarget(targetReq))
return true;
return false;
}
RefPtr<TypeLayout> createConstantBufferTypeLayoutIfNeeded(
- TypeLayoutContext const& context,
- RefPtr<TypeLayout> elementTypeLayout)
+ TypeLayoutContext const& context,
+ RefPtr<TypeLayout> elementTypeLayout)
{
// First things first, we need to check whether the element type
// we are trying to lay out even needs a constant buffer allocated
// for it.
//
- if(!needsConstantBuffer(context, elementTypeLayout))
+ if (!needsConstantBuffer(context, elementTypeLayout))
return elementTypeLayout;
return _createParameterGroupTypeLayout(
- context
- .with(context.targetReq->getOptionSet().getMatrixLayoutMode()),
+ context.with(context.targetReq->getOptionSet().getMatrixLayoutMode()),
nullptr,
elementTypeLayout);
}
static RefPtr<TypeLayout> _createParameterGroupTypeLayout(
- TypeLayoutContext const& context,
- ParameterGroupType* parameterGroupType,
- Type* elementType,
- LayoutRulesImpl* elementTypeRules)
+ TypeLayoutContext const& context,
+ ParameterGroupType* parameterGroupType,
+ Type* elementType,
+ LayoutRulesImpl* elementTypeRules)
{
// We will first compute a layout for the element type of
// the parameter group.
//
- auto elementTypeLayout = createTypeLayoutWith(
- context,
- elementTypeRules,
- elementType);
+ auto elementTypeLayout = createTypeLayoutWith(context, elementTypeRules, elementType);
// Now we delegate to a routine that does the meat of
// the complicated layout logic.
//
- return _createParameterGroupTypeLayout(
- context,
- parameterGroupType,
- elementTypeLayout);
+ return _createParameterGroupTypeLayout(context, parameterGroupType, elementTypeLayout);
}
LayoutRulesImpl* getParameterBufferElementTypeLayoutRules(
- ParameterGroupType* parameterGroupType,
- LayoutRulesImpl* rules,
- CompilerOptionSet& compilerOptions)
+ ParameterGroupType* parameterGroupType,
+ LayoutRulesImpl* rules,
+ CompilerOptionSet& compilerOptions)
{
- if( as<ConstantBufferType>(parameterGroupType) )
+ if (as<ConstantBufferType>(parameterGroupType))
{
return rules->getLayoutRulesFamily()->getConstantBufferRules(compilerOptions);
}
- else if( as<TextureBufferType>(parameterGroupType) )
+ else if (as<TextureBufferType>(parameterGroupType))
{
return rules->getLayoutRulesFamily()->getTextureBufferRules(compilerOptions);
}
- else if( as<GLSLInputParameterGroupType>(parameterGroupType) )
+ else if (as<GLSLInputParameterGroupType>(parameterGroupType))
{
return rules->getLayoutRulesFamily()->getVaryingInputRules();
}
- else if( as<GLSLOutputParameterGroupType>(parameterGroupType) )
+ else if (as<GLSLOutputParameterGroupType>(parameterGroupType))
{
return rules->getLayoutRulesFamily()->getVaryingOutputRules();
}
- else if( as<GLSLShaderStorageBufferType>(parameterGroupType) )
+ else if (as<GLSLShaderStorageBufferType>(parameterGroupType))
{
return rules->getLayoutRulesFamily()->getShaderStorageBufferRules(compilerOptions);
}
@@ -3283,13 +3410,13 @@ LayoutRulesImpl* getParameterBufferElementTypeLayoutRules(
else
{
SLANG_UNEXPECTED("uhandled parameter block type");
- //return nullptr;
+ // return nullptr;
}
}
RefPtr<TypeLayout> createParameterGroupTypeLayout(
- TypeLayoutContext const& context,
- ParameterGroupType* parameterGroupType)
+ TypeLayoutContext const& context,
+ ParameterGroupType* parameterGroupType)
{
auto parameterGroupRules = context.rules;
@@ -3309,34 +3436,35 @@ RefPtr<TypeLayout> createParameterGroupTypeLayout(
}
// Create a type layout for a structured buffer type with an associated counter
-RefPtr<StructuredBufferTypeLayout>
-createStructuredBufferWithCounterTypeLayout(
+RefPtr<StructuredBufferTypeLayout> createStructuredBufferWithCounterTypeLayout(
TypeLayoutContext const& context,
ShaderParameterKind kind,
Type* structuredBufferType,
RefPtr<TypeLayout> elementTypeLayout)
{
- auto typeLayout = createStructuredBufferTypeLayout(context, kind, structuredBufferType, elementTypeLayout);
+ auto typeLayout =
+ createStructuredBufferTypeLayout(context, kind, structuredBufferType, elementTypeLayout);
- const auto structuredBufferLayoutRules = context.getRulesFamily()->getStructuredBufferRules(context.targetReq->getOptionSet());
+ const auto structuredBufferLayoutRules =
+ context.getRulesFamily()->getStructuredBufferRules(context.targetReq->getOptionSet());
const auto counterType = context.astBuilder->getIntType();
const auto counterBufferType = context.astBuilder->getRWStructuredBufferType(counterType);
- const auto counterTypeLayout = createTypeLayoutWith(context, structuredBufferLayoutRules, counterBufferType);
+ const auto counterTypeLayout =
+ createTypeLayoutWith(context, structuredBufferLayoutRules, counterBufferType);
const auto counterVarDecl = context.astBuilder->create<VarDecl>();
counterVarDecl->type.type = counterBufferType;
counterVarDecl->nameAndLoc.name =
- context.astBuilder->getSharedASTBuilder()->getNamePool()->getName("counter");
+ context.astBuilder->getSharedASTBuilder()->getNamePool()->getName("counter");
RefPtr<VarLayout> counterVarLayout = new VarLayout();
counterVarLayout->varDecl = makeDeclRef(counterVarDecl);
counterVarLayout->typeLayout = counterTypeLayout;
- for(auto& typeResourceInfo : typeLayout->resourceInfos)
+ for (auto& typeResourceInfo : typeLayout->resourceInfos)
{
- auto counterResourceInfo
- = counterVarLayout->findOrAddResourceInfo(typeResourceInfo.kind);
+ auto counterResourceInfo = counterVarLayout->findOrAddResourceInfo(typeResourceInfo.kind);
// We expect this index to be 1
counterResourceInfo->index = typeResourceInfo.count.getFiniteValue();
}
@@ -3348,12 +3476,11 @@ createStructuredBufferWithCounterTypeLayout(
}
// Create a type layout for a structured buffer type.
-RefPtr<StructuredBufferTypeLayout>
-createStructuredBufferTypeLayout(
- TypeLayoutContext const& context,
- ShaderParameterKind kind,
- Type* structuredBufferType,
- RefPtr<TypeLayout> elementTypeLayout)
+RefPtr<StructuredBufferTypeLayout> createStructuredBufferTypeLayout(
+ TypeLayoutContext const& context,
+ ShaderParameterKind kind,
+ Type* structuredBufferType,
+ RefPtr<TypeLayout> elementTypeLayout)
{
auto rules = context.rules;
auto info = rules->GetObjectLayout(kind, context.objectLayoutOptions).getSimple();
@@ -3366,19 +3493,21 @@ createStructuredBufferTypeLayout(
typeLayout->elementTypeLayout = elementTypeLayout;
typeLayout->uniformAlignment = info.alignment;
-
- if( info.size != 0 )
+
+ if (info.size != 0)
{
typeLayout->addResourceUsage(info.kind, info.size);
}
// If element type contains existential type params and object params,
// we need to propagate them through the StructuredBufferLayout.
- if (auto existentialTypeInfo = elementTypeLayout->FindResourceInfo(LayoutResourceKind::ExistentialTypeParam))
+ if (auto existentialTypeInfo =
+ elementTypeLayout->FindResourceInfo(LayoutResourceKind::ExistentialTypeParam))
{
typeLayout->addResourceUsage(existentialTypeInfo->kind, existentialTypeInfo->count);
}
- if (auto existentialObjInfo = elementTypeLayout->FindResourceInfo(LayoutResourceKind::ExistentialObjectParam))
+ if (auto existentialObjInfo =
+ elementTypeLayout->FindResourceInfo(LayoutResourceKind::ExistentialObjectParam))
{
typeLayout->addResourceUsage(existentialObjInfo->kind, existentialObjInfo->count);
}
@@ -3391,31 +3520,28 @@ createStructuredBufferTypeLayout(
}
// Create a type layout for a structured buffer type.
-RefPtr<StructuredBufferTypeLayout>
-createStructuredBufferTypeLayout(
- TypeLayoutContext const& context,
- ShaderParameterKind kind,
- Type* structuredBufferType,
- Type* elementType)
+RefPtr<StructuredBufferTypeLayout> createStructuredBufferTypeLayout(
+ TypeLayoutContext const& context,
+ ShaderParameterKind kind,
+ Type* structuredBufferType,
+ Type* elementType)
{
- // look up the appropriate rules via the `LayoutRulesFamily`
- auto structuredBufferLayoutRules = context.getRulesFamily()->getStructuredBufferRules(context.targetReq->getOptionSet());
+ // look up the appropriate rules via the `LayoutRulesFamily`
+ auto structuredBufferLayoutRules =
+ context.getRulesFamily()->getStructuredBufferRules(context.targetReq->getOptionSet());
// Create and save type layout for the buffer contents.
- auto elementTypeLayout = createTypeLayoutWith(
- context,
- structuredBufferLayoutRules,
- elementType);
+ auto elementTypeLayout =
+ createTypeLayoutWith(context, structuredBufferLayoutRules, elementType);
- if(kind == ShaderParameterKind::AppendConsumeStructuredBuffer
- && structuredBufferLayoutRules->DoStructuredBuffersNeedSeparateCounterBuffer())
+ if (kind == ShaderParameterKind::AppendConsumeStructuredBuffer &&
+ structuredBufferLayoutRules->DoStructuredBuffersNeedSeparateCounterBuffer())
{
return createStructuredBufferWithCounterTypeLayout(
context,
kind,
structuredBufferType,
- elementTypeLayout
- );
+ elementTypeLayout);
}
else
{
@@ -3427,25 +3553,24 @@ createStructuredBufferTypeLayout(
}
}
- /// Create layout information for the given `type`.
- ///
- /// This internal routine returns both the constructed type
- /// layout object and the simple layout info, encapsulated
- /// together as a `TypeLayoutResult`.
- ///
-static TypeLayoutResult _createTypeLayout(
- TypeLayoutContext& context,
- Type* type);
-
- /// Create layout information for the given `type`, obeying any layout modifiers on the given declaration.
- ///
- /// If `declForModifiers` has any matrix layout modifiers associated with it, then
- /// the resulting type layout will respect those modifiers.
- ///
+/// Create layout information for the given `type`.
+///
+/// This internal routine returns both the constructed type
+/// layout object and the simple layout info, encapsulated
+/// together as a `TypeLayoutResult`.
+///
+static TypeLayoutResult _createTypeLayout(TypeLayoutContext& context, Type* type);
+
+/// Create layout information for the given `type`, obeying any layout modifiers on the given
+/// declaration.
+///
+/// If `declForModifiers` has any matrix layout modifiers associated with it, then
+/// the resulting type layout will respect those modifiers.
+///
static TypeLayoutResult _createTypeLayout(
- TypeLayoutContext const& context,
- Type* type,
- Decl* declForModifiers)
+ TypeLayoutContext const& context,
+ Type* type,
+ Decl* declForModifiers)
{
TypeLayoutContext subContext = context;
@@ -3459,25 +3584,23 @@ static TypeLayoutResult _createTypeLayout(
}
Type* findGlobalGenericSpecializationArg(
- TypeLayoutContext const& context,
- GlobalGenericParamDecl* decl)
+ TypeLayoutContext const& context,
+ GlobalGenericParamDecl* decl)
{
Val* arg = nullptr;
context.programLayout->globalGenericArgs.tryGetValue(decl, arg);
return as<Type>(arg);
}
-Index findGlobalGenericSpecializationParamIndex(
- ComponentType* type,
- GlobalGenericParamDecl* decl)
+Index findGlobalGenericSpecializationParamIndex(ComponentType* type, GlobalGenericParamDecl* decl)
{
Index paramCount = type->getSpecializationParamCount();
- for( Index pp = 0; pp < paramCount; ++pp )
+ for (Index pp = 0; pp < paramCount; ++pp)
{
auto param = type->getSpecializationParam(pp);
- if(param.flavor != SpecializationParam::Flavor::GenericType)
+ if (param.flavor != SpecializationParam::Flavor::GenericType)
continue;
- if(param.object != decl)
+ if (param.object != decl)
continue;
return pp;
@@ -3487,9 +3610,7 @@ Index findGlobalGenericSpecializationParamIndex(
// When constructing a new var layout from an existing one,
// copy fields to the new var from the old.
-void copyVarLayoutFields(
- VarLayout* dstVarLayout,
- VarLayout* srcVarLayout)
+void copyVarLayoutFields(VarLayout* dstVarLayout, VarLayout* srcVarLayout)
{
dstVarLayout->varDecl = srcVarLayout->varDecl;
dstVarLayout->typeLayout = srcVarLayout->typeLayout;
@@ -3504,9 +3625,7 @@ void copyVarLayoutFields(
// When constructing a new type layout from an existing one,
// copy fields to the new type from the old.
-void copyTypeLayoutFields(
- TypeLayout* dstTypeLayout,
- TypeLayout* srcTypeLayout)
+void copyTypeLayoutFields(TypeLayout* dstTypeLayout, TypeLayout* srcTypeLayout)
{
dstTypeLayout->type = srcTypeLayout->type;
dstTypeLayout->rules = srcTypeLayout->rules;
@@ -3518,16 +3637,14 @@ void copyTypeLayoutFields(
// an array-of-structs fashion?
bool doesResourceRequireAdjustmentForArrayOfStructs(LayoutResourceKind kind)
{
- switch( kind )
+ switch (kind)
{
case LayoutResourceKind::ConstantBuffer:
case LayoutResourceKind::ShaderResource:
case LayoutResourceKind::UnorderedAccess:
- case LayoutResourceKind::SamplerState:
- return true;
+ case LayoutResourceKind::SamplerState: return true;
- default:
- return false;
+ default: return false;
}
}
@@ -3565,9 +3682,9 @@ bool doesResourceRequireAdjustmentForArrayOfStructs(LayoutResourceKind kind)
// than `register(t1)`.
//
static RefPtr<TypeLayout> maybeAdjustLayoutForArrayElementType(
- RefPtr<TypeLayout> originalTypeLayout,
- LayoutSize elementCount,
- UInt& ioAdditionalSpacesNeeded)
+ RefPtr<TypeLayout> originalTypeLayout,
+ LayoutSize elementCount,
+ UInt& ioAdditionalSpacesNeeded)
{
// We will start by looking for cases that we can reject out
// of hand.
@@ -3575,21 +3692,21 @@ static RefPtr<TypeLayout> maybeAdjustLayoutForArrayElementType(
// If the original element type layout doesn't use any
// resource registers, then we are fine.
bool anyResource = false;
- for( auto resInfo : originalTypeLayout->resourceInfos )
+ for (auto resInfo : originalTypeLayout->resourceInfos)
{
- if( doesResourceRequireAdjustmentForArrayOfStructs(resInfo.kind) )
+ if (doesResourceRequireAdjustmentForArrayOfStructs(resInfo.kind))
{
anyResource = true;
break;
}
}
- if(!anyResource)
+ if (!anyResource)
return originalTypeLayout;
// Let's look at the type layout we have, and see if there is anything
// that we need to do with it.
//
- if( auto originalArrayTypeLayout = originalTypeLayout.as<ArrayTypeLayout>() )
+ if (auto originalArrayTypeLayout = originalTypeLayout.as<ArrayTypeLayout>())
{
// The element type is itself an array, so we'll need to adjust
// *its* element type accordingly.
@@ -3604,7 +3721,7 @@ static RefPtr<TypeLayout> maybeAdjustLayoutForArrayElementType(
// If nothing needed to be changed on the inner element type,
// then we are done.
- if(adjustedInnerElementTypeLayout == originalInnerElementTypeLayout)
+ if (adjustedInnerElementTypeLayout == originalInnerElementTypeLayout)
return originalTypeLayout;
// Otherwise, we need to construct a new array type layout
@@ -3617,9 +3734,11 @@ static RefPtr<TypeLayout> maybeAdjustLayoutForArrayElementType(
return adjustedArrayTypeLayout;
}
- else if(auto originalParameterGroupTypeLayout = originalTypeLayout.as<ParameterGroupTypeLayout>() )
+ else if (
+ auto originalParameterGroupTypeLayout = originalTypeLayout.as<ParameterGroupTypeLayout>())
{
- auto originalInnerElementTypeLayout = originalParameterGroupTypeLayout->elementVarLayout->typeLayout;
+ auto originalInnerElementTypeLayout =
+ originalParameterGroupTypeLayout->elementVarLayout->typeLayout;
auto adjustedInnerElementTypeLayout = maybeAdjustLayoutForArrayElementType(
originalInnerElementTypeLayout,
elementCount,
@@ -3636,12 +3755,12 @@ static RefPtr<TypeLayout> maybeAdjustLayoutForArrayElementType(
SLANG_UNIMPLEMENTED_X("array of parameter group");
UNREACHABLE_RETURN(originalTypeLayout);
}
- else if(auto originalStructTypeLayout = originalTypeLayout.as<StructTypeLayout>() )
+ else if (auto originalStructTypeLayout = originalTypeLayout.as<StructTypeLayout>())
{
Index fieldCount = originalStructTypeLayout->fields.getCount();
// Empty struct? Bail out.
- if(fieldCount == 0)
+ if (fieldCount == 0)
return originalTypeLayout;
RefPtr<StructTypeLayout> adjustedStructTypeLayout = new StructTypeLayout();
@@ -3654,12 +3773,13 @@ static RefPtr<TypeLayout> maybeAdjustLayoutForArrayElementType(
LayoutSize nextSpaceIndex = 0;
Dictionary<RefPtr<VarLayout>, RefPtr<VarLayout>> mapOriginalFieldToAdjusted;
- for( auto originalField : originalStructTypeLayout->fields )
+ for (auto originalField : originalStructTypeLayout->fields)
{
auto originalFieldTypeLayout = originalField->typeLayout;
LayoutSize originalFieldSpaceCount = 0;
- if(auto resInfo = originalFieldTypeLayout->FindResourceInfo(LayoutResourceKind::SubElementRegisterSpace))
+ if (auto resInfo = originalFieldTypeLayout->FindResourceInfo(
+ LayoutResourceKind::SubElementRegisterSpace))
originalFieldSpaceCount = resInfo->count;
// Compute the adjusted type for the field
@@ -3688,11 +3808,11 @@ static RefPtr<TypeLayout> maybeAdjustLayoutForArrayElementType(
// to do with it all.
//
bool requireNewSpace = false;
- for(auto& resInfo : adjustedField->resourceInfos )
+ for (auto& resInfo : adjustedField->resourceInfos)
{
- if( doesResourceRequireAdjustmentForArrayOfStructs(resInfo.kind) )
+ if (doesResourceRequireAdjustmentForArrayOfStructs(resInfo.kind))
{
- if(elementCount.isFinite())
+ if (elementCount.isFinite())
{
// If the array size is finite, then the field's index/offset
// is just going to be strided by the array size since we
@@ -3714,7 +3834,8 @@ static RefPtr<TypeLayout> maybeAdjustLayoutForArrayElementType(
}
if (requireNewSpace)
{
- adjustedField->findOrAddResourceInfo(LayoutResourceKind::RegisterSpace)->index = spaceOffsetForField.getFiniteValue();
+ adjustedField->findOrAddResourceInfo(LayoutResourceKind::RegisterSpace)->index =
+ spaceOffsetForField.getFiniteValue();
}
adjustedStructTypeLayout->fields.add(adjustedField);
@@ -3722,10 +3843,10 @@ static RefPtr<TypeLayout> maybeAdjustLayoutForArrayElementType(
mapOriginalFieldToAdjusted.add(originalField, adjustedField);
}
- for( auto [key, originalVal] : originalStructTypeLayout->mapVarToLayout )
+ for (auto [key, originalVal] : originalStructTypeLayout->mapVarToLayout)
{
RefPtr<VarLayout> adjustedVal;
- if( mapOriginalFieldToAdjusted.tryGetValue(originalVal, adjustedVal) )
+ if (mapOriginalFieldToAdjusted.tryGetValue(originalVal, adjustedVal))
{
adjustedStructTypeLayout->mapVarToLayout.add(key, adjustedVal);
}
@@ -3740,7 +3861,7 @@ static RefPtr<TypeLayout> maybeAdjustLayoutForArrayElementType(
// with, we can just return the type layout as-is, but we also want
// to make a note that this value should consume an additional register
// space *if* the element count is unbounded.
- if( elementCount.isInfinite() )
+ if (elementCount.isInfinite())
{
ioAdditionalSpacesNeeded++;
}
@@ -3749,11 +3870,11 @@ static RefPtr<TypeLayout> maybeAdjustLayoutForArrayElementType(
}
}
- /// Convert a `TypeLayout` to a `TypeLayoutResult`
- ///
- /// A `TypeLayout` holds all the data needed to make a `TypeLayoutResult` in practice,
- /// but sometimes it is more convenient to have the data split out.
- ///
+/// Convert a `TypeLayout` to a `TypeLayoutResult`
+///
+/// A `TypeLayout` holds all the data needed to make a `TypeLayoutResult` in practice,
+/// but sometimes it is more convenient to have the data split out.
+///
TypeLayoutResult makeTypeLayoutResult(RefPtr<TypeLayout> typeLayout)
{
TypeLayoutResult result;
@@ -3762,10 +3883,10 @@ TypeLayoutResult makeTypeLayoutResult(RefPtr<TypeLayout> typeLayout)
// If the type only consumes a single kind of non-uniform resource,
// we can fill in the `info` field directly.
//
- if( typeLayout->resourceInfos.getCount() == 1 )
+ if (typeLayout->resourceInfos.getCount() == 1)
{
auto resInfo = typeLayout->resourceInfos[0];
- if( resInfo.kind != LayoutResourceKind::Uniform )
+ if (resInfo.kind != LayoutResourceKind::Uniform)
{
result.info.kind = resInfo.kind;
result.info.size = resInfo.count;
@@ -3776,7 +3897,7 @@ TypeLayoutResult makeTypeLayoutResult(RefPtr<TypeLayout> typeLayout)
// Otherwise, we will fill out the info based on the uniform
// resources consumed, if any.
//
- if( auto resInfo = typeLayout->FindResourceInfo(LayoutResourceKind::Uniform) )
+ if (auto resInfo = typeLayout->FindResourceInfo(LayoutResourceKind::Uniform))
{
result.info.kind = LayoutResourceKind::Uniform;
result.info.alignment = typeLayout->uniformAlignment;
@@ -3799,9 +3920,7 @@ TypeLayoutResult makeTypeLayoutResult(RefPtr<TypeLayout> typeLayout)
// StructTypeLayoutBuilder
//
-void StructTypeLayoutBuilder::beginLayout(
- Type* type,
- LayoutRulesImpl* rules)
+void StructTypeLayoutBuilder::beginLayout(Type* type, LayoutRulesImpl* rules)
{
m_rules = rules;
@@ -3812,19 +3931,17 @@ void StructTypeLayoutBuilder::beginLayout(
m_info = m_rules->BeginStructLayout();
}
-void StructTypeLayoutBuilder::beginLayoutIfNeeded(
- Type* type,
- LayoutRulesImpl* rules)
+void StructTypeLayoutBuilder::beginLayoutIfNeeded(Type* type, LayoutRulesImpl* rules)
{
- if( !m_typeLayout )
+ if (!m_typeLayout)
{
beginLayout(type, rules);
}
}
RefPtr<VarLayout> StructTypeLayoutBuilder::addField(
- DeclRef<Decl> field,
- TypeLayoutResult fieldResult)
+ DeclRef<Decl> field,
+ TypeLayoutResult fieldResult)
{
SLANG_ASSERT(m_typeLayout);
@@ -3851,7 +3968,7 @@ RefPtr<VarLayout> StructTypeLayoutBuilder::addField(
fieldInfo.size = uniformUsage->count;
}
}
- if(fieldInfo.size != 0)
+ if (fieldInfo.size != 0)
{
uniformOffset = m_rules->AddStructField(&m_info, fieldInfo);
}
@@ -3864,22 +3981,23 @@ RefPtr<VarLayout> StructTypeLayoutBuilder::addField(
fieldLayout->typeLayout = fieldTypeLayout;
m_typeLayout->fields.add(fieldLayout);
- if( field )
+ if (field)
{
m_typeLayout->mapVarToLayout.add(field.getDecl(), fieldLayout);
}
// Set up uniform offset information, if there is any uniform data in the field
- if( fieldTypeLayout->FindResourceInfo(LayoutResourceKind::Uniform) )
+ if (fieldTypeLayout->FindResourceInfo(LayoutResourceKind::Uniform))
{
- fieldLayout->AddResourceInfo(LayoutResourceKind::Uniform)->index = uniformOffset.getFiniteValue();
+ fieldLayout->AddResourceInfo(LayoutResourceKind::Uniform)->index =
+ uniformOffset.getFiniteValue();
}
// Add offset information for any other resource kinds
- for( auto fieldTypeResourceInfo : fieldTypeLayout->resourceInfos )
+ for (auto fieldTypeResourceInfo : fieldTypeLayout->resourceInfos)
{
// Uniforms were dealt with above
- if(fieldTypeResourceInfo.kind == LayoutResourceKind::Uniform)
+ if (fieldTypeResourceInfo.kind == LayoutResourceKind::Uniform)
continue;
// We should not have already processed this resource type
@@ -3896,20 +4014,22 @@ RefPtr<VarLayout> StructTypeLayoutBuilder::addField(
// We handle this case by allocating a distinct register space for
// any field that consumes an unbounded amount of registers.
//
- if( fieldTypeResourceInfo.count.isInfinite() )
+ if (fieldTypeResourceInfo.count.isInfinite())
{
// We need to add one register space to own the storage for this field.
//
- auto structTypeSpaceResourceInfo = m_typeLayout->findOrAddResourceInfo(LayoutResourceKind::SubElementRegisterSpace);
+ auto structTypeSpaceResourceInfo =
+ m_typeLayout->findOrAddResourceInfo(LayoutResourceKind::SubElementRegisterSpace);
auto spaceOffset = structTypeSpaceResourceInfo->count;
structTypeSpaceResourceInfo->count += 1;
-
+
// The field itself will record itself as having a zero offset into
// the chosen space. We encode the space offset as a separate RegisterSpace
- // entry in the field layout so consuming code can use the existance of RegisterSpace entry
- // to tell that the field is introducing a new space for itself.
+ // entry in the field layout so consuming code can use the existance of RegisterSpace
+ // entry to tell that the field is introducing a new space for itself.
//
- fieldLayout->findOrAddResourceInfo(LayoutResourceKind::RegisterSpace)->index = spaceOffset.getFiniteValue();
+ fieldLayout->findOrAddResourceInfo(LayoutResourceKind::RegisterSpace)->index =
+ spaceOffset.getFiniteValue();
fieldResourceInfo->space = 0;
fieldResourceInfo->index = 0;
}
@@ -3920,13 +4040,15 @@ RefPtr<VarLayout> StructTypeLayoutBuilder::addField(
// so far, and then increment the number of slots consumed by the
// `struct` type itself.
//
- auto structTypeResourceInfo = m_typeLayout->findOrAddResourceInfo(fieldTypeResourceInfo.kind);
+ auto structTypeResourceInfo =
+ m_typeLayout->findOrAddResourceInfo(fieldTypeResourceInfo.kind);
fieldResourceInfo->index = structTypeResourceInfo->count.getFiniteValue();
structTypeResourceInfo->count += fieldTypeResourceInfo.count;
if (fieldTypeResourceInfo.kind == LayoutResourceKind::SubElementRegisterSpace &&
canTypeDirectlyUseRegisterSpace(fieldTypeLayout))
{
- fieldLayout->findOrAddResourceInfo(LayoutResourceKind::RegisterSpace)->index = fieldResourceInfo->index;
+ fieldLayout->findOrAddResourceInfo(LayoutResourceKind::RegisterSpace)->index =
+ fieldResourceInfo->index;
}
}
}
@@ -3934,7 +4056,9 @@ RefPtr<VarLayout> StructTypeLayoutBuilder::addField(
return fieldLayout;
}
-RefPtr<VarLayout> StructTypeLayoutBuilder::addExplicitUniformField(DeclRef<VarDeclBase> field, TypeLayoutResult fieldResult)
+RefPtr<VarLayout> StructTypeLayoutBuilder::addExplicitUniformField(
+ DeclRef<VarDeclBase> field,
+ TypeLayoutResult fieldResult)
{
auto packoffsetModifier = field.getDecl()->findModifier<HLSLPackOffsetSemantic>();
if (!packoffsetModifier)
@@ -3959,13 +4083,14 @@ RefPtr<VarLayout> StructTypeLayoutBuilder::addExplicitUniformField(DeclRef<VarDe
m_info.alignment = uniformInfo.alignment;
m_info.size.raw = Math::Max(
m_info.size.getFiniteValue(),
- (size_t)(uniformOffset + fieldResult.layout->FindResourceInfo(LayoutResourceKind::Uniform)->count.getFiniteValue()));
+ (size_t)(uniformOffset + fieldResult.layout->FindResourceInfo(LayoutResourceKind::Uniform)
+ ->count.getFiniteValue()));
return fieldLayout;
}
RefPtr<VarLayout> StructTypeLayoutBuilder::addField(
- DeclRef<VarDeclBase> field,
- RefPtr<TypeLayout> fieldTypeLayout)
+ DeclRef<VarDeclBase> field,
+ RefPtr<TypeLayout> fieldTypeLayout)
{
TypeLayoutResult fieldResult = makeTypeLayoutResult(fieldTypeLayout);
return addField(field, fieldResult);
@@ -3973,7 +4098,8 @@ RefPtr<VarLayout> StructTypeLayoutBuilder::addField(
void StructTypeLayoutBuilder::endLayout()
{
- if(!m_typeLayout) return;
+ if (!m_typeLayout)
+ return;
m_rules->EndStructLayout(&m_info);
@@ -3992,9 +4118,9 @@ TypeLayoutResult StructTypeLayoutBuilder::getTypeLayoutResult()
}
static TypeLayoutResult _createTypeLayoutForGlobalGenericTypeParam(
- TypeLayoutContext const& context,
- Type* type,
- GlobalGenericParamDecl* globalGenericParamDecl)
+ TypeLayoutContext const& context,
+ Type* type,
+ GlobalGenericParamDecl* globalGenericParamDecl)
{
SimpleLayoutInfo info;
info.alignment = 0;
@@ -4015,16 +4141,14 @@ static TypeLayoutResult _createTypeLayoutForGlobalGenericTypeParam(
}
RefPtr<TypeLayout> createTypeLayoutForGlobalGenericTypeParam(
- TypeLayoutContext const& context,
- Type* type,
- GlobalGenericParamDecl* globalGenericParamDecl)
+ TypeLayoutContext const& context,
+ Type* type,
+ GlobalGenericParamDecl* globalGenericParamDecl)
{
return _createTypeLayoutForGlobalGenericTypeParam(context, type, globalGenericParamDecl).layout;
}
-static bool _isDescriptorSlotLike(
- TypeLayoutContext const& context,
- LayoutResourceKind kind)
+static bool _isDescriptorSlotLike(TypeLayoutContext const& context, LayoutResourceKind kind)
{
if (kind == LayoutResourceKind::DescriptorTableSlot)
{
@@ -4035,8 +4159,9 @@ static bool _isDescriptorSlotLike(
{
const auto hlslToVulkanKind = HLSLToVulkanLayoutOptions::getKind(kind);
// If it maps to a kind and it is enabled it is 'in effect' a Descriptor slot
- return hlslToVulkanKind != HLSLToVulkanLayoutOptions::Kind::Invalid &&
- (context.objectLayoutOptions.hlslToVulkanKindFlags & HLSLToVulkanLayoutOptions::getKindFlag(hlslToVulkanKind));
+ return hlslToVulkanKind != HLSLToVulkanLayoutOptions::Kind::Invalid &&
+ (context.objectLayoutOptions.hlslToVulkanKindFlags &
+ HLSLToVulkanLayoutOptions::getKindFlag(hlslToVulkanKind));
}
return false;
@@ -4046,14 +4171,11 @@ static TypeLayoutResult createArrayLikeTypeLayout(
TypeLayoutContext& context,
Type* type,
Type* baseType,
- IntVal* arrayLength
- )
+ IntVal* arrayLength)
{
auto rules = context.rules;
- auto elementResult = _createTypeLayout(
- context,
- baseType);
+ auto elementResult = _createTypeLayout(context, baseType);
auto elementInfo = elementResult.info;
auto elementTypeLayout = elementResult.layout;
@@ -4078,9 +4200,7 @@ static TypeLayoutResult createArrayLikeTypeLayout(
// support unbounded types.
//
- auto arrayUniformInfo = rules->GetArrayLayout(
- elementInfo,
- elementCount).getUniformLayout();
+ auto arrayUniformInfo = rules->GetArrayLayout(elementInfo, elementCount).getUniformLayout();
RefPtr<ArrayTypeLayout> typeLayout = new ArrayTypeLayout();
@@ -4128,16 +4248,16 @@ static TypeLayoutResult createArrayLikeTypeLayout(
// type to compute how they contribute to the resource usage
// of the overall array type.
//
- for( auto elementResourceInfo : elementTypeLayout->resourceInfos )
+ for (auto elementResourceInfo : elementTypeLayout->resourceInfos)
{
// The uniform case was already handled above
- if( elementResourceInfo.kind == LayoutResourceKind::Uniform )
+ if (elementResourceInfo.kind == LayoutResourceKind::Uniform)
continue;
LayoutSize arrayResourceCount = 0;
// We copy because if the element is *actually* DescriptorSlot like,
- // we'll change the type.
+ // we'll change the type.
// NOTE! That as it stands this will change the resource type from an HLSL type
// to Descriptor slot. This scenario happens when we have HLSLToVulkanLayoutOptions
// enabled, we layout with some HLSL types.
@@ -4174,10 +4294,9 @@ static TypeLayoutResult createArrayLikeTypeLayout(
// so that this logic doesn't trigger and we instead handle it with
// the default logic below.
//
- else if(
- elementCount.isInfinite()
- && adjustedElementTypeLayout != elementTypeLayout
- && doesResourceRequireAdjustmentForArrayOfStructs(elementResourceKind) )
+ else if (
+ elementCount.isInfinite() && adjustedElementTypeLayout != elementTypeLayout &&
+ doesResourceRequireAdjustmentForArrayOfStructs(elementResourceKind))
{
// We want to ignore resource types consumed by the element type
// that need adjustement if the array size is infinite, since
@@ -4193,9 +4312,7 @@ static TypeLayoutResult createArrayLikeTypeLayout(
// should contribute to the resource usage of the array, we can
// add in that resource usage.
//
- typeLayout->addResourceUsage(
- elementResourceInfo.kind,
- arrayResourceCount);
+ typeLayout->addResourceUsage(elementResourceInfo.kind, arrayResourceCount);
}
// The loop above to compute the resource usage of the array from its
@@ -4206,31 +4323,30 @@ static TypeLayoutResult createArrayLikeTypeLayout(
// if we skipped them as part of the loop (which happens when
// we detect that the element type layout had been "adjusted").
//
- if( adjustedElementTypeLayout != elementTypeLayout )
+ if (adjustedElementTypeLayout != elementTypeLayout)
{
- typeLayout->addResourceUsage(LayoutResourceKind::SubElementRegisterSpace, additionalSpacesNeededForAdjustedElementType);
+ typeLayout->addResourceUsage(
+ LayoutResourceKind::SubElementRegisterSpace,
+ additionalSpacesNeededForAdjustedElementType);
}
return TypeLayoutResult(typeLayout, arrayUniformInfo);
}
-static void _addLayout(TypeLayoutContext& context,
- Type* type,
- TypeLayout* layout)
+static void _addLayout(TypeLayoutContext& context, Type* type, TypeLayout* layout)
{
// Add it *without info*.
// The info can be added with _updateLayout
context.layoutMap.set(type, TypeLayoutResult(layout, SimpleLayoutInfo()));
}
-static void _addLayout(TypeLayoutContext& context,
- Type* type,
- const TypeLayoutResult& result)
+static void _addLayout(TypeLayoutContext& context, Type* type, const TypeLayoutResult& result)
{
context.layoutMap[type] = result;
}
-static TypeLayoutResult _updateLayout(TypeLayoutContext& context,
+static TypeLayoutResult _updateLayout(
+ TypeLayoutContext& context,
Type* type,
const TypeLayoutResult& result)
{
@@ -4247,13 +4363,11 @@ static TypeLayoutResult _updateLayout(TypeLayoutContext& context,
return result;
}
-static TypeLayoutResult _createTypeLayout(
- TypeLayoutContext& context,
- Type* type)
+static TypeLayoutResult _createTypeLayout(TypeLayoutContext& context, Type* type)
{
if (auto layoutResultPtr = context.layoutMap.tryGetValue(type))
{
- return *layoutResultPtr;
+ return *layoutResultPtr;
}
auto rules = context.rules;
@@ -4278,29 +4392,27 @@ static TypeLayoutResult _createTypeLayout(
// the constant buffer, which need to be surfaced out
// to the top level.
//
- auto typeLayout = createParameterGroupTypeLayout(
- context,
- parameterGroupType);
+ auto typeLayout = createParameterGroupTypeLayout(context, parameterGroupType);
return TypeLayoutResult(typeLayout, info);
}
else if (const auto samplerStateType = as<SamplerStateType>(type))
{
return createSimpleTypeLayout(
- rules->GetObjectLayout(ShaderParameterKind::SamplerState, context.objectLayoutOptions).getSimple(),
+ rules->GetObjectLayout(ShaderParameterKind::SamplerState, context.objectLayoutOptions)
+ .getSimple(),
type,
rules);
}
else if (as<SubpassInputType>(type))
{
// SubpassInputType fills 2 slots, 'shader resource' and 'input_attachment_index'
- auto objLayout1 = rules->GetObjectLayout(ShaderParameterKind::Texture, context.objectLayoutOptions);
- auto objLayout2 = rules->GetObjectLayout(ShaderParameterKind::SubpassInput, context.objectLayoutOptions);
+ auto objLayout1 =
+ rules->GetObjectLayout(ShaderParameterKind::Texture, context.objectLayoutOptions);
+ auto objLayout2 =
+ rules->GetObjectLayout(ShaderParameterKind::SubpassInput, context.objectLayoutOptions);
objLayout1.layoutInfos.add(objLayout2.layoutInfos.getFirst());
- return createSimpleTypeLayout(
- objLayout1,
- type,
- rules);
+ return createSimpleTypeLayout(objLayout1, type, rules);
}
else if (auto textureType = as<TextureType>(type))
{
@@ -4311,48 +4423,33 @@ static TypeLayoutResult _createTypeLayout(
{
switch (textureType->getAccess())
{
- default:
- kind = ShaderParameterKind::MutableTextureSampler;
- break;
+ default: kind = ShaderParameterKind::MutableTextureSampler; break;
- case SLANG_RESOURCE_ACCESS_READ:
- kind = ShaderParameterKind::TextureSampler;
- break;
+ case SLANG_RESOURCE_ACCESS_READ: kind = ShaderParameterKind::TextureSampler; break;
}
}
else
{
switch (textureType->getAccess())
{
- default:
- kind = ShaderParameterKind::MutableTexture;
- break;
+ default: kind = ShaderParameterKind::MutableTexture; break;
- case SLANG_RESOURCE_ACCESS_READ:
- kind = ShaderParameterKind::Texture;
- break;
+ case SLANG_RESOURCE_ACCESS_READ: kind = ShaderParameterKind::Texture; break;
}
}
auto objLayout = rules->GetObjectLayout(kind, context.objectLayoutOptions);
- return createSimpleTypeLayout(
- objLayout,
- type,
- rules);
+ return createSimpleTypeLayout(objLayout, type, rules);
}
else if (auto imageType = as<GLSLImageType>(type))
{
// TODO: the logic here should really be defined by the rules,
// and not at this top level...
ShaderParameterKind kind;
- switch( imageType->getAccess() )
+ switch (imageType->getAccess())
{
- default:
- kind = ShaderParameterKind::MutableImage;
- break;
+ default: kind = ShaderParameterKind::MutableImage; break;
- case SLANG_RESOURCE_ACCESS_READ:
- kind = ShaderParameterKind::Image;
- break;
+ case SLANG_RESOURCE_ACCESS_READ: kind = ShaderParameterKind::Image; break;
}
return createSimpleTypeLayout(
@@ -4378,62 +4475,66 @@ 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).getSimple(); \
- auto typeLayout = createStructuredBufferTypeLayout( \
- context, \
- ShaderParameterKind::KIND, \
- type_##TYPE, \
- type_##TYPE->getElementType()); \
- return TypeLayoutResult(typeLayout, info); \
- } while(0)
-
- CASE(HLSLStructuredBufferType, StructuredBuffer);
- CASE(HLSLRWStructuredBufferType, MutableStructuredBuffer);
+#define CASE(TYPE, KIND) \
+ else if (auto type_##TYPE = as<TYPE>(type)) do \
+ { \
+ auto info = rules->GetObjectLayout(ShaderParameterKind::KIND, context.objectLayoutOptions) \
+ .getSimple(); \
+ auto typeLayout = createStructuredBufferTypeLayout( \
+ context, \
+ ShaderParameterKind::KIND, \
+ type_##TYPE, \
+ type_##TYPE->getElementType()); \
+ return TypeLayoutResult(typeLayout, info); \
+ } \
+ while (0)
+
+ CASE(HLSLStructuredBufferType, StructuredBuffer);
+ CASE(HLSLRWStructuredBufferType, MutableStructuredBuffer);
CASE(HLSLRasterizerOrderedStructuredBufferType, MutableStructuredBuffer);
- CASE(HLSLAppendStructuredBufferType, AppendConsumeStructuredBuffer);
- CASE(HLSLConsumeStructuredBufferType, AppendConsumeStructuredBuffer);
+ CASE(HLSLAppendStructuredBufferType, AppendConsumeStructuredBuffer);
+ CASE(HLSLConsumeStructuredBufferType, AppendConsumeStructuredBuffer);
#undef CASE
// TODO: need a better way to handle this stuff...
-#define CASE(TYPE, KIND) \
- else if(as<TYPE>(type)) do { \
- return createSimpleTypeLayout( \
- rules->GetObjectLayout(ShaderParameterKind::KIND, context.objectLayoutOptions), \
- type, rules); \
- } while(0)
-
- CASE(HLSLByteAddressBufferType, RawBuffer);
- CASE(HLSLRWByteAddressBufferType, MutableRawBuffer);
- CASE(HLSLRasterizerOrderedByteAddressBufferType, MutableRawBuffer);
-
- CASE(GLSLInputAttachmentType, InputRenderTarget);
+#define CASE(TYPE, KIND) \
+ else if (as<TYPE>(type)) do \
+ { \
+ return createSimpleTypeLayout( \
+ rules->GetObjectLayout(ShaderParameterKind::KIND, context.objectLayoutOptions), \
+ type, \
+ rules); \
+ } \
+ while (0)
+
+ CASE(HLSLByteAddressBufferType, RawBuffer);
+ CASE(HLSLRWByteAddressBufferType, MutableRawBuffer);
+ CASE(HLSLRasterizerOrderedByteAddressBufferType, MutableRawBuffer);
+
+ CASE(GLSLInputAttachmentType, InputRenderTarget);
// This case is mostly to allow users to add new resource types...
- CASE(UntypedBufferResourceType, RawBuffer);
+ CASE(UntypedBufferResourceType, RawBuffer);
- CASE(GLSLShaderStorageBufferType, MutableRawBuffer);
+ CASE(GLSLShaderStorageBufferType, MutableRawBuffer);
#undef CASE
- else if(auto basicType = as<BasicExpressionType>(type))
+ else if (auto basicType = as<BasicExpressionType>(type))
{
return createSimpleTypeLayout(
rules->GetScalarLayout(basicType->getBaseType()),
type,
rules);
}
- else if(auto vecType = as<VectorExpressionType>(type))
+ else if (auto vecType = as<VectorExpressionType>(type))
{
auto elementType = vecType->getElementType();
- size_t elementCount = (size_t) getIntVal(vecType->getElementCount());
+ size_t elementCount = (size_t)getIntVal(vecType->getElementCount());
- auto element = _createTypeLayout(
- context,
- elementType);
+ auto element = _createTypeLayout(context, elementType);
BaseType elementBaseType = BaseType::Void;
if (auto elementBasicType = as<BasicExpressionType>(elementType))
@@ -4455,15 +4556,13 @@ static TypeLayoutResult _createTypeLayout(
return TypeLayoutResult(typeLayout, info);
}
- else if(auto matType = as<MatrixExpressionType>(type))
+ else if (auto matType = as<MatrixExpressionType>(type))
{
- size_t rowCount = (size_t) getIntVal(matType->getRowCount());
- size_t colCount = (size_t) getIntVal(matType->getColumnCount());
+ size_t rowCount = (size_t)getIntVal(matType->getRowCount());
+ size_t colCount = (size_t)getIntVal(matType->getColumnCount());
auto elementType = matType->getElementType();
- auto elementResult = _createTypeLayout(
- context,
- elementType);
+ auto elementResult = _createTypeLayout(context, elementType);
auto elementTypeLayout = elementResult.layout;
auto elementInfo = elementResult.info;
@@ -4500,10 +4599,7 @@ static TypeLayoutResult _createTypeLayout(
auto rowType = matType->getRowType();
RefPtr<VectorTypeLayout> rowTypeLayout = new VectorTypeLayout();
- auto rowInfo = rules->GetVectorLayout(
- elementBaseType,
- elementInfo,
- colCount);
+ auto rowInfo = rules->GetVectorLayout(elementBaseType, elementInfo, colCount);
size_t majorStride = info.elementStride;
size_t minorStride = elementInfo.getUniformLayout().size.getFiniteValue();
@@ -4545,7 +4641,11 @@ static TypeLayoutResult _createTypeLayout(
}
else if (auto arrayType = as<ArrayExpressionType>(type))
{
- return createArrayLikeTypeLayout(context, arrayType, arrayType->getElementType(), arrayType->getElementCount());
+ return createArrayLikeTypeLayout(
+ context,
+ arrayType,
+ arrayType->getElementType(),
+ arrayType->getElementCount());
}
else if (auto atomicType = as<AtomicType>(type))
{
@@ -4567,9 +4667,7 @@ static TypeLayoutResult _createTypeLayout(
ptrLayout->addResourceUsage(info.kind, info.size);
- const auto valueTypeLayout = _createTypeLayout(
- context,
- ptrType->getValueType());
+ const auto valueTypeLayout = _createTypeLayout(context, ptrType->getValueType());
ptrLayout->valueTypeLayout = valueTypeLayout.layout;
@@ -4586,7 +4684,7 @@ static TypeLayoutResult _createTypeLayout(
{
// A `Tuple` type is laid out exactly the same way as a `struct` type,
// except that we want have a declref to the field.
-
+
StructTypeLayoutBuilder typeLayoutBuilder;
StructTypeLayoutBuilder pendingDataTypeLayoutBuilder;
@@ -4607,20 +4705,20 @@ static TypeLayoutResult _createTypeLayout(
// computed so far.
//
Int baseExistentialSlotIndex = 0;
- if (auto resInfo = typeLayout->FindResourceInfo(LayoutResourceKind::ExistentialTypeParam))
+ if (auto resInfo =
+ typeLayout->FindResourceInfo(LayoutResourceKind::ExistentialTypeParam))
baseExistentialSlotIndex = Int(resInfo->count.getFiniteValue());
//
// When computing the layout for the field, we will give it access
// to all the incoming specialized type slots that haven't already
// been consumed/claimed by preceding fields.
//
- auto fieldLayoutContext = context.withSpecializationArgsOffsetBy(baseExistentialSlotIndex);
+ auto fieldLayoutContext =
+ context.withSpecializationArgsOffsetBy(baseExistentialSlotIndex);
auto elementType = tupleType->getMember(i);
- TypeLayoutResult fieldResult = _createTypeLayout(
- fieldLayoutContext,
- elementType,
- nullptr);
+ TypeLayoutResult fieldResult =
+ _createTypeLayout(fieldLayoutContext, elementType, nullptr);
auto fieldTypeLayout = fieldResult.layout;
auto fieldVarLayout = typeLayoutBuilder.addField(DeclRef<VarDeclBase>(), fieldResult);
@@ -4638,7 +4736,9 @@ static TypeLayoutResult _createTypeLayout(
// created for no reason.
//
pendingDataTypeLayoutBuilder.beginLayoutIfNeeded(type, rules);
- auto fieldPendingVarLayout = pendingDataTypeLayoutBuilder.addField(DeclRef<VarDeclBase>(), fieldPendingDataTypeLayout);
+ auto fieldPendingVarLayout = pendingDataTypeLayoutBuilder.addField(
+ DeclRef<VarDeclBase>(),
+ fieldPendingDataTypeLayout);
fieldVarLayout->pendingVarLayout = fieldPendingVarLayout;
}
}
@@ -4668,7 +4768,8 @@ static TypeLayoutResult _createTypeLayout(
_addLayout(context, type, typeLayout);
// Add all base fields first.
- for (auto inheritanceDeclRef : getMembersOfType<InheritanceDecl>(context.astBuilder, structDeclRef))
+ for (auto inheritanceDeclRef :
+ getMembersOfType<InheritanceDecl>(context.astBuilder, structDeclRef))
{
auto baseType = getSup(context.astBuilder, inheritanceDeclRef);
if (isInterfaceType(baseType))
@@ -4678,12 +4779,14 @@ static TypeLayoutResult _createTypeLayout(
}
// First, add all fields with explicit offsets.
- for (auto field : getFields(context.astBuilder, structDeclRef, MemberFilterStyle::Instance))
+ for (auto field :
+ getFields(context.astBuilder, structDeclRef, MemberFilterStyle::Instance))
{
// If the field has an explicit offset, then we will
// use that to place it.
//
- if (const auto packOffsetModifier = field.getDecl()->findModifier<HLSLPackOffsetSemantic>())
+ if (const auto packOffsetModifier =
+ field.getDecl()->findModifier<HLSLPackOffsetSemantic>())
{
TypeLayoutResult fieldResult = _createTypeLayout(
context,
@@ -4692,11 +4795,12 @@ static TypeLayoutResult _createTypeLayout(
typeLayoutBuilder.addExplicitUniformField(field, fieldResult);
continue;
}
-
}
- for (auto field : getFields(context.astBuilder, structDeclRef, MemberFilterStyle::Instance))
+ for (auto field :
+ getFields(context.astBuilder, structDeclRef, MemberFilterStyle::Instance))
{
- if (const auto packOffsetModifier = field.getDecl()->findModifier<HLSLPackOffsetSemantic>())
+ if (const auto packOffsetModifier =
+ field.getDecl()->findModifier<HLSLPackOffsetSemantic>())
continue;
// The fields of a `struct` type may include existential (interface)
@@ -4710,14 +4814,16 @@ static TypeLayoutResult _createTypeLayout(
// computed so far.
//
Int baseExistentialSlotIndex = 0;
- if(auto resInfo = typeLayout->FindResourceInfo(LayoutResourceKind::ExistentialTypeParam))
+ if (auto resInfo =
+ typeLayout->FindResourceInfo(LayoutResourceKind::ExistentialTypeParam))
baseExistentialSlotIndex = Int(resInfo->count.getFiniteValue());
//
// When computing the layout for the field, we will give it access
// to all the incoming specialized type slots that haven't already
// been consumed/claimed by preceding fields.
//
- auto fieldLayoutContext = context.withSpecializationArgsOffsetBy(baseExistentialSlotIndex);
+ auto fieldLayoutContext =
+ context.withSpecializationArgsOffsetBy(baseExistentialSlotIndex);
TypeLayoutResult fieldResult = _createTypeLayout(
fieldLayoutContext,
@@ -4733,14 +4839,15 @@ static TypeLayoutResult _createTypeLayout(
// that this type needs to have stored somewhere, but which can't
// be laid out in the layout of the type itself.
//
- if(auto fieldPendingDataTypeLayout = fieldTypeLayout->pendingDataTypeLayout)
+ if (auto fieldPendingDataTypeLayout = fieldTypeLayout->pendingDataTypeLayout)
{
// We only create this secondary layout on-demand, so that
// we don't end up with a bunch of empty structure type layouts
// created for no reason.
//
pendingDataTypeLayoutBuilder.beginLayoutIfNeeded(type, rules);
- auto fieldPendingVarLayout = pendingDataTypeLayoutBuilder.addField(field, fieldPendingDataTypeLayout);
+ auto fieldPendingVarLayout =
+ pendingDataTypeLayoutBuilder.addField(field, fieldPendingDataTypeLayout);
fieldVarLayout->pendingVarLayout = fieldPendingVarLayout;
}
}
@@ -4748,7 +4855,7 @@ static TypeLayoutResult _createTypeLayout(
typeLayoutBuilder.endLayout();
pendingDataTypeLayoutBuilder.endLayout();
- if( auto pendingDataTypeLayout = pendingDataTypeLayoutBuilder.getTypeLayout() )
+ if (auto pendingDataTypeLayout = pendingDataTypeLayoutBuilder.getTypeLayout())
{
typeLayout->pendingDataTypeLayout = pendingDataTypeLayout;
}
@@ -4757,9 +4864,8 @@ static TypeLayoutResult _createTypeLayout(
}
else if (auto globalGenericParamDecl = declRef.as<GlobalGenericParamDecl>())
{
- if( auto concreteType = findGlobalGenericSpecializationArg(
- context,
- globalGenericParamDecl.getDecl()) )
+ if (auto concreteType =
+ findGlobalGenericSpecializationArg(context, globalGenericParamDecl.getDecl()))
{
// If we know what concrete type has been used to specialize
// the global generic type parameter, then we should use
@@ -4772,17 +4878,17 @@ static TypeLayoutResult _createTypeLayout(
// Otherwise we must create a type layout that represents
// the generic type parameter itself.
//
- return _createTypeLayoutForGlobalGenericTypeParam(context, type, globalGenericParamDecl.getDecl());
+ return _createTypeLayoutForGlobalGenericTypeParam(
+ context,
+ type,
+ globalGenericParamDecl.getDecl());
}
}
else if (auto assocTypeParam = declRef.as<AssocTypeDecl>())
{
- return createSimpleTypeLayout(
- SimpleLayoutInfo(),
- type,
- rules);
+ return createSimpleTypeLayout(SimpleLayoutInfo(), type, rules);
}
- else if( auto simpleGenericParam = declRef.as<GenericTypeParamDecl>() )
+ else if (auto simpleGenericParam = declRef.as<GenericTypeParamDecl>())
{
// A bare generic type parameter can come up during layout
// of a generic entry point (or an entry point nested in
@@ -4797,12 +4903,9 @@ static TypeLayoutResult _createTypeLayout(
// any parameters, even those that don't depend on
// generics.
//
- return createSimpleTypeLayout(
- SimpleLayoutInfo(),
- type,
- rules);
+ return createSimpleTypeLayout(SimpleLayoutInfo(), type, rules);
}
- else if( auto interfaceDeclRef = declRef.as<InterfaceDecl>() )
+ else if (auto interfaceDeclRef = declRef.as<InterfaceDecl>())
{
RefPtr<ExistentialTypeLayout> typeLayout = new ExistentialTypeLayout();
typeLayout->type = type;
@@ -4955,15 +5058,15 @@ static TypeLayoutResult _createTypeLayout(
// to determine if it "fits" in the reserved space.
//
bool fits = true;
- for(auto usage : concreteTypeAnyValueLayout->resourceInfos)
+ for (auto usage : concreteTypeAnyValueLayout->resourceInfos)
{
- if(usage.kind == LayoutResourceKind::Uniform)
+ if (usage.kind == LayoutResourceKind::Uniform)
{
// If the amount of uniform storage that the concrete type
// requires is more than has been reserved, when the
// type does not fit.
//
- if(usage.count > fixedExistentialValueSize)
+ if (usage.count > fixedExistentialValueSize)
{
fits = false;
break;
@@ -4989,7 +5092,7 @@ static TypeLayoutResult _createTypeLayout(
// If the value does *not* fit, then we need to figure out
// where the excess data will go.
//
- if(!fits)
+ if (!fits)
{
// If we were doing layout for a typical CPU target, then
// we could just say that the fixed-size storage contains
@@ -5008,15 +5111,16 @@ static TypeLayoutResult _createTypeLayout(
// Because we know the layout of the data, but not the placement,
// it is considered to be a "pending" part of the type layout.
//
- typeLayout->pendingDataTypeLayout =
- createTypeLayout(context, concreteType);
+ typeLayout->pendingDataTypeLayout = createTypeLayout(context, concreteType);
}
}
- // Interface type occupies a uniform slot for the fixed size storage, with alignment of 4 bytes.
+ // Interface type occupies a uniform slot for the fixed size storage, with alignment of
+ // 4 bytes.
return TypeLayoutResult(
- typeLayout, SimpleLayoutInfo(LayoutResourceKind::Uniform, uniformSlotSize, 4));
+ typeLayout,
+ SimpleLayoutInfo(LayoutResourceKind::Uniform, uniformSlotSize, 4));
}
- else if( auto enumDeclRef = declRef.as<EnumDecl>() )
+ else if (auto enumDeclRef = declRef.as<EnumDecl>())
{
// We lay out an enumeration type as its tag type.
//
@@ -5034,51 +5138,47 @@ static TypeLayoutResult _createTypeLayout(
//
// We should probably inform the user with an error message here.
- return createSimpleTypeLayout(
- SimpleLayoutInfo(),
- errorType,
- rules);
+ return createSimpleTypeLayout(SimpleLayoutInfo(), errorType, rules);
}
- else if( auto existentialSpecializedType = as<ExistentialSpecializedType>(type) )
+ else if (auto existentialSpecializedType = as<ExistentialSpecializedType>(type))
{
ExpandedSpecializationArgs args;
for (Index i = 0; i < existentialSpecializedType->getArgCount(); ++i)
{
args.add(existentialSpecializedType->getArg(i));
}
- TypeLayoutContext subContext = context.withSpecializationArgs(
- args.getBuffer(),
- args.getCount());
+ TypeLayoutContext subContext =
+ context.withSpecializationArgs(args.getBuffer(), args.getCount());
- auto baseTypeLayoutResult = _createTypeLayout(
- subContext,
- existentialSpecializedType->getBaseType());
+ auto baseTypeLayoutResult =
+ _createTypeLayout(subContext, existentialSpecializedType->getBaseType());
UniformLayoutInfo info = rules->BeginStructLayout();
rules->AddStructField(&info, baseTypeLayoutResult.info.getUniformLayout());
- RefPtr<ExistentialSpecializedTypeLayout> typeLayout = new ExistentialSpecializedTypeLayout();
+ RefPtr<ExistentialSpecializedTypeLayout> typeLayout =
+ new ExistentialSpecializedTypeLayout();
_addLayout(context, type, typeLayout);
typeLayout->type = type;
typeLayout->rules = rules;
- for( auto resInfo : baseTypeLayoutResult.layout->resourceInfos )
+ for (auto resInfo : baseTypeLayoutResult.layout->resourceInfos)
{
- if(resInfo.kind != LayoutResourceKind::Uniform)
+ if (resInfo.kind != LayoutResourceKind::Uniform)
typeLayout->addResourceUsage(resInfo);
}
RefPtr<VarLayout> pendingDataVarLayout = new VarLayout();
- if(auto pendingDataTypeLayout = baseTypeLayoutResult.layout->pendingDataTypeLayout)
+ if (auto pendingDataTypeLayout = baseTypeLayoutResult.layout->pendingDataTypeLayout)
{
pendingDataVarLayout->typeLayout = pendingDataTypeLayout;
- for( auto pendingResInfo : pendingDataTypeLayout->resourceInfos )
+ for (auto pendingResInfo : pendingDataTypeLayout->resourceInfos)
{
auto kind = pendingResInfo.kind;
UInt index = 0;
- if( kind == LayoutResourceKind::Uniform )
+ if (kind == LayoutResourceKind::Uniform)
{
LayoutSize uniformOffset = rules->AddStructField(
&info,
@@ -5088,7 +5188,7 @@ static TypeLayoutResult _createTypeLayout(
}
else
{
- if(auto primaryResInfo = baseTypeLayoutResult.layout->FindResourceInfo(kind))
+ if (auto primaryResInfo = baseTypeLayoutResult.layout->FindResourceInfo(kind))
index = primaryResInfo->count.getFiniteValue();
typeLayout->addResourceUsage(pendingResInfo);
}
@@ -5100,7 +5200,7 @@ static TypeLayoutResult _createTypeLayout(
typeLayout->pendingDataVarLayout = pendingDataVarLayout;
typeLayout->uniformAlignment = info.alignment;
- if( info.size != 0 )
+ if (info.size != 0)
{
typeLayout->addResourceUsage(LayoutResourceKind::Uniform, info.size);
}
@@ -5110,16 +5210,13 @@ static TypeLayoutResult _createTypeLayout(
// catch-all case in case nothing matched
SLANG_ASSERT(!"unimplemented case in type layout");
- return createSimpleTypeLayout(
- SimpleLayoutInfo(),
- type,
- rules);
+ return createSimpleTypeLayout(SimpleLayoutInfo(), type, rules);
}
RefPtr<TypeLayout> getSimpleVaryingParameterTypeLayout(
- TypeLayoutContext const& context,
- Type* type,
- EntryPointParameterDirectionMask directionMask)
+ TypeLayoutContext const& context,
+ Type* type,
+ EntryPointParameterDirectionMask directionMask)
{
auto rules = context.rules;
@@ -5137,16 +5234,16 @@ RefPtr<TypeLayout> getSimpleVaryingParameterTypeLayout(
int varyingRulesCount = 0;
LayoutRulesImpl* varyingRules[2];
- if( directionMask & kEntryPointParameterDirection_Input )
+ if (directionMask & kEntryPointParameterDirection_Input)
{
varyingRules[varyingRulesCount++] = context.getRulesFamily()->getVaryingInputRules();
}
- if( directionMask & kEntryPointParameterDirection_Output )
+ if (directionMask & kEntryPointParameterDirection_Output)
{
varyingRules[varyingRulesCount++] = context.getRulesFamily()->getVaryingOutputRules();
}
- if(auto basicType = as<BasicExpressionType>(type))
+ if (auto basicType = as<BasicExpressionType>(type))
{
auto baseType = basicType->getBaseType();
@@ -5154,7 +5251,7 @@ RefPtr<TypeLayout> getSimpleVaryingParameterTypeLayout(
typeLayout->type = type;
typeLayout->rules = rules;
- for( int rr = 0; rr < varyingRulesCount; ++rr )
+ for (int rr = 0; rr < varyingRulesCount; ++rr)
{
auto info = varyingRules[rr]->GetScalarLayout(baseType);
typeLayout->addResourceUsage(info.kind, info.size);
@@ -5162,13 +5259,13 @@ RefPtr<TypeLayout> getSimpleVaryingParameterTypeLayout(
return typeLayout;
}
- else if(auto vecType = as<VectorExpressionType>(type))
+ else if (auto vecType = as<VectorExpressionType>(type))
{
auto elementType = vecType->getElementType();
- size_t elementCount = (size_t) getIntVal(vecType->getElementCount());
+ size_t elementCount = (size_t)getIntVal(vecType->getElementCount());
BaseType elementBaseType = BaseType::Void;
- if( auto elementBasicType = as<BasicExpressionType>(elementType) )
+ if (auto elementBasicType = as<BasicExpressionType>(elementType))
{
elementBaseType = elementBasicType->getBaseType();
}
@@ -5187,7 +5284,7 @@ RefPtr<TypeLayout> getSimpleVaryingParameterTypeLayout(
typeLayout->rules = rules;
typeLayout->elementTypeLayout = elementTypeLayout;
- for( int rr = 0; rr < varyingRulesCount; ++rr )
+ for (int rr = 0; rr < varyingRulesCount; ++rr)
{
auto varyingRuleSet = varyingRules[rr];
auto elementInfo = varyingRuleSet->GetScalarLayout(elementBaseType);
@@ -5197,14 +5294,14 @@ RefPtr<TypeLayout> getSimpleVaryingParameterTypeLayout(
return typeLayout;
}
- else if(auto matType = as<MatrixExpressionType>(type))
+ else if (auto matType = as<MatrixExpressionType>(type))
{
- size_t rowCount = (size_t) getIntVal(matType->getRowCount());
- size_t colCount = (size_t) getIntVal(matType->getColumnCount());
+ size_t rowCount = (size_t)getIntVal(matType->getRowCount());
+ size_t colCount = (size_t)getIntVal(matType->getColumnCount());
auto elementType = matType->getElementType();
BaseType elementBaseType = BaseType::Void;
- if( auto elementBasicType = as<BasicExpressionType>(elementType) )
+ if (auto elementBasicType = as<BasicExpressionType>(elementType))
{
elementBaseType = elementBasicType->getBaseType();
}
@@ -5241,19 +5338,24 @@ RefPtr<TypeLayout> getSimpleVaryingParameterTypeLayout(
typeLayout->elementTypeLayout = rowTypeLayout;
typeLayout->mode = context.matrixLayoutMode;
- for( int rr = 0; rr < varyingRulesCount; ++rr )
+ for (int rr = 0; rr < varyingRulesCount; ++rr)
{
auto varyingRuleSet = varyingRules[rr];
auto elementInfo = varyingRuleSet->GetScalarLayout(elementBaseType);
- auto info = varyingRuleSet->GetMatrixLayout(elementBaseType, elementInfo, layoutMajorCount, layoutMinorCount);
+ auto info = varyingRuleSet->GetMatrixLayout(
+ elementBaseType,
+ elementInfo,
+ layoutMajorCount,
+ layoutMinorCount);
typeLayout->addResourceUsage(info.kind, info.size);
- if(context.matrixLayoutMode == kMatrixLayoutMode_RowMajor)
+ if (context.matrixLayoutMode == kMatrixLayoutMode_RowMajor)
{
// For row-major matrices only, we can compute an effective
// resource usage for the row type.
- auto rowInfo = varyingRuleSet->GetVectorLayout(elementBaseType, elementInfo, colCount);
+ auto rowInfo =
+ varyingRuleSet->GetVectorLayout(elementBaseType, elementInfo, colCount);
rowTypeLayout->addResourceUsage(rowInfo.kind, rowInfo.size);
}
}
@@ -5263,23 +5365,18 @@ RefPtr<TypeLayout> getSimpleVaryingParameterTypeLayout(
// catch-all case in case nothing matched
SLANG_ASSERT(!"unimplemented case for varying parameter layout");
- return createSimpleTypeLayout(
- SimpleLayoutInfo(),
- type,
- rules).layout;
+ return createSimpleTypeLayout(SimpleLayoutInfo(), type, rules).layout;
}
-RefPtr<TypeLayout> createTypeLayout(
- TypeLayoutContext& context,
- Type* type)
+RefPtr<TypeLayout> createTypeLayout(TypeLayoutContext& context, Type* type)
{
return _createTypeLayout(context, type).layout;
}
RefPtr<TypeLayout> createTypeLayoutWith(
- const TypeLayoutContext& context,
- LayoutRulesImpl* rules,
- Type* type)
+ const TypeLayoutContext& context,
+ LayoutRulesImpl* rules,
+ Type* type)
{
auto c = context.with(rules);
return createTypeLayout(c, type);
@@ -5289,9 +5386,9 @@ RefPtr<TypeLayout> createTypeLayoutWith(
void TypeLayout::removeResourceUsage(LayoutResourceKind kind)
{
Int infoCount = resourceInfos.getCount();
- for( Int ii = 0; ii < infoCount; ++ii )
+ for (Int ii = 0; ii < infoCount; ++ii)
{
- if( resourceInfos[ii].kind == kind )
+ if (resourceInfos[ii].kind == kind)
{
resourceInfos.removeAt(ii);
return;
@@ -5302,9 +5399,9 @@ void TypeLayout::removeResourceUsage(LayoutResourceKind kind)
void VarLayout::removeResourceUsage(LayoutResourceKind kind)
{
Int infoCount = resourceInfos.getCount();
- for( Int ii = 0; ii < infoCount; ++ii )
+ for (Int ii = 0; ii < infoCount; ++ii)
{
- if( resourceInfos[ii].kind == kind )
+ if (resourceInfos[ii].kind == kind)
{
resourceInfos.removeAt(ii);
return;
@@ -5315,7 +5412,7 @@ void VarLayout::removeResourceUsage(LayoutResourceKind kind)
void TypeLayout::addResourceUsageFrom(TypeLayout* otherTypeLayout)
{
- for(auto resInfo : otherTypeLayout->resourceInfos)
+ for (auto resInfo : otherTypeLayout->resourceInfos)
addResourceUsage(resInfo);
}
@@ -5324,7 +5421,7 @@ RefPtr<TypeLayout> TypeLayout::unwrapArray()
{
TypeLayout* typeLayout = this;
- while(auto arrayTypeLayout = as<ArrayTypeLayout>(typeLayout))
+ while (auto arrayTypeLayout = as<ArrayTypeLayout>(typeLayout))
typeLayout = arrayTypeLayout->elementTypeLayout;
return typeLayout;