[SPIR-V] (untested) Implementation of getGradients

This commit is contained in:
DrChat 2017-10-01 18:59:54 -05:00
parent 2a3c66484e
commit a7b6d91a2b
1 changed files with 21 additions and 2 deletions

View File

@ -996,7 +996,7 @@ void SpirvShaderTranslator::ProcessAllocInstruction(
// Already included, nothing to do here. // Already included, nothing to do here.
} break; } break;
case AllocType::kMemory: { case AllocType::kMemory: {
assert_always(); // Nothing to do for this.
} break; } break;
default: default:
break; break;
@ -1357,6 +1357,25 @@ void SpirvShaderTranslator::ProcessTextureFetchInstruction(
dest = b.createTextureCall(spv::NoPrecision, vec4_float_type_, false, dest = b.createTextureCall(spv::NoPrecision, vec4_float_type_, false,
false, false, false, false, params); false, false, false, false, params);
} break; } break;
case FetchOpcode::kGetTextureGradients: {
auto texture_index = b.makeUintConstant(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 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);
} break;
case FetchOpcode::kGetTextureWeights: { case FetchOpcode::kGetTextureWeights: {
// fract(src0 * textureSize); // fract(src0 * textureSize);
auto texture_index = b.makeUintConstant(instr.operands[1].storage_index); auto texture_index = b.makeUintConstant(instr.operands[1].storage_index);
@ -1397,7 +1416,7 @@ void SpirvShaderTranslator::ProcessTextureFetchInstruction(
} break; } break;
case FetchOpcode::kSetTextureLod: { case FetchOpcode::kSetTextureLod: {
// <lod register> = src1.x // <lod register> = src1.x (MIP level)
// ... immediately after // ... immediately after
// tfetch UseRegisterLOD=true // tfetch UseRegisterLOD=true
} break; } break;