Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support both 'const in' and 'in const' param specifiers #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions hlslang/GLSLCodeGen/hlslSupportLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,16 +738,33 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
" m[0][1], m[1][1], m[2][1], m[3][1],\n"
" m[0][2], m[1][2], m[2][2], m[3][2],\n"
" m[0][3], m[1][3], m[2][3], m[3][3]);\n"
"}\n")
);
"}\n"

"mat4x3 xll_transpose_mf3x4(mat3x4 m) {\n"
" return mat4x3( m[0][0], m[1][0], m[2][0],\n"
" m[0][1], m[1][1], m[2][1],\n"
" m[0][2], m[1][2], m[2][2],\n"
" m[0][3], m[1][3], m[2][3]);\n"
"}\n\n"
"mat3x4 xll_transpose_mf4x3(mat4x3 m) {\n"
" return mat3x4( m[0][0], m[1][0], m[2][0], m[3][0],\n"
" m[0][1], m[1][1], m[2][1], m[3][1],\n"
" m[0][2], m[1][2], m[2][2], m[3][2]);\n"
"}\n\n"
)
);

// Note: constructing temporary vector and assigning individual components; seems to avoid
// some GLSL bugs on AMD (Win7, Radeon HD 58xx, Catalyst 10.5).
hlslSupportLib->insert( CodeMap::value_type( EOpMatrixIndex,
"vec2 xll_matrixindex_mf2x2_i (mat2 m, int i) { vec2 v; v.x=m[0][i]; v.y=m[1][i]; return v; }\n"
"vec3 xll_matrixindex_mf3x3_i (mat3 m, int i) { vec3 v; v.x=m[0][i]; v.y=m[1][i]; v.z=m[2][i]; return v; }\n"
"vec4 xll_matrixindex_mf4x4_i (mat4 m, int i) { vec4 v; v.x=m[0][i]; v.y=m[1][i]; v.z=m[2][i]; v.w=m[3][i]; return v; }\n")
);
"vec4 xll_matrixindex_mf4x4_i (mat4 m, int i) { vec4 v; v.x=m[0][i]; v.y=m[1][i]; v.z=m[2][i]; v.w=m[3][i]; return v; }\n"

"vec3 xll_matrixindex_mf3x4_i (mat3x4 m, int i) { vec3 v; v.x=m[0][i]; v.y=m[1][i]; v.z=m[2][i]; return v; }\n"
"vec4 xll_matrixindex_mf4x3_i (mat4x3 m, int i) { vec4 v; v.x=m[0][i]; v.y=m[1][i]; v.z=m[2][i]; v.w=m[3][i]; return v; }\n"
)
);

// The GLSL ES implementation on NaCl does not support dynamic indexing
// (except when the operand is a uniform in vertex shaders). The GLSL specification
Expand Down
36 changes: 32 additions & 4 deletions hlslang/MachineIndependent/hlslang.y
Original file line number Diff line number Diff line change
Expand Up @@ -1125,13 +1125,29 @@ parameter_declaration
if (parseContext.paramErrorCheck($3.line, $1.qualifier, $2, $$.param.type))
parseContext.recover();
}
| parameter_qualifier type_qualifier parameter_declarator
{
$$ = $3;
if (parseContext.paramErrorCheck($3.line, $2.qualifier, $1, $$.param.type))
parseContext.recover();
}
| type_qualifier parameter_declarator {
$$ = $2;
if (parseContext.paramErrorCheck($2.line, $1.qualifier, EvqIn, $$.param.type))
parseContext.recover();
}
| parameter_qualifier parameter_declarator {
$$ = $2;
if (parseContext.parameterSamplerErrorCheck($2.line, $1, *$2.param.type))
parseContext.recover();
if (parseContext.paramErrorCheck($2.line, EvqTemporary, $1, $$.param.type))
parseContext.recover();
}
| parameter_declarator {
$$ = $1;
if (parseContext.paramErrorCheck($1.line, EvqTemporary, EvqIn, $$.param.type))
parseContext.recover();
}
//
// Only type
//
Expand All @@ -1140,20 +1156,32 @@ parameter_declaration
if (parseContext.paramErrorCheck($3.line, $1.qualifier, $2, $$.param.type))
parseContext.recover();
}
| parameter_qualifier type_qualifier parameter_type_specifier {
$$ = $3;
if (parseContext.paramErrorCheck($3.line, $2.qualifier, $1, $$.param.type))
parseContext.recover();
}
| type_qualifier parameter_type_specifier {
$$ = $2;
if (parseContext.paramErrorCheck($2.line, $1.qualifier, EvqIn, $$.param.type))
parseContext.recover();
}
| parameter_qualifier parameter_type_specifier {
$$ = $2;
if (parseContext.parameterSamplerErrorCheck($2.line, $1, *$2.param.type))
parseContext.recover();
if (parseContext.paramErrorCheck($2.line, EvqTemporary, $1, $$.param.type))
parseContext.recover();
}
| parameter_type_specifier {
$$ = $1;
if (parseContext.paramErrorCheck($1.line, EvqTemporary, EvqIn, $$.param.type))
parseContext.recover();
}
;

parameter_qualifier
: /* empty */ {
$$ = EvqIn;
}
| IN_QUAL {
: IN_QUAL {
$$ = EvqIn;
}
| OUT_QUAL {
Expand Down
15 changes: 13 additions & 2 deletions tests/vertex/const-arg-in.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,24 @@ float4 fake_to_float(const in fake4 fake)
real.y = fake.fy;
real.z = fake.fz;
real.w = fake.fw;


return(real);
}

float4 fake_to_float_2(in const fake4 fake)
{
float4 real;
real.x = fake.fx;
real.y = fake.fy;
real.z = fake.fz;
real.w = fake.fw;

return(real);
}

float4 splat(const float f)
{
return(fake_to_float(fake_splat(f)));
return(fake_to_float(fake_splat(f)) + fake_to_float_2(fake_splat(f)));
}

float4 main() : POSITION
Expand Down