summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_image.cpp27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
index 968901d42..7d901c04b 100644
--- a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
@@ -266,30 +266,21 @@ Id ImageGatherSubpixelOffset(EmitContext& ctx, const IR::TextureInstInfo& info,
266 Id coords) { 266 Id coords) {
267 // Apply a subpixel offset of 1/512 the texel size of the texture to ensure same rounding on 267 // Apply a subpixel offset of 1/512 the texel size of the texture to ensure same rounding on
268 // AMD hardware as on Maxwell or other Nvidia architectures. 268 // AMD hardware as on Maxwell or other Nvidia architectures.
269 const auto calculate_offset{[&](size_t dim) -> std::array<Id, 2> { 269 const auto calculate_coords{[&](size_t dim) {
270 const Id nudge{ctx.Const(0x1p-9f)}; 270 const Id nudge{ctx.Const(0x1p-9f)};
271 const Id image_size{ctx.OpImageQuerySizeLod(ctx.U32[dim], texture, ctx.u32_zero_value)}; 271 const Id image_size{ctx.OpImageQuerySizeLod(ctx.U32[dim], texture, ctx.u32_zero_value)};
272 const Id offset_x{ctx.OpFDiv( 272 Id offset{dim == 2 ? ctx.ConstantComposite(ctx.F32[dim], nudge, nudge)
273 ctx.F32[1], nudge, 273 : ctx.ConstantComposite(ctx.F32[dim], nudge, nudge, ctx.f32_zero_value)};
274 ctx.OpConvertUToF(ctx.F32[1], ctx.OpCompositeExtract(ctx.U32[1], image_size, 0)))}; 274 offset = ctx.OpFDiv(ctx.F32[dim], offset, ctx.OpConvertUToF(ctx.F32[dim], image_size));
275 const Id offset_y{ctx.OpFDiv( 275 return ctx.OpFAdd(ctx.F32[dim], coords, offset);
276 ctx.F32[1], nudge,
277 ctx.OpConvertUToF(ctx.F32[1], ctx.OpCompositeExtract(ctx.U32[1], image_size, 1)))};
278 return {ctx.OpFAdd(ctx.F32[1], ctx.OpCompositeExtract(ctx.F32[1], coords, 0), offset_x),
279 ctx.OpFAdd(ctx.F32[1], ctx.OpCompositeExtract(ctx.F32[1], coords, 1), offset_y)};
280 }}; 276 }};
281 switch (info.type) { 277 switch (info.type) {
282 case TextureType::Color2D: 278 case TextureType::Color2D:
283 case TextureType::Color2DRect: { 279 case TextureType::Color2DRect:
284 const auto offset{calculate_offset(2)}; 280 return calculate_coords(2);
285 return ctx.OpCompositeConstruct(ctx.F32[2], offset[0], offset[1]);
286 }
287 case TextureType::ColorArray2D: 281 case TextureType::ColorArray2D:
288 case TextureType::ColorCube: { 282 case TextureType::ColorCube:
289 const auto offset{calculate_offset(3)}; 283 return calculate_coords(3);
290 return ctx.OpCompositeConstruct(ctx.F32[3], offset[0], offset[1],
291 ctx.OpCompositeExtract(ctx.F32[1], coords, 2));
292 }
293 default: 284 default:
294 return coords; 285 return coords;
295 } 286 }