0003-Add-support-for-SPV_NV_shader_image_footprint

This commit is contained in:
Chao Chen
2018-09-19 11:41:27 -07:00
parent beae2251b7
commit 3a1379667d
13 changed files with 1189 additions and 5 deletions

View File

@@ -33,7 +33,7 @@ enum Op;
enum Capability;
static const int GLSLextNVVersion = 100;
static const int GLSLextNVRevision = 7;
static const int GLSLextNVRevision = 8;
//SPV_NV_sample_mask_override_coverage
const char* const E_SPV_NV_sample_mask_override_coverage = "SPV_NV_sample_mask_override_coverage";
@@ -60,4 +60,7 @@ const char* const E_SPV_NV_fragment_shader_barycentric = "SPV_NV_fragment_shader
//SPV_NV_compute_shader_derivatives
const char* const E_SPV_NV_compute_shader_derivatives = "SPV_NV_compute_shader_derivatives";
//SPV_NV_shader_image_footprint
const char* const E_SPV_NV_shader_image_footprint = "SPV_NV_shader_image_footprint";
#endif // #ifndef GLSLextNV_H

View File

@@ -3667,6 +3667,25 @@ void TGlslangToSpvTraverser::translateArguments(const glslang::TIntermAggregate&
if (i == 3)
lvalue = true;
break;
#endif
#ifdef NV_EXTENSIONS
case glslang::EOpImageSampleFootprintNV:
if (i == 4)
lvalue = true;
break;
case glslang::EOpImageSampleFootprintClampNV:
case glslang::EOpImageSampleFootprintLodNV:
if (i == 5)
lvalue = true;
break;
case glslang::EOpImageSampleFootprintGradNV:
if (i == 6)
lvalue = true;
break;
case glslang::EOpImageSampleFootprintGradClampNV:
if (i == 7)
lvalue = true;
break;
#endif
default:
break;
@@ -4020,6 +4039,10 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
// Check for texture functions other than queries
bool sparse = node->isSparseTexture();
#ifdef NV_EXTENSIONS
bool imageFootprint = node->isImageFootprint();
#endif
bool cubeCompare = sampler.dim == glslang::EsdCube && sampler.arrayed && sampler.shadow;
// check for bias argument
@@ -4049,7 +4072,12 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
++nonBiasArgCount;
if (sparse)
++nonBiasArgCount;
#ifdef NV_EXTENSIONS
if (imageFootprint)
//Following three extra arguments
// int granularity, bool coarse, out gl_TextureFootprint2DNV footprint
nonBiasArgCount += 3;
#endif
if ((int)arguments.size() > nonBiasArgCount)
bias = true;
}
@@ -4142,7 +4170,6 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
params.lodClamp = arguments[2 + extraArgs];
++extraArgs;
}
// sparse
if (sparse) {
params.texelOut = arguments[2 + extraArgs];
@@ -4158,13 +4185,81 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
} else
params.component = builder.makeIntConstant(0);
}
#ifdef NV_EXTENSIONS
spv::Id resultStruct = spv::NoResult;
if (imageFootprint) {
//Following three extra arguments
// int granularity, bool coarse, out gl_TextureFootprint2DNV footprint
params.granularity = arguments[2 + extraArgs];
params.coarse = arguments[3 + extraArgs];
resultStruct = arguments[4 + extraArgs];
extraArgs += 3;
}
#endif
// bias
if (bias) {
params.bias = arguments[2 + extraArgs];
++extraArgs;
}
#ifdef NV_EXTENSIONS
if (imageFootprint) {
builder.addExtension(spv::E_SPV_NV_shader_image_footprint);
builder.addCapability(spv::CapabilityImageFootprintNV);
//resultStructType(OpenGL type) contains 5 elements:
//struct gl_TextureFootprint2DNV {
// uvec2 anchor;
// uvec2 offset;
// uvec2 mask;
// uint lod;
// uint granularity;
//};
//or
//struct gl_TextureFootprint3DNV {
// uvec3 anchor;
// uvec3 offset;
// uvec2 mask;
// uint lod;
// uint granularity;
//};
spv::Id resultStructType = builder.getContainedTypeId(builder.getTypeId(resultStruct));
assert(builder.isStructType(resultStructType));
//resType (SPIR-V type) contains 6 elements:
//Member 0 must be a Boolean type scalar(LOD),
//Member 1 must be a vector of integer type, whose Signedness operand is 0(anchor),
//Member 2 must be a vector of integer type, whose Signedness operand is 0(offset),
//Member 3 must be a vector of integer type, whose Signedness operand is 0(mask),
//Member 4 must be a scalar of integer type, whose Signedness operand is 0(lod),
//Member 5 must be a scalar of integer type, whose Signedness operand is 0(granularity).
std::vector<spv::Id> members;
members.push_back(resultType());
for (int i = 0; i < 5; i++) {
members.push_back(builder.getContainedTypeId(resultStructType, i));
}
spv::Id resType = builder.makeStructType(members, "ResType");
//call ImageFootprintNV
spv::Id res = builder.createTextureCall(precision, resType, sparse, cracked.fetch, cracked.proj, cracked.gather, noImplicitLod, params);
//copy resType (SPIR-V type) to resultStructType(OpenGL type)
for (int i = 0; i < 5; i++) {
builder.clearAccessChain();
builder.setAccessChainLValue(resultStruct);
//Accessing to a struct we created, no coherent flag is set
spv::Builder::AccessChain::CoherentFlags flags;
flags.clear();
builder.accessChainPush(builder.makeIntConstant(i), flags);
builder.accessChainStore(builder.createCompositeExtract(res, builder.getContainedTypeId(resType, i+1), i+1));
}
return builder.createCompositeExtract(res, resultType(), 0);
}
#endif
// projective component (might not to move)
// GLSL: "The texture coordinates consumed from P, not including the last component of P,
// are divided by the last component of P."

