HLSL: add Buffer support for Load method
This commit is contained in:
@@ -754,6 +754,18 @@ bool HlslGrammar::acceptTextureType(TType& type)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Buffers can handle small mats if they fit in 4 components
|
||||
if (dim == EsdBuffer && txType.isMatrix()) {
|
||||
if ((txType.getMatrixCols() * txType.getMatrixRows()) > 4) {
|
||||
expected("components < 4 in matrix buffer type");
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: except we don't handle it yet...
|
||||
unimplemented("matrix type in buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!txType.isScalar() && !txType.isVector()) {
|
||||
expected("scalar or vector type");
|
||||
return false;
|
||||
@@ -789,7 +801,14 @@ bool HlslGrammar::acceptTextureType(TType& type)
|
||||
const bool shadow = txType.isScalar() || (txType.isVector() && txType.getVectorSize() == 1);
|
||||
|
||||
TSampler sampler;
|
||||
sampler.setTexture(txType.getBasicType(), dim, array, shadow, ms);
|
||||
|
||||
// Buffers are combined.
|
||||
if (dim == EsdBuffer) {
|
||||
sampler.set(txType.getBasicType(), dim, array);
|
||||
} else {
|
||||
// DX10 textures are separated. TODO: DX9.
|
||||
sampler.setTexture(txType.getBasicType(), dim, array, shadow, ms);
|
||||
}
|
||||
|
||||
type.shallowCopy(TType(sampler, EvqUniform, arraySizes));
|
||||
|
||||
|
||||
@@ -1154,11 +1154,12 @@ void HlslParseContext::decomposeSampleMethods(const TSourceLoc& loc, TIntermType
|
||||
TIntermTyped* coordSwizzle = nullptr;
|
||||
|
||||
const bool isMS = argTex->getType().getSampler().isMultiSample();
|
||||
const bool isBuffer = argTex->getType().getSampler().dim == EsdBuffer;
|
||||
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
|
||||
if (isMS || isBuffer) {
|
||||
// MS and Buffer have no LOD
|
||||
coordSwizzle = argCoord;
|
||||
} else {
|
||||
// Extract coordinate
|
||||
@@ -1181,10 +1182,6 @@ void HlslParseContext::decomposeSampleMethods(const TSourceLoc& loc, TIntermType
|
||||
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);
|
||||
|
||||
// Build up the fetch
|
||||
txfetch->getSequence().push_back(argTex);
|
||||
txfetch->getSequence().push_back(coordSwizzle);
|
||||
@@ -1193,8 +1190,10 @@ void HlslParseContext::decomposeSampleMethods(const TSourceLoc& loc, TIntermType
|
||||
// add 2DMS sample index
|
||||
TIntermTyped* argSampleIdx = argAggregate->getSequence()[2]->getAsTyped();
|
||||
txfetch->getSequence().push_back(argSampleIdx);
|
||||
} else if (isBuffer) {
|
||||
// Nothing else to do for buffers.
|
||||
} else {
|
||||
// 2DMS has no LOD, but everything else does.
|
||||
// 2DMS and buffer have no LOD, but everything else does.
|
||||
txfetch->getSequence().push_back(lodComponent);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,11 @@ const char* BaseTypeName(const char argOrder, const char* scalarName, const char
|
||||
bool IsSamplerType(const char argType) { return argType == 'S' || argType == 's'; }
|
||||
bool IsTextureArrayed(const char argOrder) { return argOrder == '@' || argOrder == '&'; }
|
||||
bool IsTextureMS(const char argOrder) { return argOrder == '$' || argOrder == '&'; }
|
||||
bool IsTextureType(const char argOrder) { return argOrder == '%' || argOrder == '@' || IsTextureMS(argOrder); }
|
||||
bool IsBuffer(const char argOrder) { return argOrder == '*'; }
|
||||
bool IsTextureType(const char argOrder)
|
||||
{
|
||||
return argOrder == '%' || argOrder == '@' || IsTextureMS(argOrder) || IsBuffer(argOrder);
|
||||
}
|
||||
|
||||
// Reject certain combinations that are illegal sample methods. For example,
|
||||
// 3D arrays.
|
||||
@@ -78,6 +82,7 @@ bool IsIllegalSample(const glslang::TString& name, const char* argOrder, int dim
|
||||
{
|
||||
const bool isArrayed = IsTextureArrayed(*argOrder);
|
||||
const bool isMS = IsTextureMS(*argOrder);
|
||||
const bool isBuffer = IsBuffer(*argOrder);
|
||||
|
||||
// there are no 3D arrayed textures, or 3D SampleCmp(LevelZero)
|
||||
if (dim0 == 3 && (isArrayed || name == "SampleCmp" || name == "SampleCmpLevelZero"))
|
||||
@@ -112,6 +117,10 @@ bool IsIllegalSample(const glslang::TString& name, const char* argOrder, int dim
|
||||
if (isMS && dim0 != 2)
|
||||
return true;
|
||||
|
||||
// Buffer are only 1D
|
||||
if (isBuffer && dim0 != 1)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -127,9 +136,9 @@ int CoordinateArgPos(const glslang::TString& name, bool isTexture)
|
||||
}
|
||||
|
||||
// Some texture methods use an addition coordinate dimension for the mip
|
||||
bool HasMipInCoord(const glslang::TString& name, bool isMS)
|
||||
bool HasMipInCoord(const glslang::TString& name, bool isMS, bool isBuffer)
|
||||
{
|
||||
return name == "Load" && !isMS;
|
||||
return name == "Load" && !isMS && !isBuffer;
|
||||
}
|
||||
|
||||
// LOD calculations don't pass the array level in the coordinate.
|
||||
@@ -197,6 +206,7 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons
|
||||
const bool isArrayed = IsTextureArrayed(argOrder[0]);
|
||||
const bool isSampler = IsSamplerType(argType[0]);
|
||||
const bool isMS = IsTextureMS(argOrder[0]);
|
||||
const bool isBuffer = IsBuffer(argOrder[0]);
|
||||
|
||||
char type = *argType;
|
||||
|
||||
@@ -219,37 +229,38 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons
|
||||
char order = *argOrder;
|
||||
|
||||
if (UseHlslTypes) {
|
||||
// TODO: handle sub-vec4 returns
|
||||
switch (type) {
|
||||
case '-': s += "void"; break;
|
||||
case 'F': s += "float"; break;
|
||||
case 'D': s += "double"; break;
|
||||
case 'I': s += "int"; break;
|
||||
case 'U': s += "uint"; break;
|
||||
case 'B': s += "bool"; break;
|
||||
case 'S': s += "sampler"; break;
|
||||
case 's': s += "SamplerComparisonState"; break;
|
||||
case 'T': s += "Texture"; break;
|
||||
case 'i': s += "Texture <int4>"; break;
|
||||
case 'u': s += "Texture <uint4>"; break;
|
||||
default: s += "UNKNOWN_TYPE"; break;
|
||||
case '-': s += "void"; break;
|
||||
case 'F': s += "float"; break;
|
||||
case 'D': s += "double"; break;
|
||||
case 'I': s += "int"; break;
|
||||
case 'U': s += "uint"; break;
|
||||
case 'B': s += "bool"; break;
|
||||
case 'S': s += "sampler"; break;
|
||||
case 's': s += "SamplerComparisonState"; break;
|
||||
case 'T': s += (isBuffer ? "Buffer" : "Texture"); break;
|
||||
case 'i': s += (isBuffer ? "Buffer <int4>" : "Texture <int4>"); break;
|
||||
case 'u': s += (isBuffer ? "Buffer <uint4>" : "Texture <uint4>"); break;
|
||||
default: s += "UNKNOWN_TYPE"; break;
|
||||
}
|
||||
} else {
|
||||
switch (type) {
|
||||
case '-': s += "void"; break;
|
||||
case 'F': s += BaseTypeName(order, "float", "vec", "mat"); break;
|
||||
case 'D': s += BaseTypeName(order, "double", "dvec", "dmat"); break;
|
||||
case 'I': s += BaseTypeName(order, "int", "ivec", "imat"); break;
|
||||
case 'U': s += BaseTypeName(order, "uint", "uvec", "umat"); break;
|
||||
case 'B': s += BaseTypeName(order, "bool", "bvec", "bmat"); break;
|
||||
case 'S': s += "sampler"; break;
|
||||
case 's': s += "samplerShadow"; break;
|
||||
case 'F': s += BaseTypeName(order, "float", "vec", "mat"); break;
|
||||
case 'D': s += BaseTypeName(order, "double", "dvec", "dmat"); break;
|
||||
case 'I': s += BaseTypeName(order, "int", "ivec", "imat"); break;
|
||||
case 'U': s += BaseTypeName(order, "uint", "uvec", "umat"); break;
|
||||
case 'B': s += BaseTypeName(order, "bool", "bvec", "bmat"); break;
|
||||
case 'S': s += "sampler"; break;
|
||||
case 's': s += "samplerShadow"; break;
|
||||
case 'T': // fall through
|
||||
case 'i': // ...
|
||||
case 'u': // ...
|
||||
if (type != 'T')
|
||||
if (type != 'T') // create itexture, utexture, etc
|
||||
s += type;
|
||||
|
||||
s += "texture";
|
||||
s += (isBuffer ? "samplerBuffer" : "texture");
|
||||
break;
|
||||
|
||||
default: s += "UNKNOWN_TYPE"; break;
|
||||
@@ -263,7 +274,7 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons
|
||||
|
||||
// Add sampler dimensions
|
||||
if (isSampler || isTexture) {
|
||||
if (order == 'V' || isTexture) {
|
||||
if ((order == 'V' || isTexture) && !isBuffer) {
|
||||
switch (dim0) {
|
||||
case 1: s += "1D"; break;
|
||||
case 2: s += (isMS ? "2DMS" : "2D"); break;
|
||||
@@ -442,6 +453,7 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c
|
||||
// '%' as first letter of order creates texture of given F/I/U type (texture, itexture, etc)
|
||||
// '@' as first letter of order creates arrayed texture of given type
|
||||
// '$' / '&' as first letter of order creates 2DMS / 2DMSArray textures
|
||||
// '*' as first letter of order creates buffer object
|
||||
|
||||
static const struct {
|
||||
const char* name; // intrinsic name
|
||||
@@ -630,7 +642,7 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c
|
||||
{ "SampleLevel", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,S,F,", EShLangAll },
|
||||
{ "SampleLevel", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,S,F,,I", EShLangAll },
|
||||
|
||||
{ "Load", /*!O*/ "V4", nullptr, "%@,V", "FIU,I", EShLangAll },
|
||||
{ "Load", /*!O*/ "V4", nullptr, "%@*,V", "FIU,I", EShLangAll },
|
||||
{ "Load", /* O*/ "V4", nullptr, "%@,V,V", "FIU,I,I", EShLangAll },
|
||||
{ "Load", /* +sampleidex*/ "V4", nullptr, "$&,V,S", "FIU,I,I", EShLangAll },
|
||||
{ "Load", /* +samplindex, offset*/ "V4", nullptr, "$&,V,S,V", "FIU,I,I,I", EShLangAll },
|
||||
@@ -724,7 +736,8 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c
|
||||
const bool isTexture = IsTextureType(*argOrder);
|
||||
const bool isArrayed = IsTextureArrayed(*argOrder);
|
||||
const bool isMS = IsTextureMS(*argOrder);
|
||||
const bool mipInCoord = HasMipInCoord(intrinsic.name, isMS);
|
||||
const bool isBuffer = IsBuffer(*argOrder);
|
||||
const bool mipInCoord = HasMipInCoord(intrinsic.name, isMS, isBuffer);
|
||||
const int fixedVecSize = FixedVecSize(argOrder);
|
||||
const int coordArg = CoordinateArgPos(intrinsic.name, isTexture);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user