mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-12-26 11:22:33 -06:00
shader_recompiler: Use vector arithmetic rather than component-wise in ImageGatherSubpixelOffset
Should be more efficient and better readable
This commit is contained in:
parent
fe91066f46
commit
82b78cde73
1 changed files with 9 additions and 18 deletions
|
@ -266,30 +266,21 @@ Id ImageGatherSubpixelOffset(EmitContext& ctx, const IR::TextureInstInfo& info,
|
||||||
Id coords) {
|
Id coords) {
|
||||||
// Apply a subpixel offset of 1/512 the texel size of the texture to ensure same rounding on
|
// Apply a subpixel offset of 1/512 the texel size of the texture to ensure same rounding on
|
||||||
// AMD hardware as on Maxwell or other Nvidia architectures.
|
// AMD hardware as on Maxwell or other Nvidia architectures.
|
||||||
const auto calculate_offset{[&](size_t dim) -> std::array<Id, 2> {
|
const auto calculate_coords{[&](size_t dim) {
|
||||||
const Id nudge{ctx.Const(0x1p-9f)};
|
const Id nudge{ctx.Const(0x1p-9f)};
|
||||||
const Id image_size{ctx.OpImageQuerySizeLod(ctx.U32[dim], texture, ctx.u32_zero_value)};
|
const Id image_size{ctx.OpImageQuerySizeLod(ctx.U32[dim], texture, ctx.u32_zero_value)};
|
||||||
const Id offset_x{ctx.OpFDiv(
|
Id offset{dim == 2 ? ctx.ConstantComposite(ctx.F32[dim], nudge, nudge)
|
||||||
ctx.F32[1], nudge,
|
: ctx.ConstantComposite(ctx.F32[dim], nudge, nudge, ctx.f32_zero_value)};
|
||||||
ctx.OpConvertUToF(ctx.F32[1], ctx.OpCompositeExtract(ctx.U32[1], image_size, 0)))};
|
offset = ctx.OpFDiv(ctx.F32[dim], offset, ctx.OpConvertUToF(ctx.F32[dim], image_size));
|
||||||
const Id offset_y{ctx.OpFDiv(
|
return ctx.OpFAdd(ctx.F32[dim], coords, offset);
|
||||||
ctx.F32[1], nudge,
|
|
||||||
ctx.OpConvertUToF(ctx.F32[1], ctx.OpCompositeExtract(ctx.U32[1], image_size, 1)))};
|
|
||||||
return {ctx.OpFAdd(ctx.F32[1], ctx.OpCompositeExtract(ctx.F32[1], coords, 0), offset_x),
|
|
||||||
ctx.OpFAdd(ctx.F32[1], ctx.OpCompositeExtract(ctx.F32[1], coords, 1), offset_y)};
|
|
||||||
}};
|
}};
|
||||||
switch (info.type) {
|
switch (info.type) {
|
||||||
case TextureType::Color2D:
|
case TextureType::Color2D:
|
||||||
case TextureType::Color2DRect: {
|
case TextureType::Color2DRect:
|
||||||
const auto offset{calculate_offset(2)};
|
return calculate_coords(2);
|
||||||
return ctx.OpCompositeConstruct(ctx.F32[2], offset[0], offset[1]);
|
|
||||||
}
|
|
||||||
case TextureType::ColorArray2D:
|
case TextureType::ColorArray2D:
|
||||||
case TextureType::ColorCube: {
|
case TextureType::ColorCube:
|
||||||
const auto offset{calculate_offset(3)};
|
return calculate_coords(3);
|
||||||
return ctx.OpCompositeConstruct(ctx.F32[3], offset[0], offset[1],
|
|
||||||
ctx.OpCompositeExtract(ctx.F32[1], coords, 2));
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return coords;
|
return coords;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue