Merge pull request #121 from amdrexu/feature

Parser & SPV: Implement two extensions regarding GLSL sparse texture.
This commit is contained in:
John Kessenich 2016-01-15 00:52:18 -07:00
commit 68f1431a55
12 changed files with 1621 additions and 151 deletions

View file

@ -369,6 +369,8 @@ enum TOperator {
EOpImageAtomicExchange,
EOpImageAtomicCompSwap,
EOpSparseImageLoad,
EOpImageGuardEnd,
//
@ -398,6 +400,31 @@ enum TOperator {
EOpTextureGather,
EOpTextureGatherOffset,
EOpTextureGatherOffsets,
EOpTextureClamp,
EOpTextureOffsetClamp,
EOpTextureGradClamp,
EOpTextureGradOffsetClamp,
EOpSparseTextureGuardBegin,
EOpSparseTexture,
EOpSparseTextureLod,
EOpSparseTextureOffset,
EOpSparseTextureFetch,
EOpSparseTextureFetchOffset,
EOpSparseTextureLodOffset,
EOpSparseTextureGrad,
EOpSparseTextureGradOffset,
EOpSparseTextureGather,
EOpSparseTextureGatherOffset,
EOpSparseTextureGatherOffsets,
EOpSparseTexelsResident,
EOpSparseTextureClamp,
EOpSparseTextureOffsetClamp,
EOpSparseTextureGradClamp,
EOpSparseTextureGradOffsetClamp,
EOpSparseTextureGuardEnd,
EOpTextureGuardEnd,
@ -622,6 +649,7 @@ struct TCrackedTextureOp {
bool offsets;
bool gather;
bool grad;
bool lodClamp;
};
//
@ -637,6 +665,8 @@ public:
bool isConstructor() const;
bool isTexture() const { return op > EOpTextureGuardBegin && op < EOpTextureGuardEnd; }
bool isImage() const { return op > EOpImageGuardBegin && op < EOpImageGuardEnd; }
bool isSparseTexture() const { return op > EOpSparseTextureGuardBegin && op < EOpSparseTextureGuardEnd; }
bool isSparseImage() const { return op == EOpSparseImageLoad; }
// Crack the op into the individual dimensions of texturing operation.
void crackTexture(TSampler sampler, TCrackedTextureOp& cracked) const
@ -649,6 +679,7 @@ public:
cracked.offsets = false;
cracked.gather = false;
cracked.grad = false;
cracked.lodClamp = false;
switch (op) {
case EOpImageQuerySize:
@ -657,25 +688,40 @@ public:
case EOpTextureQueryLod:
case EOpTextureQueryLevels:
case EOpTextureQuerySamples:
case EOpSparseTexelsResident:
cracked.query = true;
break;
case EOpTexture:
case EOpSparseTexture:
break;
case EOpTextureClamp:
case EOpSparseTextureClamp:
cracked.lodClamp = true;
break;
case EOpTextureProj:
cracked.proj = true;
break;
case EOpTextureLod:
case EOpSparseTextureLod:
cracked.lod = true;
break;
case EOpTextureOffset:
case EOpSparseTextureOffset:
cracked.offset = true;
break;
case EOpTextureOffsetClamp:
case EOpSparseTextureOffsetClamp:
cracked.offset = true;
cracked.lodClamp = true;
break;
case EOpTextureFetch:
case EOpSparseTextureFetch:
cracked.fetch = true;
if (sampler.dim == Esd1D || (sampler.dim == Esd2D && ! sampler.ms) || sampler.dim == Esd3D)
cracked.lod = true;
break;
case EOpTextureFetchOffset:
case EOpSparseTextureFetchOffset:
cracked.fetch = true;
cracked.offset = true;
if (sampler.dim == Esd1D || (sampler.dim == Esd2D && ! sampler.ms) || sampler.dim == Esd3D)
@ -686,6 +732,7 @@ public:
cracked.proj = true;
break;
case EOpTextureLodOffset:
case EOpSparseTextureLodOffset:
cracked.offset = true;
cracked.lod = true;
break;
@ -699,9 +746,16 @@ public:
cracked.proj = true;
break;
case EOpTextureGrad:
case EOpSparseTextureGrad:
cracked.grad = true;
break;
case EOpTextureGradClamp:
case EOpSparseTextureGradClamp:
cracked.grad = true;
cracked.lodClamp = true;
break;
case EOpTextureGradOffset:
case EOpSparseTextureGradOffset:
cracked.grad = true;
cracked.offset = true;
break;
@ -714,14 +768,23 @@ public:
cracked.offset = true;
cracked.proj = true;
break;
case EOpTextureGradOffsetClamp:
case EOpSparseTextureGradOffsetClamp:
cracked.grad = true;
cracked.offset = true;
cracked.lodClamp = true;
break;
case EOpTextureGather:
case EOpSparseTextureGather:
cracked.gather = true;
break;
case EOpTextureGatherOffset:
case EOpSparseTextureGatherOffset:
cracked.gather = true;
cracked.offset = true;
break;
case EOpTextureGatherOffsets:
case EOpSparseTextureGatherOffsets:
cracked.gather = true;
cracked.offsets = true;
break;

View file

@ -1956,6 +1956,14 @@ void TBuiltIns::add2ndGenerationSamplingImaging(int version, EProfile profile, i
}
}
}
//
// sparseTexelsResidentARB()
//
if (profile != EEsProfile && version >= 450) {
commonBuiltins.append("bool sparseTexelsResidentARB(int code);\n");
}
}
//
@ -2069,6 +2077,15 @@ void TBuiltIns::addImageFunctions(TSampler sampler, TString& typeName, int versi
commonBuiltins.append(prefixes[sampler.type]);
commonBuiltins.append("vec4);\n");
if (sampler.dim != Esd1D && sampler.dim != EsdBuffer && profile != EEsProfile && version >= 450) {
commonBuiltins.append("int sparseImageLoadARB(readonly volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", out ");
commonBuiltins.append(prefixes[sampler.type]);
commonBuiltins.append("vec4");
commonBuiltins.append(");\n");
}
if ( profile != EEsProfile ||
(profile == EEsProfile && version >= 310)) {
if (sampler.type == EbtInt || sampler.type == EbtUint) {
@ -2123,7 +2140,7 @@ void TBuiltIns::addImageFunctions(TSampler sampler, TString& typeName, int versi
//
// Add all the texture lookup functions for the given type.
//
void TBuiltIns::addSamplingFunctions(TSampler sampler, TString& typeName, int /*version*/, EProfile /*profile*/)
void TBuiltIns::addSamplingFunctions(TSampler sampler, TString& typeName, int version, EProfile profile)
{
//
// texturing
@ -2196,97 +2213,148 @@ void TBuiltIns::addSamplingFunctions(TSampler sampler, TString& typeName, int /*
if (extraProj && (sampler.dim == Esd3D || sampler.shadow))
continue;
TString s;
for (int lodClamp = 0; lodClamp <= 1 ;++lodClamp) { // loop over "bool" lod clamp
// return type
if (sampler.shadow)
s.append("float ");
else {
s.append(prefixes[sampler.type]);
s.append("vec4 ");
}
if (lodClamp && (profile == EEsProfile || version < 450))
continue;
if (lodClamp && (proj || lod || fetch))
continue;
// name
if (fetch)
s.append("texel");
else
s.append("texture");
if (proj)
s.append("Proj");
if (lod)
s.append("Lod");
if (grad)
s.append("Grad");
if (fetch)
s.append("Fetch");
if (offset)
s.append("Offset");
s.append("(");
for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not
// sampler type
s.append(typeName);
if (sparse && (profile == EEsProfile || version < 450))
continue;
// Sparse sampling is not for 1D/1D array texture, buffer texture, and projective texture
if (sparse && (sampler.dim == Esd1D || sampler.dim == EsdBuffer || proj))
continue;
// P coordinate
if (extraProj)
s.append(",vec4");
else {
s.append(",");
TBasicType t = fetch ? EbtInt : EbtFloat;
if (totalDims == 1)
s.append(TType::getBasicString(t));
else {
s.append(prefixes[t]);
s.append("vec");
s.append(postfixes[totalDims]);
TString s;
// return type
if (sparse)
s.append("int ");
else {
if (sampler.shadow)
s.append("float ");
else {
s.append(prefixes[sampler.type]);
s.append("vec4 ");
}
}
// name
if (sparse) {
if (fetch)
s.append("sparseTexel");
else
s.append("sparseTexture");
} else {
if (fetch)
s.append("texel");
else
s.append("texture");
}
if (proj)
s.append("Proj");
if (lod)
s.append("Lod");
if (grad)
s.append("Grad");
if (fetch)
s.append("Fetch");
if (offset)
s.append("Offset");
if (lodClamp)
s.append("Clamp");
if (lodClamp || sparse)
s.append("ARB");
s.append("(");
// sampler type
s.append(typeName);
// P coordinate
if (extraProj)
s.append(",vec4");
else {
s.append(",");
TBasicType t = fetch ? EbtInt : EbtFloat;
if (totalDims == 1)
s.append(TType::getBasicString(t));
else {
s.append(prefixes[t]);
s.append("vec");
s.append(postfixes[totalDims]);
}
}
if (bias && compare)
continue;
// non-optional lod argument (lod that's not driven by lod loop) or sample
if ((fetch && sampler.dim != EsdBuffer && sampler.dim != EsdRect && !sampler.ms) ||
(sampler.ms && fetch))
s.append(",int");
// non-optional lod
if (lod)
s.append(",float");
// gradient arguments
if (grad) {
if (dimMap[sampler.dim] == 1)
s.append(",float,float");
else {
s.append(",vec");
s.append(postfixes[dimMap[sampler.dim]]);
s.append(",vec");
s.append(postfixes[dimMap[sampler.dim]]);
}
}
// offset
if (offset) {
if (dimMap[sampler.dim] == 1)
s.append(",int");
else {
s.append(",ivec");
s.append(postfixes[dimMap[sampler.dim]]);
}
}
// non-optional compare
if (compare)
s.append(",float");
// lod clamp
if (lodClamp)
s.append(",float");
// texel out (for sparse texture)
if (sparse) {
s.append(",out ");
if (sampler.shadow)
s.append("float ");
else {
s.append(prefixes[sampler.type]);
s.append("vec4 ");
}
}
// optional bias
if (bias)
s.append(",float");
s.append(");\n");
// Add to the per-language set of built-ins
if (bias)
stageBuiltins[EShLangFragment].append(s);
else
commonBuiltins.append(s);
}
}
if (bias && compare)
continue;
// non-optional lod argument (lod that's not driven by lod loop) or sample
if ((fetch && sampler.dim != EsdBuffer && sampler.dim != EsdRect && !sampler.ms) ||
(sampler.ms && fetch))
s.append(",int");
// non-optional lod
if (lod)
s.append(",float");
// gradient arguments
if (grad) {
if (dimMap[sampler.dim] == 1)
s.append(",float,float");
else {
s.append(",vec");
s.append(postfixes[dimMap[sampler.dim]]);
s.append(",vec");
s.append(postfixes[dimMap[sampler.dim]]);
}
}
// offset
if (offset) {
if (dimMap[sampler.dim] == 1)
s.append(",int");
else {
s.append(",ivec");
s.append(postfixes[dimMap[sampler.dim]]);
}
}
// optional bias or non-optional compare
if (bias || compare)
s.append(",float");
s.append(");\n");
// Add to the per-language set of built-ins
if (bias)
stageBuiltins[EShLangFragment].append(s);
else
commonBuiltins.append(s);
}
}
}
@ -2303,7 +2371,7 @@ void TBuiltIns::addSamplingFunctions(TSampler sampler, TString& typeName, int /*
//
// Add all the texture gather functions for the given type.
//
void TBuiltIns::addGatherFunctions(TSampler sampler, TString& typeName, int version, EProfile /* profile */)
void TBuiltIns::addGatherFunctions(TSampler sampler, TString& typeName, int version, EProfile profile)
{
switch (sampler.dim) {
case Esd2D:
@ -2330,51 +2398,71 @@ void TBuiltIns::addGatherFunctions(TSampler sampler, TString& typeName, int vers
if (offset > 0 && sampler.dim == EsdCube)
continue;
TString s;
for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not
if (sparse && (profile == EEsProfile || version < 450))
continue;
// return type
s.append(prefixes[sampler.type]);
s.append("vec4 ");
TString s;
// name
s.append("textureGather");
switch (offset) {
case 1:
s.append("Offset");
break;
case 2:
s.append("Offsets");
default:
break;
// return type
if (sparse)
s.append("int ");
else {
s.append(prefixes[sampler.type]);
s.append("vec4 ");
}
// name
if (sparse)
s.append("sparseTextureGather");
else
s.append("textureGather");
switch (offset) {
case 1:
s.append("Offset");
break;
case 2:
s.append("Offsets");
default:
break;
}
if (sparse)
s.append("ARB");
s.append("(");
// sampler type argument
s.append(typeName);
// P coordinate argument
s.append(",vec");
int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
s.append(postfixes[totalDims]);
// refZ argument
if (sampler.shadow)
s.append(",float");
// offset argument
if (offset > 0) {
s.append(",ivec2");
if (offset == 2)
s.append("[4]");
}
// texel out (for sparse texture)
if (sparse) {
s.append(",out ");
s.append(prefixes[sampler.type]);
s.append("vec4 ");
}
// comp argument
if (comp)
s.append(",int");
s.append(");\n");
commonBuiltins.append(s);
}
s.append("(");
// sampler type argument
s.append(typeName);
// P coordinate argument
s.append(",vec");
int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
s.append(postfixes[totalDims]);
// refZ argument
if (sampler.shadow)
s.append(",float");
// offset argument
if (offset > 0) {
s.append(",ivec2");
if (offset == 2)
s.append("[4]");
}
// comp argument
if (comp)
s.append(",int");
s.append(");\n");
commonBuiltins.append(s);
//printf("%s", s.c_str());
}
}
}
@ -3164,6 +3252,37 @@ void IdentifyBuiltIns(int version, EProfile profile, int spv, EShLanguage langua
symbolTable.setFunctionExtensions("fwidthCoarse", 1, &E_GL_ARB_derivative_control);
}
// E_GL_ARB_sparse_texture2
if (profile != EEsProfile)
{
symbolTable.setFunctionExtensions("sparseTextureARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureLodARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureOffsetARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTexelFetchARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTexelFetchOffsetARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureLodOffsetARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureGradARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureGradOffsetARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureGatherARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureGatherOffsetARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureGatherOffsetsARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseImageLoadARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTexelsResident", 1, &E_GL_ARB_sparse_texture2);
}
// E_GL_ARB_sparse_texture_clamp
if (profile != EEsProfile)
{
symbolTable.setFunctionExtensions("sparseTextureClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("sparseTextureOffsetClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("sparseTextureGradClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("sparseTextureGradOffsetClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("textureClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("textureOffsetClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("textureGradClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("textureGradOffsetClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
}
symbolTable.setVariableExtensions("gl_FragDepthEXT", 1, &E_GL_EXT_frag_depth);
if (profile == EEsProfile) {
@ -3423,6 +3542,32 @@ void IdentifyBuiltIns(int version, EProfile profile, int spv, EShLanguage langua
symbolTable.relateToOperator("shadow1DProjLod", EOpTextureProjLod);
symbolTable.relateToOperator("shadow2DProjLod", EOpTextureProjLod);
}
if (profile != EEsProfile)
{
symbolTable.relateToOperator("sparseTextureARB", EOpSparseTexture);
symbolTable.relateToOperator("sparseTextureLodARB", EOpSparseTextureLod);
symbolTable.relateToOperator("sparseTextureOffsetARB", EOpSparseTextureOffset);
symbolTable.relateToOperator("sparseTexelFetchARB", EOpSparseTextureFetch);
symbolTable.relateToOperator("sparseTexelFetchOffsetARB", EOpSparseTextureFetchOffset);
symbolTable.relateToOperator("sparseTextureLodOffsetARB", EOpSparseTextureLodOffset);
symbolTable.relateToOperator("sparseTextureGradARB", EOpSparseTextureGrad);
symbolTable.relateToOperator("sparseTextureGradOffsetARB", EOpSparseTextureGradOffset);
symbolTable.relateToOperator("sparseTextureGatherARB", EOpSparseTextureGather);
symbolTable.relateToOperator("sparseTextureGatherOffsetARB", EOpSparseTextureGatherOffset);
symbolTable.relateToOperator("sparseTextureGatherOffsetsARB", EOpSparseTextureGatherOffsets);
symbolTable.relateToOperator("sparseImageLoadARB", EOpSparseImageLoad);
symbolTable.relateToOperator("sparseTexelsResidentARB", EOpSparseTexelsResident);
symbolTable.relateToOperator("sparseTextureClampARB", EOpSparseTextureClamp);
symbolTable.relateToOperator("sparseTextureOffsetClampARB", EOpSparseTextureOffsetClamp);
symbolTable.relateToOperator("sparseTextureGradClampARB", EOpSparseTextureGradClamp);
symbolTable.relateToOperator("sparseTextureGradOffsetClampARB", EOpSparseTextureGradOffsetClamp);
symbolTable.relateToOperator("textureClampARB", EOpTextureClamp);
symbolTable.relateToOperator("textureOffsetClampARB", EOpTextureOffsetClamp);
symbolTable.relateToOperator("textureGradClampARB", EOpTextureGradClamp);
symbolTable.relateToOperator("textureGradOffsetClampARB", EOpTextureGradOffsetClamp);
}
}
switch(language) {

View file

@ -173,6 +173,8 @@ void TParseContext::initializeExtensionBehavior()
extensionBehavior[E_GL_ARB_derivative_control] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_texture_image_samples] = EBhDisable;
extensionBehavior[E_GL_ARB_viewport_array] = EBhDisable;
extensionBehavior[E_GL_ARB_sparse_texture2] = EBhDisable;
extensionBehavior[E_GL_ARB_sparse_texture_clamp] = EBhDisable;
// extensionBehavior[E_GL_ARB_cull_distance] = EBhDisable; // present for 4.5, but need extension control over block members
// #line and #include
@ -274,6 +276,8 @@ const char* TParseContext::getPreamble()
"#define GL_ARB_derivative_control 1\n"
"#define GL_ARB_shader_texture_image_samples 1\n"
"#define GL_ARB_viewport_array 1\n"
"#define GL_ARB_sparse_texture2 1\n"
"#define GL_ARB_sparse_texture_clamp 1\n"
"#define GL_GOOGLE_cpp_style_line_directive 1\n"
"#define GL_GOOGLE_include_directive 1\n"

View file

@ -111,6 +111,8 @@ const char* const E_GL_ARB_shader_draw_parameters = "GL_ARB_shader_draw_pa
const char* const E_GL_ARB_derivative_control = "GL_ARB_derivative_control";
const char* const E_GL_ARB_shader_texture_image_samples = "GL_ARB_shader_texture_image_samples";
const char* const E_GL_ARB_viewport_array = "GL_ARB_viewport_array";
const char* const E_GL_ARB_sparse_texture2 = "GL_ARB_sparse_texture2";
const char* const E_GL_ARB_sparse_texture_clamp = "GL_ARB_sparse_texture_clamp";
//const char* const E_GL_ARB_cull_distance = "GL_ARB_cull_distance"; // present for 4.5, but need extension control over block members
// #line and #include