View File

@@ -1654,6 +1654,13 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool sparse,
if (parameters.component != NoResult)
texArgs[numArgs++] = parameters.component;
#ifdef NV_EXTENSIONS
if (parameters.granularity != NoResult)
texArgs[numArgs++] = parameters.granularity;
if (parameters.coarse != NoResult)
texArgs[numArgs++] = parameters.coarse;
#endif
//
// Set up the optional arguments
//
@@ -1725,6 +1732,10 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool sparse,
opCode = OpImageSparseFetch;
else
opCode = OpImageFetch;
#ifdef NV_EXTENSIONS
} else if (parameters.granularity && parameters.coarse) {
opCode = OpImageSampleFootprintNV;
#endif
} else if (gather) {
if (parameters.Dref)
if (sparse)

View File

@@ -366,6 +366,10 @@ public:
Id component;
Id texelOut;
Id lodClamp;
#ifdef NV_EXTENSIONS
Id granularity;
Id coarse;
#endif
bool nonprivate;
bool volatil;
};

View File

@@ -1251,7 +1251,9 @@ const char* OpcodeString(int op)
#ifdef NV_EXTENSIONS
case OpGroupNonUniformPartitionNV: return "OpGroupNonUniformPartitionNV";
case OpImageSampleFootprintNV: return "OpImageSampleFootprintNV";
#endif
default:
return "Bad";
}
@@ -2596,6 +2598,12 @@ void Parameterize()
#ifdef NV_EXTENSIONS
InstructionDesc[OpGroupNonUniformPartitionNV].operands.push(OperandId, "X");
InstructionDesc[OpImageSampleFootprintNV].operands.push(OperandId, "'Sampled Image'");
InstructionDesc[OpImageSampleFootprintNV].operands.push(OperandId, "'Coordinate'");
InstructionDesc[OpImageSampleFootprintNV].operands.push(OperandId, "'Granularity'");
InstructionDesc[OpImageSampleFootprintNV].operands.push(OperandId, "'Coarse'");
InstructionDesc[OpImageSampleFootprintNV].operands.push(OperandImageOperands, "", true);
InstructionDesc[OpImageSampleFootprintNV].operands.push(OperandVariableIds, "", true);
#endif
}