mesa/src
Lionel Landwerlin e25e17dd0c intel/fs: clamp per vertex input accesses to patchControlPoints
In a tesselation control shader where an input array is accessed using
the index gl_InvocationID, we can end up accessing elements beyond the
number of input vertices specified in the shader key.

This happens because of the lowering in nir_lower_indirect_derefs().
This lowering will affect compact variables which happens in this
case :

  in gl_PerVertex {
      vec4  gl_Position;
      float gl_ClipDistance[1];
  } gl_in[gl_MaxPatchVertices];

The lowered code produced by NIR is somewhat ineffecient (implements a
binary seach) :

  if (gl_InvocationID < 16) {
     if (gl_InvocationID < 8) {
        if (gl_InvocationID < 4) {
          vec4 vals = load_at_offset(0);
          value = bcsel(vals, gl_InvocationID);
        } else {
          vec4 vals = load_at_offset(4);
          value = bcsel(vals, gl_InvocationID - 4);
        }
     } else {
        if (gl_InvocationID < 12) {
          vec4 vals = load_at_offset(8);
          value = bcsel(vals, gl_InvocationID - 8);
        } else {
          vec4 vals = load_at_offset(12);
          value = bcsel(vals, gl_InvocationID - 12);
        }
     }
  } else {
     if (gl_InvocationID < 24) {
        ...
     } else {
        ...
     }
  }

By default the gl_MaxPatchVertices must be set at 32 items and that's
what the lowering code will use to divide the access into chunks of 4.
But when running with 3 input vertices, this means we'll pull one more
item than what was delivered in the shader payload.

This triggers issues further down the register scheduling where the
g5UD (register for the 4th item) is overwritten by a previous SEND,
leading the URB read to use an invalid handle.

This pass clamps any access load_per_vertex_input intrinsic vertex
indice to (input_vertices - 1).

Fixes issues with tests like :
dEQP-VK.clipping.user_defined.clip_distance.vert_tess.*

Also fixes a hang with zink/anv on :
KHR-GL46.draw_elements_base_vertex_tests.AEP_shader_stages

v2: Don't replace source register

v3: Implement in NIR

v4: Clamp per vertex array sizes in NIR (Jason)

v5: Move the clamping on the intel compiler

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9749>
2022-12-07 08:16:03 +00:00
..
amd radv: fix guardband if the polygon mode is points or lines 2022-12-06 19:30:51 +00:00
android_stub
asahi agx: Lower VBOs in NIR 2022-12-02 06:25:20 +00:00
broadcom v3dv: fix job serialization for single sync path 2022-12-01 14:08:56 +00:00
c11 c11: Remove _MTX_INITIALIZER_NP for windows 2022-11-09 04:38:28 +00:00
compiler nir: Use nir_component_mask_t for nir_alu_dst::write_mask 2022-12-06 18:37:19 -06:00
drm-shim drm-shim: drop gnu99 override 2022-09-16 02:06:38 +00:00
egl egl+glx: Always support no_error contexts. 2022-12-05 19:26:41 +00:00
etnaviv tree-wide: Use __func__ instead of __FUNCTION__ in non-gallium code 2022-11-22 06:53:46 +00:00
freedreno tu: Destroy disk_cache during tu_physical_device_finish 2022-12-06 19:06:50 +00:00
gallium zink: don't use defunct custom-flag 2022-12-06 22:09:46 +00:00
gbm dri: Add createNewScreen into the __DRI_MESA extension. 2022-12-05 19:26:41 +00:00
getopt
glx glx: fix xshm check to init xshm_opcode. 2022-12-06 22:31:14 +00:00
gtest gtest: Fix maybe-uninitialized compiler warning 2022-06-29 21:02:18 +00:00
hgl
imagination pvr: Add empty PDS program 2022-12-05 14:46:07 +00:00
imgui
intel intel/fs: clamp per vertex input accesses to patchControlPoints 2022-12-07 08:16:03 +00:00
loader dri: Introduce internal Mesa DRI driver loader extension. 2022-12-05 19:26:41 +00:00
mapi mapi: update gles 1.1 extention packet link 2022-11-20 15:14:01 +00:00
mesa mesa: Add missing dep on generated marshal header in the tests build. 2022-12-06 18:35:37 +00:00
microsoft dzn: Don't crash when libd3d12.so can't be found 2022-12-04 01:07:08 +00:00
nouveau drm-shim/nouveau: fix the shim to work with nvif ioctl. 2022-11-09 21:21:22 +00:00
panfrost panfrost: Enable AFBC of more formats 2022-12-01 02:03:15 +00:00
tool pps: make pps-producer RT only on freedreno 2022-11-15 21:21:42 +00:00
util meson: replace deprecated meson.get_cross_property(...) with meson.get_external_property(...) 2022-12-01 22:09:55 +00:00
virtio venus: check against the Vulkan type rather than type index. 2022-12-06 19:50:53 +00:00
vulkan vulkan: Use vk_image_sanitize_extent 2022-12-02 20:46:33 +00:00
meson.build meson: build radeon drm-shim also for r300 and r600 2022-11-16 14:37:47 +00:00