[SPIR-V] Fix tfetches with an offset
This commit is contained in:
parent
20099e51af
commit
516c113423
|
@ -1465,19 +1465,29 @@ void SpirvShaderTranslator::ProcessTextureFetchInstruction(
|
||||||
params.sampler = image;
|
params.sampler = image;
|
||||||
params.lod = b.makeIntConstant(0);
|
params.lod = b.makeIntConstant(0);
|
||||||
size = b.createTextureQueryCall(spv::Op::OpImageQuerySizeLod, params);
|
size = b.createTextureQueryCall(spv::Op::OpImageQuerySizeLod, params);
|
||||||
|
|
||||||
|
if (instr.dimension == TextureDimension::k1D) {
|
||||||
|
size = b.createUnaryOp(spv::Op::OpConvertSToF, float_type_, size);
|
||||||
|
} else if (instr.dimension == TextureDimension::k2D) {
|
||||||
|
size =
|
||||||
|
b.createUnaryOp(spv::Op::OpConvertSToF, vec2_float_type_, size);
|
||||||
|
} else if (instr.dimension == TextureDimension::k3D) {
|
||||||
|
size =
|
||||||
|
b.createUnaryOp(spv::Op::OpConvertSToF, vec3_float_type_, size);
|
||||||
|
} else if (instr.dimension == TextureDimension::kCube) {
|
||||||
|
size =
|
||||||
|
b.createUnaryOp(spv::Op::OpConvertSToF, vec4_float_type_, size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instr.dimension == TextureDimension::k1D) {
|
if (instr.dimension == TextureDimension::k1D) {
|
||||||
|
src = b.createCompositeExtract(src, float_type_, 0);
|
||||||
if (instr.attributes.offset_x) {
|
if (instr.attributes.offset_x) {
|
||||||
auto offset = b.makeCompositeConstant(
|
auto offset = b.makeFloatConstant(instr.attributes.offset_x + 0.5f);
|
||||||
vec2_float_type_,
|
offset = b.createBinOp(spv::Op::OpFDiv, float_type_, offset, size);
|
||||||
std::vector<Id>(
|
src = b.createBinOp(spv::Op::OpFAdd, float_type_, src, offset);
|
||||||
{b.makeFloatConstant(instr.attributes.offset_x + 0.5f),
|
|
||||||
b.makeFloatConstant(0.f)}));
|
|
||||||
offset =
|
|
||||||
b.createBinOp(spv::Op::OpFDiv, vec2_float_type_, offset, size);
|
|
||||||
src = b.createBinOp(spv::Op::OpFAdd, vec2_float_type_, src, offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/bb944006.aspx
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/bb944006.aspx
|
||||||
// "Because the runtime does not support 1D textures, the compiler will
|
// "Because the runtime does not support 1D textures, the compiler will
|
||||||
// use a 2D texture with the knowledge that the y-coordinate is
|
// use a 2D texture with the knowledge that the y-coordinate is
|
||||||
|
@ -1486,6 +1496,8 @@ void SpirvShaderTranslator::ProcessTextureFetchInstruction(
|
||||||
vec2_float_type_,
|
vec2_float_type_,
|
||||||
std::vector<Id>({src, b.makeFloatConstant(0.0f)}));
|
std::vector<Id>({src, b.makeFloatConstant(0.0f)}));
|
||||||
} else if (instr.dimension == TextureDimension::k2D) {
|
} else if (instr.dimension == TextureDimension::k2D) {
|
||||||
|
src = b.createRvalueSwizzle(spv::NoPrecision, vec2_float_type_, src,
|
||||||
|
std::vector<uint32_t>({0, 1}));
|
||||||
if (instr.attributes.offset_x || instr.attributes.offset_y) {
|
if (instr.attributes.offset_x || instr.attributes.offset_y) {
|
||||||
auto offset = b.makeCompositeConstant(
|
auto offset = b.makeCompositeConstant(
|
||||||
vec2_float_type_,
|
vec2_float_type_,
|
||||||
|
|
Loading…
Reference in New Issue