Implement the extension GL_AMD_texture_gather_bias_lod

This commit is contained in:
Rex Xu
2016-11-17 17:47:59 +08:00
parent 94c18a84cd
commit 225e0fcadd
12 changed files with 770 additions and 11 deletions

View File

@@ -28,11 +28,12 @@
#define GLSLextAMD_H
enum BuiltIn;
enum Capability;
enum Decoration;
enum Op;
static const int GLSLextAMDVersion = 100;
static const int GLSLextAMDRevision = 2;
static const int GLSLextAMDRevision = 3;
// SPV_AMD_shader_ballot
static const char* const E_SPV_AMD_shader_ballot = "SPV_AMD_shader_ballot";
@@ -113,4 +114,9 @@ enum GcnShaderAMD {
// SPV_AMD_gpu_shader_half_float
static const char* const E_SPV_AMD_gpu_shader_half_float = "SPV_AMD_gpu_shader_half_float";
// SPV_AMD_texture_gather_bias_lod
static const char* const E_SPV_AMD_texture_gather_bias_lod = "SPV_AMD_texture_gather_bias_lod";
static const Capability OpCapabilityImageGatherBiasLodAMD = static_cast<Capability>(5009);
#endif // #ifndef GLSLextAMD_H

View File

@@ -3044,7 +3044,7 @@ void TGlslangToSpvTraverser::translateArguments(const glslang::TIntermAggregate&
if (i == 6)
lvalue = true;
break;
case glslang::EOpSparseTextureGather:
case glslang::EOpSparseTextureGather:
if ((sampler.shadow && i == 3) || (! sampler.shadow && i == 2))
lvalue = true;
break;
@@ -3053,6 +3053,17 @@ void TGlslangToSpvTraverser::translateArguments(const glslang::TIntermAggregate&
if ((sampler.shadow && i == 4) || (! sampler.shadow && i == 3))
lvalue = true;
break;
#ifdef AMD_EXTENSIONS
case glslang::EOpSparseTextureGatherLod:
if (i == 3)
lvalue = true;
break;
case glslang::EOpSparseTextureGatherLodOffset:
case glslang::EOpSparseTextureGatherLodOffsets:
if (i == 4)
lvalue = true;
break;
#endif
default:
break;
}
@@ -3219,10 +3230,22 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
// check for bias argument
bool bias = false;
#ifdef AMD_EXTENSIONS
if (! cracked.lod && ! cracked.grad && ! cracked.fetch && ! cubeCompare) {
#else
if (! cracked.lod && ! cracked.gather && ! cracked.grad && ! cracked.fetch && ! cubeCompare) {
#endif
int nonBiasArgCount = 2;
#ifdef AMD_EXTENSIONS
if (cracked.gather)
++nonBiasArgCount; // comp argument should be present when bias argument is present
#endif
if (cracked.offset)
++nonBiasArgCount;
#ifdef AMD_EXTENSIONS
else if (cracked.offsets)
++nonBiasArgCount;
#endif
if (cracked.grad)
nonBiasArgCount += 2;
if (cracked.lodClamp)
@@ -3241,6 +3264,17 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
params.sampler = builder.createUnaryOp(spv::OpImage, builder.getImageType(params.sampler), params.sampler);
}
#ifdef AMD_EXTENSIONS
if (cracked.gather) {
const auto& sourceExtensions = glslangIntermediate->getRequestedExtensions();
if (bias || cracked.lod ||
sourceExtensions.find(glslang::E_GL_AMD_texture_gather_bias_lod) != sourceExtensions.end()) {
builder.addExtension(spv::E_SPV_AMD_texture_gather_bias_lod);
builder.addCapability(spv::OpCapabilityImageGatherBiasLodAMD);
}
}
#endif
// set the rest of the arguments
params.coords = arguments[1];
@@ -3308,21 +3342,20 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
++extraArgs;
}
// bias
if (bias) {
params.bias = arguments[2 + extraArgs];
++extraArgs;
}
// gather component
if (cracked.gather && ! sampler.shadow) {
// default component is 0, if missing, otherwise an argument
if (2 + extraArgs < (int)arguments.size()) {
params.component = arguments[2 + extraArgs];
++extraArgs;
} else {
} else
params.component = builder.makeIntConstant(0);
}
}
// bias
if (bias) {
params.bias = arguments[2 + extraArgs];
++extraArgs;
}
// projective component (might not to move)

View File

@@ -839,6 +839,10 @@ const char* CapabilityString(int info)
case 4437: return "DeviceGroup";
case 4439: return "MultiView";
#ifdef AMD_EXTENSIONS
case 5009: return "ImageGatherBiasLodAMD";
#endif
#ifdef NV_EXTENSIONS
case 5251: return "GeometryShaderPassthroughNV";
case 5254: return "ShaderViewportIndexLayerNV";