HLSL: Implement packoffset production.
This commit is contained in:
@@ -2537,15 +2537,23 @@ void HlslGrammar::acceptPostDecls(TType& type)
|
||||
expected("(");
|
||||
return;
|
||||
}
|
||||
acceptTokenClass(EHTokIdentifier);
|
||||
acceptTokenClass(EHTokDot);
|
||||
acceptTokenClass(EHTokIdentifier);
|
||||
HlslToken locationToken;
|
||||
if (! acceptIdentifier(locationToken)) {
|
||||
expected("c[subcomponent][.component]");
|
||||
return;
|
||||
}
|
||||
HlslToken componentToken;
|
||||
if (acceptTokenClass(EHTokDot)) {
|
||||
if (! acceptIdentifier(componentToken)) {
|
||||
expected("component");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (! acceptTokenClass(EHTokRightParen)) {
|
||||
expected(")");
|
||||
break;
|
||||
}
|
||||
// TODO: process the packoffset information
|
||||
// c1.y means component y of location slot 1
|
||||
parseContext.handlePackOffset(locationToken.loc, type, *locationToken.string, componentToken.string);
|
||||
} else if (! acceptIdentifier(idToken)) {
|
||||
expected("semantic or packoffset or register");
|
||||
return;
|
||||
|
||||
@@ -2134,6 +2134,46 @@ void HlslParseContext::handleSemantic(TType& type, const TString& semantic)
|
||||
type.getQualifier().builtIn = EbvViewportIndex;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle seeing something like ": packoffset( c[Subcomponent][.component] )"
|
||||
//
|
||||
// 'location' has the "c[Subcomponent]" part.
|
||||
// 'component' points to the "component" part, or nullptr if not present.
|
||||
//
|
||||
void HlslParseContext::handlePackOffset(const TSourceLoc& loc, TType& type, const glslang::TString& location,
|
||||
const glslang::TString* component)
|
||||
{
|
||||
if (location.size() == 0 || location[0] != 'c') {
|
||||
error(loc, "expected 'c'", "packoffset", "");
|
||||
return;
|
||||
}
|
||||
if (location.size() == 1)
|
||||
return;
|
||||
if (! isdigit(location[1])) {
|
||||
error(loc, "expected number after 'c'", "packoffset", "");
|
||||
return;
|
||||
}
|
||||
|
||||
type.getQualifier().layoutOffset = 16 * atoi(location.substr(1, location.size()).c_str());
|
||||
if (component) {
|
||||
int componentOffset = 0;
|
||||
switch ((*component)[0]) {
|
||||
case 'x': componentOffset = 0; break;
|
||||
case 'y': componentOffset = 4; break;
|
||||
case 'z': componentOffset = 8; break;
|
||||
case 'w': componentOffset = 12; break;
|
||||
default:
|
||||
componentOffset = -1;
|
||||
break;
|
||||
}
|
||||
if (componentOffset < 0 || component->size() > 1) {
|
||||
error(loc, "expected {x, y, z, w} for component", "packoffset", "");
|
||||
return;
|
||||
}
|
||||
type.getQualifier().layoutOffset += componentOffset;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Same error message for all places assignments don't work.
|
||||
//
|
||||
|
||||
@@ -95,6 +95,7 @@ public:
|
||||
void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&);
|
||||
TFunction* handleConstructorCall(const TSourceLoc&, const TType&);
|
||||
void handleSemantic(TType& type, const TString& semantic);
|
||||
void handlePackOffset(const TSourceLoc&, TType& type, const glslang::TString& location, const glslang::TString* component);
|
||||
|
||||
TIntermAggregate* handleSamplerTextureCombine(const TSourceLoc& loc, TIntermTyped* argTex, TIntermTyped* argSampler);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user