[SPIR-V] Proper implementation of getGradients

This commit is contained in:
DrChat 2018-02-23 00:00:07 -06:00
parent 5a4dcd7043
commit 24baf58ae3
1 changed files with 12 additions and 17 deletions

View File

@ -1846,26 +1846,21 @@ void SpirvShaderTranslator::ProcessTextureFetchInstruction(
dest = b.createTextureCall(spv::NoPrecision, vec4_float_type_, false,
false, false, false, false, params);
} break;
case FetchOpcode::kGetTextureGradients: {
auto texture_index =
b.makeUintConstant(tex_binding_map_[instr.operands[2].storage_index]);
auto texture_ptr =
b.createAccessChain(spv::StorageClass::StorageClassUniformConstant,
tex_[dim_idx], std::vector<Id>({texture_index}));
auto texture = b.createLoad(texture_ptr);
Id src_x = b.createCompositeExtract(src, float_type_, 0);
Id src_y = b.createCompositeExtract(src, float_type_, 1);
Id grad = LoadFromOperand(instr.operands[1]);
Id gradX = b.createCompositeExtract(grad, float_type_, 0);
Id gradY = b.createCompositeExtract(grad, float_type_, 1);
spv::Builder::TextureParameters params = {0};
params.coords = src;
params.sampler = texture;
params.gradX = gradX;
params.gradY = gradY;
dest = b.createTextureCall(spv::NoPrecision, vec4_float_type_, false,
false, false, false, false, params);
dest = b.createCompositeConstruct(
vec4_float_type_,
{
b.createUnaryOp(spv::OpDPdx, float_type_, src_x),
b.createUnaryOp(spv::OpDPdy, float_type_, src_x),
b.createUnaryOp(spv::OpDPdx, float_type_, src_y),
b.createUnaryOp(spv::OpDPdy, float_type_, src_y),
});
} break;
case FetchOpcode::kGetTextureWeights: {
// fract(src0 * textureSize);
auto texture_index =