Skip to content

Commit ac988c2

Browse files
committed
Fix CB emulation when copying the struct out of CB
When an entire struct was copied out of the uniform buffer, like so: Foo foo = global_ubo.foos[3]; We didn't propagate the struct type correctly; this change fixes it.
1 parent 12a7da4 commit ac988c2

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/GLSLGenerator.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ void GLSLGenerator::OutputExpression(HLSLExpression* expression, const HLSLType*
486486

487487
if (bufferAccess)
488488
{
489-
OutputBufferAccessExpression(bufferAccess, expression, 0);
489+
OutputBufferAccessExpression(bufferAccess, expression, expression->expressionType, 0);
490490
}
491491
else if (expression->nodeType == HLSLNodeType_IdentifierExpression)
492492
{
@@ -1312,10 +1312,8 @@ HLSLBuffer* GLSLGenerator::GetBufferAccessExpression(HLSLExpression* expression)
13121312
return 0;
13131313
}
13141314

1315-
void GLSLGenerator::OutputBufferAccessExpression(HLSLBuffer* buffer, HLSLExpression* expression, unsigned int postOffset)
1315+
void GLSLGenerator::OutputBufferAccessExpression(HLSLBuffer* buffer, HLSLExpression* expression, const HLSLType& type, unsigned int postOffset)
13161316
{
1317-
const HLSLType& type = expression->expressionType;
1318-
13191317
if (type.array)
13201318
{
13211319
Error("Constant buffer access is not supported for arrays (use indexing instead)");
@@ -1368,7 +1366,7 @@ void GLSLGenerator::OutputBufferAccessExpression(HLSLBuffer* buffer, HLSLExpress
13681366

13691367
for (HLSLStructField* field = st->field; field; field = field->nextField)
13701368
{
1371-
OutputBufferAccessExpression(buffer, expression, offset);
1369+
OutputBufferAccessExpression(buffer, expression, field->type, offset);
13721370

13731371
if (field->nextField)
13741372
m_writer.Write(",");

src/GLSLGenerator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class GLSLGenerator
9696
void LayoutBufferAlign(const HLSLType& type, unsigned int& offset);
9797

9898
HLSLBuffer* GetBufferAccessExpression(HLSLExpression* expression);
99-
void OutputBufferAccessExpression(HLSLBuffer* buffer, HLSLExpression* expression, unsigned int postOffset);
99+
void OutputBufferAccessExpression(HLSLBuffer* buffer, HLSLExpression* expression, const HLSLType& type, unsigned int postOffset);
100100
unsigned int OutputBufferAccessIndex(HLSLExpression* expression, unsigned int postOffset);
101101

102102
void OutputBuffer(int indent, HLSLBuffer* buffer);

0 commit comments

Comments
 (0)