SPV: Fix #807: use --hlsl-offsets to allow hlsl-style offsets in a buffer.

Corresponds to the EShMsgHlslOffsets flag in messages.
Works for both GLSL and HLSL.
This commit is contained in:
John Kessenich
2017-04-05 17:38:20 -06:00
parent 6f1e595dbc
commit 4f1403ed1b
12 changed files with 276 additions and 10 deletions

View File

@@ -2728,7 +2728,23 @@ void TGlslangToSpvTraverser::updateMemberOffset(const glslang::TType& /*structTy
int memberSize;
int dummyStride;
int memberAlignment = glslangIntermediate->getBaseAlignment(memberType, memberSize, dummyStride, explicitLayout == glslang::ElpStd140, matrixLayout == glslang::ElmRowMajor);
// Adjust alignment for HLSL rules
if (glslangIntermediate->usingHlslOFfsets() &&
! memberType.isArray() && memberType.isVector()) {
int dummySize;
int componentAlignment = glslangIntermediate->getBaseAlignmentScalar(memberType, dummySize);
if (componentAlignment <= 4)
memberAlignment = componentAlignment;
}
// Bump up to member alignment
glslang::RoundToPow2(currentOffset, memberAlignment);
// Bump up to vec4 if there is a bad straddle
if (glslangIntermediate->improperStraddle(memberType, memberSize, currentOffset))
glslang::RoundToPow2(currentOffset, 16);
nextOffset = currentOffset + memberSize;
}