v3d/uniforms: update VIEWPORT_X/Y_SCALE uniforms for v71
authorAlejandro Piñeiro <apinheiro@igalia.com>
Thu, 21 Oct 2021 11:46:11 +0000 (13:46 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 13 Oct 2023 22:37:43 +0000 (22:37 +0000)
As the packet CLIPPER_XY scaling, this needs to be computed on 1/64ths
of pixel, instead of 1/256ths of pixels.

As this is the usual values that we get from macros, we add manually a
v42 and v71 macro, and define a new helper to get those.

Those granularity values are the same for Vulkan and OpenGL, so
perhaps we should move them to a common place.

As with v3dv, V3D_X macro name is somewhat confusing. It is
specifically created to ask for define values that depends on the
version. But I also felt that V3D_DEFINE_X was too long.

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25450>

src/gallium/drivers/v3d/v3d_context.h
src/gallium/drivers/v3d/v3d_uniforms.c

index 7754e676c886dbfdf76497d9f9d31158b84edf39..92c1faae6e59ba235ed834ded87c68d8a3cd123b 100644 (file)
@@ -842,6 +842,34 @@ void v3d_disk_cache_store(struct v3d_context *v3d,
         v3d_X_thing;                                            \
 })
 
+/* FIXME: The same for vulkan/opengl. Common place? define it at the
+ * v3d_packet files?
+ */
+#define V3D33_CLIPPER_XY_GRANULARITY 256.0f
+#define V3D42_CLIPPER_XY_GRANULARITY 256.0f
+#define V3D71_CLIPPER_XY_GRANULARITY 64.0f
+
+/* Helper to get hw-specific macro values */
+#define V3DV_X(devinfo, thing) ({                               \
+   __typeof(V3D33_##thing) V3D_X_THING;                         \
+   switch (devinfo->ver) {                                      \
+   case 33:                                                     \
+   case 40:                                                     \
+      V3D_X_THING = V3D33_##thing;                              \
+      break;                                                    \
+      case 41:                                                  \
+   case 42:                                                     \
+      V3D_X_THING = V3D42_##thing;                              \
+      break;                                                    \
+   case 71:                                                     \
+      V3D_X_THING = V3D71_##thing;                              \
+      break;                                                    \
+   default:                                                     \
+      unreachable("Unsupported hardware generation");           \
+   }                                                            \
+   V3D_X_THING;                                                 \
+})
+
 #ifdef v3dX
 #  include "v3dx_context.h"
 #else
index 95eb838954f1268aec75dd9c6a69be8cc31e5ef8..64c217d4f6c6ecd3b2c8dd34e0ded5f220b76624 100644 (file)
@@ -261,6 +261,7 @@ v3d_write_uniforms(struct v3d_context *v3d, struct v3d_job *job,
                    struct v3d_compiled_shader *shader,
                    enum pipe_shader_type stage)
 {
+        struct v3d_device_info *devinfo = &v3d->screen->devinfo;
         struct v3d_constbuf_stateobj *cb = &v3d->constbuf[stage];
         struct v3d_texture_stateobj *texstate = &v3d->tex[stage];
         struct v3d_uniform_list *uinfo = &shader->prog_data.base->uniforms;
@@ -292,13 +293,16 @@ v3d_write_uniforms(struct v3d_context *v3d, struct v3d_job *job,
                 case QUNIFORM_UNIFORM:
                         cl_aligned_u32(&uniforms, gallium_uniforms[data]);
                         break;
-                case QUNIFORM_VIEWPORT_X_SCALE:
-                        cl_aligned_f(&uniforms, v3d->viewport.scale[0] * 256.0f);
+                case QUNIFORM_VIEWPORT_X_SCALE: {
+                        float clipper_xy_granularity = V3DV_X(devinfo, CLIPPER_XY_GRANULARITY);
+                        cl_aligned_f(&uniforms, v3d->viewport.scale[0] * clipper_xy_granularity);
                         break;
-                case QUNIFORM_VIEWPORT_Y_SCALE:
-                        cl_aligned_f(&uniforms, v3d->viewport.scale[1] * 256.0f);
+                }
+                case QUNIFORM_VIEWPORT_Y_SCALE: {
+                        float clipper_xy_granularity = V3DV_X(devinfo, CLIPPER_XY_GRANULARITY);
+                        cl_aligned_f(&uniforms, v3d->viewport.scale[1] * clipper_xy_granularity);
                         break;
-
+                }
                 case QUNIFORM_VIEWPORT_Z_OFFSET:
                         cl_aligned_f(&uniforms, v3d->viewport.translate[2]);
                         break;