Commit 7b211a37 by steve-lunarg

HLSL: allow multi-dimensional arrays

All the underpinnings are there; this just parses multiple array dimensions and passes them through to the existing mechanisms. Also, minor comment fixes, and add a new test for multi-dim arrays.
parent e3aa654c
// implicit sized array
// array size from initializer
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 };
// Test implicit size arrayed structs
// Test initializer sizing for arrayed structs
static struct mystruct {
int i;
float f;
......@@ -24,7 +24,7 @@ struct PS_OUTPUT { float4 color : SV_Target0; };
void main(out PS_OUTPUT ps_output)
{
// implicit sized local array
// local array sized from initializers
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];
......
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(
{"hlsl.amend.frag", "f1"},
{"hlsl.array.frag", "PixelShaderFunction"},
{"hlsl.array.implicit-size.frag", "PixelShaderFunction"},
{"hlsl.array.multidim.frag", "main"},
{"hlsl.assoc.frag", "PixelShaderFunction"},
{"hlsl.attribute.frag", "PixelShaderFunction"},
{"hlsl.buffer.frag", "PixelShaderFunction"},
......
......@@ -2676,35 +2676,40 @@ bool HlslGrammar::acceptDefaultLabel(TIntermNode*& statement)
}
// array_specifier
// : LEFT_BRACKET integer_expression RGHT_BRACKET post_decls // optional
// : LEFT_BRACKET RGHT_BRACKET post_decls // optional
// : LEFT_BRACKET integer_expression RGHT_BRACKET ... // optional
// : LEFT_BRACKET RGHT_BRACKET // optional
//
void HlslGrammar::acceptArraySpecifier(TArraySizes*& arraySizes)
{
arraySizes = nullptr;
if (! acceptTokenClass(EHTokLeftBracket))
// Early-out if there aren't any array dimensions
if (!peekTokenClass(EHTokLeftBracket))
return;
TSourceLoc loc = token.loc;
TIntermTyped* sizeExpr = nullptr;
// If we get here, we have at least one array dimension. This will track the sizes we find.
arraySizes = new TArraySizes;
// Array sizing expression is optional. If ommitted, array is implicitly sized.
const bool hasArraySize = acceptAssignmentExpression(sizeExpr);
// Collect each array dimension.
while (acceptTokenClass(EHTokLeftBracket)) {
TSourceLoc loc = token.loc;
TIntermTyped* sizeExpr = nullptr;
if (! acceptTokenClass(EHTokRightBracket)) {
expected("]");
return;
}
// Array sizing expression is optional. If ommitted, array will be later sized by initializer list.
const bool hasArraySize = acceptAssignmentExpression(sizeExpr);
arraySizes = new TArraySizes;
if (hasArraySize) {
TArraySize arraySize;
parseContext.arraySizeCheck(loc, sizeExpr, arraySize);
arraySizes->addInnerSize(arraySize);
} else {
arraySizes->addInnerSize(); // implicitly sized
if (! acceptTokenClass(EHTokRightBracket)) {
expected("]");
return;
}
if (hasArraySize) {
TArraySize arraySize;
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