Skip to content

Commit f8c493f

Browse files
antiagainstehsannas
authored andcommitted
[spirv] Add support for VK_EXT_scalar_block_layout
Ref: KhronosGroup/Vulkan-Docs#854
1 parent fd1f7be commit f8c493f

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

include/dxc/Support/SPIRVOptions.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ enum class SpirvLayoutRule {
3131
RelaxedGLSLStd430, // std430 with relaxed vector layout
3232
FxcCTBuffer, // fxc.exe layout rule for cbuffer/tbuffer
3333
FxcSBuffer, // fxc.exe layout rule for structured buffers
34+
Scalar, // VK_EXT_scalar_block_layout
3435
Max, // This is an invalid layout rule
3536
};
3637

tools/clang/lib/SPIRV/AlignmentSizeCalculator.cpp

+17-6
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ std::pair<uint32_t, uint32_t> AlignmentSizeCalculator::getAlignmentAndSize(
190190
uint32_t alignment = 0, size = 0;
191191
std::tie(alignment, size) =
192192
getAlignmentAndSize(elemType, rule, isRowMajor, stride);
193-
// Use element alignment for fxc rules
193+
// Use element alignment for fxc rules and VK_EXT_scalar_block_layout
194194
if (rule != SpirvLayoutRule::FxcCTBuffer &&
195-
rule != SpirvLayoutRule::FxcSBuffer)
195+
rule != SpirvLayoutRule::FxcSBuffer &&
196+
rule != SpirvLayoutRule::Scalar)
196197
alignment = (elemCount == 3 ? 4 : elemCount) * size;
197198

198199
return {alignment, elemCount * size};
@@ -217,9 +218,11 @@ std::pair<uint32_t, uint32_t> AlignmentSizeCalculator::getAlignmentAndSize(
217218

218219
const uint32_t vecStorageSize = rowMajor ? rowCount : colCount;
219220

220-
if (rule == SpirvLayoutRule::FxcSBuffer) {
221+
if (rule == SpirvLayoutRule::FxcSBuffer ||
222+
rule == SpirvLayoutRule::Scalar) {
221223
*stride = vecStorageSize * size;
222-
// Use element alignment for fxc structured buffers
224+
// Use element alignment for fxc structured buffers and
225+
// VK_EXT_scalar_block_layout
223226
return {alignment, rowCount * colCount * size};
224227
}
225228

@@ -274,6 +277,12 @@ std::pair<uint32_t, uint32_t> AlignmentSizeCalculator::getAlignmentAndSize(
274277
structSize += memberSize;
275278
}
276279

280+
if (rule == SpirvLayoutRule::Scalar) {
281+
// A structure has a scalar alignment equal to the largest scalar
282+
// alignment of any of its members in VK_EXT_scalar_block_layout.
283+
return {maxAlignment, structSize};
284+
}
285+
277286
if (rule == SpirvLayoutRule::GLSLStd140 ||
278287
rule == SpirvLayoutRule::RelaxedGLSLStd140 ||
279288
rule == SpirvLayoutRule::FxcCTBuffer) {
@@ -297,9 +306,11 @@ std::pair<uint32_t, uint32_t> AlignmentSizeCalculator::getAlignmentAndSize(
297306
std::tie(alignment, size) = getAlignmentAndSize(arrayType->getElementType(),
298307
rule, isRowMajor, stride);
299308

300-
if (rule == SpirvLayoutRule::FxcSBuffer) {
309+
if (rule == SpirvLayoutRule::FxcSBuffer ||
310+
rule == SpirvLayoutRule::Scalar) {
301311
*stride = size;
302-
// Use element alignment for fxc structured buffers
312+
// Use element alignment for fxc structured buffers and
313+
// VK_EXT_scalar_block_layout
303314
return {alignment, size * elemCount};
304315
}
305316

0 commit comments

Comments
 (0)