diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-07-07 09:14:18 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-07 09:14:18 -0700 |
| commit | 975e4b326cd2ef3ef0341d1fb7509315b9dee555 (patch) | |
| tree | 09c8ef6014eb49fe9a173600a5b8639d4695c34e /source/slang | |
| parent | c47f23c2e61538c55819363f9db47ce946649027 (diff) | |
| parent | d35b4d4bc62beebaa56b949a1ac59470192b5dfc (diff) | |
Merge pull request #58 from tfoleyNV/bug-57
Bug 57
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/reflection.cpp | 43 | ||||
| -rw-r--r-- | source/slang/type-layout.cpp | 41 |
2 files changed, 73 insertions, 11 deletions
diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp index b27cc0696..d62da70c1 100644 --- a/source/slang/reflection.cpp +++ b/source/slang/reflection.cpp @@ -100,6 +100,14 @@ SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType) { return SLANG_TYPE_KIND_CONSTANT_BUFFER; } + else if (type->As<TextureBufferType>()) + { + return SLANG_TYPE_KIND_TEXTURE_BUFFER; + } + else if (type->As<GLSLShaderStorageBufferType>()) + { + return SLANG_TYPE_KIND_SHADER_STORAGE_BUFFER; + } else if (auto samplerStateType = type->As<SamplerStateType>()) { return SLANG_TYPE_KIND_SAMPLER_STATE; @@ -1049,6 +1057,24 @@ static void emitReflectionTypeInfoJSON( type->getElementType()); break; + case SLANG_TYPE_KIND_TEXTURE_BUFFER: + write(writer, "\"kind\": \"textureBuffer\""); + write(writer, ",\n"); + write(writer, "\"elementType\": "); + emitReflectionTypeJSON( + writer, + type->getElementType()); + break; + + case SLANG_TYPE_KIND_SHADER_STORAGE_BUFFER: + write(writer, "\"kind\": \"shaderStorageBuffer\""); + write(writer, ",\n"); + write(writer, "\"elementType\": "); + emitReflectionTypeJSON( + writer, + type->getElementType()); + break; + case SLANG_TYPE_KIND_SCALAR: write(writer, "\"kind\": \"scalar\""); write(writer, ",\n"); @@ -1184,6 +1210,23 @@ static void emitReflectionTypeLayoutInfoJSON( typeLayout->getElementTypeLayout()); break; + case SLANG_TYPE_KIND_TEXTURE_BUFFER: + write(writer, "\"kind\": \"textureBuffer\""); + write(writer, ",\n"); + write(writer, "\"elementType\": "); + emitReflectionTypeLayoutJSON( + writer, + typeLayout->getElementTypeLayout()); + break; + + case SLANG_TYPE_KIND_SHADER_STORAGE_BUFFER: + write(writer, "\"kind\": \"shaderStorageBuffer\""); + write(writer, ",\n"); + write(writer, "\"elementType\": "); + emitReflectionTypeLayoutJSON( + writer, + typeLayout->getElementTypeLayout()); + break; } // TODO: emit size info for types diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp index fbaec3736..10c7327ce 100644 --- a/source/slang/type-layout.cpp +++ b/source/slang/type-layout.cpp @@ -155,20 +155,32 @@ struct GLSLConstantBufferLayoutRulesImpl : DefaultConstantBufferLayoutRulesImpl { }; +// The `std140` and `std430` rules require vectors to be aligned to the next power of +// two up from their size (so a `float2` is 8-byte aligned, and a `float3` is +// 16-byte aligned). +// +// Note that in this case we have a type layout where the size is *not* a multiple +// of the alignment, so it should be possible to pack a scalar after a `float3`. +static SimpleLayoutInfo getGLSLVectorLayout( + SimpleLayoutInfo elementInfo, size_t elementCount) +{ + assert(elementInfo.kind == LayoutResourceKind::Uniform); + auto size = elementInfo.size * elementCount; + SimpleLayoutInfo vectorInfo( + LayoutResourceKind::Uniform, + size, + RoundUpToPowerOfTwo(size)); + return vectorInfo; +} + +// The `std140` rules combine the GLSL-specific layout for 3-vectors with the +// alignment padding for structures and arrays that is common to both HLSL +// and GLSL constant buffers. struct Std140LayoutRulesImpl : GLSLConstantBufferLayoutRulesImpl { - // The `std140` rules require vectors to be aligned to the next power of two - // up from their size (so a `float2` is 8-byte aligned, and a `float3` is - // 16-byte aligned). SimpleLayoutInfo GetVectorLayout(SimpleLayoutInfo elementInfo, size_t elementCount) override { - assert(elementInfo.kind == LayoutResourceKind::Uniform); - auto size = elementInfo.size * elementCount; - SimpleLayoutInfo vectorInfo( - LayoutResourceKind::Uniform, - size, - RoundUpToPowerOfTwo(size)); - return vectorInfo; + return getGLSLVectorLayout(elementInfo, elementCount); } }; @@ -207,8 +219,15 @@ struct HLSLStructuredBufferLayoutRulesImpl : DefaultLayoutRulesImpl // TODO: customize these to be correct... }; -struct Std430LayoutRulesImpl : GLSLConstantBufferLayoutRulesImpl +// The `std430` rules don't include the array/structure alignment padding that +// gets applied to constant buffers, but they do include the padding of 3-vectors +// to be aligned as 4-vectors. +struct Std430LayoutRulesImpl : DefaultLayoutRulesImpl { + SimpleLayoutInfo GetVectorLayout(SimpleLayoutInfo elementInfo, size_t elementCount) override + { + return getGLSLVectorLayout(elementInfo, elementCount); + } }; struct DefaultVaryingLayoutRulesImpl : DefaultLayoutRulesImpl |
