spirv: Add 0.5 to integer coordinates for OpImageSampleExplicitLod
Just casting to a float is insufficient because that gives us the upper-left corner
of the texel rather than the center.
Fixes: 701cb9d60c03 "nir/vtn: Handle integer sampling coordinates"
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7069>
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index d88ae4c..ec976c4 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -2661,7 +2661,9 @@
"Unless the Kernel capability is being used, the coordinate parameter "
"OpImageSampleExplicitLod must be floating point.");
- p->src = nir_src_for_ssa(nir_i2f32(&b->nb, p->src.ssa));
+ p->src = nir_src_for_ssa(
+ nir_fadd(&b->nb, nir_i2f32(&b->nb, p->src.ssa),
+ nir_imm_float(&b->nb, 0.5)));
}
p->src_type = nir_tex_src_coord;