HLSL: Add texture Load method & decomposition

This commit is contained in:
LoopDawg
2016-07-20 16:34:44 -06:00
parent 83768cb541
commit f245101954
14 changed files with 2501 additions and 96 deletions

View File

@@ -1124,6 +1124,71 @@ void HlslParseContext::decomposeSampleMethods(const TSourceLoc& loc, TIntermType
break;
}
case EOpMethodLoad:
{
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* argCoord = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* argOffset = nullptr;
TIntermTyped* lodComponent = nullptr;
TIntermTyped* coordSwizzle = nullptr;
const bool isMS = argTex->getType().getSampler().isMultiSample();
const TBasicType coordBaseType = argCoord->getType().getBasicType();
// Last component of coordinate is the mip level, for non-MS. we separate them here:
if (isMS) {
// MS has no LOD
coordSwizzle = argTex;
} else {
// Extract coordinate
TVectorFields coordFields(0,1,2,3);
coordFields.num = argCoord->getType().getVectorSize() - (isMS ? 0 : 1);
TIntermTyped* coordIdx = intermediate.addSwizzle(coordFields, loc);
coordSwizzle = intermediate.addIndex(EOpVectorSwizzle, argCoord, coordIdx, loc);
coordSwizzle->setType(TType(coordBaseType, EvqTemporary, coordFields.num));
// Extract LOD
TIntermTyped* lodIdx = intermediate.addConstantUnion(coordFields.num, loc, true);
lodComponent = intermediate.addIndex(EOpIndexDirect, argCoord, lodIdx, loc);
lodComponent->setType(TType(coordBaseType, EvqTemporary, 1));
}
const int numArgs = argAggregate->getSequence().size();
const bool hasOffset = ((!isMS && numArgs == 3) || (isMS && numArgs == 4));
// Obtain offset arg, if there is one.
if (hasOffset) {
const int offsetPos = (isMS ? 3 : 2);
argOffset = argAggregate->getSequence()[offsetPos]->getAsTyped();
}
// Create texel fetch
const TOperator fetchOp = (hasOffset ? EOpTextureFetchOffset : EOpTextureFetch);
TIntermAggregate* txfetch = new TIntermAggregate(fetchOp);
const TSamplerDim dim = argTex->getType().getSampler().dim;
if (dim == EsdBuffer) // TODO: buffers
assert(0);
if (isMS) // TODO: 2DMS sample number
assert(0);
// Build up the fetch
txfetch->getSequence().push_back(argTex);
txfetch->getSequence().push_back(coordSwizzle);
if (!isMS) // MS has no LOD
txfetch->getSequence().push_back(lodComponent);
if (hasOffset)
txfetch->getSequence().push_back(argOffset);
txfetch->setType(node->getType());
txfetch->setLoc(loc);
node = txfetch;
break;
}
default:
break; // most pass through unchanged
}

View File

@@ -593,10 +593,10 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c
// { "SampleLevel", /*!O A*/ "V4", nullptr, "@V,S,V,S", "FIU,S,F,F", EShLangAll },
// { "SampleLevel", /* O A*/ "V4", nullptr, "@V,S,V,S,V", "FIU,S,F,F,I", EShLangAll },
// { "Load", "V4", nullptr, "%V,V", "FIU,I", EShLangAll },
// { "Load", "V4", nullptr, "@V,V", "FIU,I", EShLangAll },
// { "Load", /* offset*/ "V4", nullptr, "%V,V,V", "FIU,I,I", EShLangAll },
// { "Load", /* offset*/ "V4", nullptr, "@V,V,V", "FIU,I,I", EShLangAll },
{ "Load", /*!O !A*/ "V4", nullptr, "%V,V", "FIU,I", EShLangAll },
{ "Load", /*!O A*/ "V4", nullptr, "@V,V", "FIU,I", EShLangAll },
{ "Load", /* O !A*/ "V4", nullptr, "%V,V,V", "FIU,I,I", EShLangAll },
{ "Load", /* O A*/ "V4", nullptr, "@V,V,V", "FIU,I,I", EShLangAll },
// TODO: MS variants of Load
// { "Load", /* +sampleidex*/ "V4", nullptr, "$V,V,S", "FIU,I,I", EShLangAll },
// { "Load", /* +samplindex, offset*/ "V4", nullptr, "$V,V,S,V", "FIU,I,I,I", EShLangAll },
@@ -944,7 +944,7 @@ void TBuiltInParseablesHlsl::identifyBuiltIns(int /*version*/, EProfile /*profil
symbolTable.relateToOperator("SampleCmpLevelZero", EOpMethodSampleCmpLevelZero);
symbolTable.relateToOperator("SampleGrad", EOpMethodSampleGrad);
// symbolTable.relateToOperator("SampleLevel", EOpMethodSampleLevel);
// symbolTable.relateToOperator("Load", EOpMethodLoad);
symbolTable.relateToOperator("Load", EOpMethodLoad);
symbolTable.relateToOperator("GetDimensions", EOpMethodGetDimensions);
}