Commit 062b239d by John Kessenich Committed by GitHub

Merge pull request #549 from steve-lunarg/multidim-array

HLSL: allow multi-dimensional arrays
parents f042e407 7b211a37
// implicit sized array // array size from initializer
static float g_array [ ] = { 1, 2, 3, 4, 5 }; static float g_array [ ] = { 1, 2, 3, 4, 5 };
// Unused implicit sized array // Unused: array size from initializer
static float g_array_unused [ ] = { 1, 2, 3, 4, 5, 6, 7 }; static float g_array_unused [ ] = { 1, 2, 3, 4, 5, 6, 7 };
// Test implicit size arrayed structs // Test initializer sizing for arrayed structs
static struct mystruct { static struct mystruct {
int i; int i;
float f; float f;
...@@ -24,7 +24,7 @@ struct PS_OUTPUT { float4 color : SV_Target0; }; ...@@ -24,7 +24,7 @@ struct PS_OUTPUT { float4 color : SV_Target0; };
void main(out PS_OUTPUT ps_output) void main(out PS_OUTPUT ps_output)
{ {
// implicit sized local array // local array sized from initializers
float l_array[] = { 1, 2, 3 }; float l_array[] = { 1, 2, 3 };
ps_output.color = g_array[0] + g_array[4] + l_array[1] + g_mystruct[0].f + g_array[idx]; ps_output.color = g_array[0] + g_array[4] + l_array[1] + g_mystruct[0].f + g_array[idx];
......
float float_array[5][4][3];
struct PS_OUTPUT
{
float4 Color : SV_Target0;
};
PS_OUTPUT main()
{
float4 float4_array_1[2][3];
float4 float4_array_2[5][3];
float4_array_1[1][2] = float_array[2][3][1];
float4_array_2[1] = float4_array_1[0];
PS_OUTPUT psout;
psout.Color = float4_array_1[1][2];
return psout;
}
...@@ -83,6 +83,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -83,6 +83,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.amend.frag", "f1"}, {"hlsl.amend.frag", "f1"},
{"hlsl.array.frag", "PixelShaderFunction"}, {"hlsl.array.frag", "PixelShaderFunction"},
{"hlsl.array.implicit-size.frag", "PixelShaderFunction"}, {"hlsl.array.implicit-size.frag", "PixelShaderFunction"},
{"hlsl.array.multidim.frag", "main"},
{"hlsl.assoc.frag", "PixelShaderFunction"}, {"hlsl.assoc.frag", "PixelShaderFunction"},
{"hlsl.attribute.frag", "PixelShaderFunction"}, {"hlsl.attribute.frag", "PixelShaderFunction"},
{"hlsl.buffer.frag", "PixelShaderFunction"}, {"hlsl.buffer.frag", "PixelShaderFunction"},
......
...@@ -2680,35 +2680,40 @@ bool HlslGrammar::acceptDefaultLabel(TIntermNode*& statement) ...@@ -2680,35 +2680,40 @@ bool HlslGrammar::acceptDefaultLabel(TIntermNode*& statement)
} }
// array_specifier // array_specifier
// : LEFT_BRACKET integer_expression RGHT_BRACKET post_decls // optional // : LEFT_BRACKET integer_expression RGHT_BRACKET ... // optional
// : LEFT_BRACKET RGHT_BRACKET post_decls // optional // : LEFT_BRACKET RGHT_BRACKET // optional
// //
void HlslGrammar::acceptArraySpecifier(TArraySizes*& arraySizes) void HlslGrammar::acceptArraySpecifier(TArraySizes*& arraySizes)
{ {
arraySizes = nullptr; arraySizes = nullptr;
if (! acceptTokenClass(EHTokLeftBracket)) // Early-out if there aren't any array dimensions
if (!peekTokenClass(EHTokLeftBracket))
return; return;
TSourceLoc loc = token.loc; // If we get here, we have at least one array dimension. This will track the sizes we find.
TIntermTyped* sizeExpr = nullptr; arraySizes = new TArraySizes;
// Array sizing expression is optional. If ommitted, array is implicitly sized. // Collect each array dimension.
const bool hasArraySize = acceptAssignmentExpression(sizeExpr); while (acceptTokenClass(EHTokLeftBracket)) {
TSourceLoc loc = token.loc;
TIntermTyped* sizeExpr = nullptr;
if (! acceptTokenClass(EHTokRightBracket)) { // Array sizing expression is optional. If ommitted, array will be later sized by initializer list.
expected("]"); const bool hasArraySize = acceptAssignmentExpression(sizeExpr);
return;
}
arraySizes = new TArraySizes; if (! acceptTokenClass(EHTokRightBracket)) {
expected("]");
if (hasArraySize) { return;
TArraySize arraySize; }
parseContext.arraySizeCheck(loc, sizeExpr, arraySize);
arraySizes->addInnerSize(arraySize); if (hasArraySize) {
} else { TArraySize arraySize;
arraySizes->addInnerSize(); // implicitly sized parseContext.arraySizeCheck(loc, sizeExpr, arraySize);
arraySizes->addInnerSize(arraySize);
} else {
arraySizes->addInnerSize(0); // sized by initializers.
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment