Skip to content

Commit ff1f979

Browse files
committed
Cleared out arrayStride mess
1 parent dc41516 commit ff1f979

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

include/nbl/asset/ShaderRes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ struct SShaderMemoryBlock
108108

109109
struct SMember
110110
{
111-
//! count==1 implies not array
112111
union {
113112
uint32_t count;
114113
uint32_t count_specID;
115114
};
116115
bool countIsSpecConstant;
117116
uint32_t offset;
118117
uint32_t size;
118+
//! relevant only in case of array types
119119
uint32_t arrayStride;
120120
//! mtxStride==0 implies not matrix
121121
uint32_t mtxStride;
@@ -131,6 +131,8 @@ struct SShaderMemoryBlock
131131
size_t count;
132132
} members;
133133
std::string name;
134+
135+
bool isArray() const { return countIsSpecConstant || count > 1u; }
134136
};
135137

136138
SMember::SMembers members;

src/nbl/asset/CShaderIntrospector.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,10 @@ static void introspectStructType(spirv_cross::Compiler& _comp, impl::SShaderMemo
684684
member.offset = _baseOffset + _comp.type_struct_member_offset(_parentType, m);
685685
member.rowMajor = _comp.get_member_decoration(_parentType.self, m, spv::DecorationRowMajor);
686686
member.type = spvcrossType2E_TYPE(mtype.basetype);
687+
member.arrayStride = 0u;
687688

689+
// if array, then we can get array stride from decoration (via spirv-cross)
690+
// otherwise arrayStride is left with value 0
688691
if (mtype.array.size())
689692
{
690693
member.count = mtype.array[0];
@@ -698,10 +701,6 @@ static void introspectStructType(spirv_cross::Compiler& _comp, impl::SShaderMemo
698701
member.count_specID = sc->id;
699702
}
700703
}
701-
else if (mtype.columns > 1u)
702-
member.arrayStride = member.size;
703-
else if (mtype.basetype != spirv_cross::SPIRType::Struct)
704-
member.arrayStride = core::max(0x1u<<core::findMSB(member.size),16u);
705704

706705
if (mtype.basetype == spirv_cross::SPIRType::Struct) //recursive introspection done in DFS manner (and without recursive calls)
707706
_pushStack.push({member.members, mtype, member.offset});

src/nbl/video/IOpenGLPipeline.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,18 @@ class IOpenGLPipeline
7373

7474
uint8_t* valueptr = state+m.offset;
7575

76-
uint32_t arrayStride = 0u; // TODO: @Crisspl this calculation is 100% wrong with `row_major` and arrays of matrices (for both std140 and std430)
76+
uint32_t arrayStride = m.arrayStride;
77+
// in case of non-array types, m.arrayStride is irrelevant
78+
// we should compute it though, so that we dont have to branch in the loop
79+
if (!m.isArray())
7780
{
78-
uint32_t arrayStride1 = 0u;
81+
// 1N for scalar types, 2N for gvec2, 4N for gvec3 and gvec4
82+
// N==sizeof(float)
7983
if (is_scalar_or_vec())
80-
arrayStride1 = (m.mtxRowCnt==1u) ? m.size : core::roundUpToPoT(m.mtxRowCnt)*4u;
84+
arrayStride = (m.mtxRowCnt==1u) ? m.size : core::roundUpToPoT(m.mtxRowCnt)*sizeof(float);
85+
// same as size in case of matrices
8186
else if (is_mtx())
82-
arrayStride1 = m.arrayStride;
83-
assert(arrayStride1);
84-
arrayStride = (m.count <= 1u) ? arrayStride1 : m.arrayStride;
87+
arrayStride = m.size;
8588
}
8689
assert(m.mtxStride==0u || arrayStride%m.mtxStride==0u);
8790
NBL_ASSUME_ALIGNED(valueptr, sizeof(float));

0 commit comments

Comments
 (0)