From de5d767f9a8d92f47a5fae06390a5d32ccd42735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Fri, 19 Jul 2024 10:55:59 -0700 Subject: [PATCH] intel/brw: Add a maximum scratch size restriction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gfx 12.5 moved scratch to a surface and SURFTYPE_SCRATCH has this pitch restriction: RENDER_SURFACE_STATE::Surface Pitch For surfaces of type SURFTYPE_SCRATCH, valid range of pitch is: [63,262143] -> [64B, 256KB] The pitch of the surface is the scratch size per thread and the surface should be large enough to accommodate every physical thread. So here adding a new field to intel_device_info, setting it in intel_device_info_init_common() so even offline tools can have it set. And finally adding a check to fail shader compilation if needed scratch is larger than supported. This issue can be reproduced in debug builds when running dEQP-VK.protected_memory.stack.stacksize_1024 on Gfx 12.5 or newer platforms. Ref: BSpec 43862 (r52666) Reviewed-by: Lionel Landwerlin Signed-off-by: José Roberto de Souza Part-of: --- src/intel/compiler/brw_fs.cpp | 22 +++++++++++++--------- src/intel/dev/intel_device_info.c | 14 ++++++++++++++ src/intel/dev/intel_device_info.py | 2 ++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/intel/compiler/brw_fs.cpp b/src/intel/compiler/brw_fs.cpp index 123dc6dba7b..a3f0d172781 100644 --- a/src/intel/compiler/brw_fs.cpp +++ b/src/intel/compiler/brw_fs.cpp @@ -2940,14 +2940,6 @@ fs_visitor::allocate_registers(bool allow_spilling) debug_optimizer(nir, "lowered_vgrfs_to_fixed_grfs", 96, 3); if (last_scratch > 0) { - ASSERTED unsigned max_scratch_size = 2 * 1024 * 1024; - - /* Take the max of any previously compiled variant of the shader. In the - * case of bindless shaders with return parts, this will also take the - * max of all parts. - */ - prog_data->total_scratch = MAX2(brw_get_scratch_size(last_scratch), - prog_data->total_scratch); /* We currently only support up to 2MB of scratch space. If we * need to support more eventually, the documentation suggests @@ -2959,9 +2951,21 @@ fs_visitor::allocate_registers(bool allow_spilling) * See 3D-Media-GPGPU Engine > Media GPGPU Pipeline > * Thread Group Tracking > Local Memory/Scratch Space. */ - assert(prog_data->total_scratch < max_scratch_size); + if (last_scratch <= devinfo->max_scratch_size_per_thread) { + /* Take the max of any previously compiled variant of the shader. In the + * case of bindless shaders with return parts, this will also take the + * max of all parts. + */ + prog_data->total_scratch = MAX2(brw_get_scratch_size(last_scratch), + prog_data->total_scratch); + } else { + fail("Scratch space required is larger than supported"); + } } + if (failed) + return; + brw_fs_lower_scoreboard(*this); } diff --git a/src/intel/dev/intel_device_info.c b/src/intel/dev/intel_device_info.c index f8eca0cca85..c0f87653eaf 100644 --- a/src/intel/dev/intel_device_info.c +++ b/src/intel/dev/intel_device_info.c @@ -1615,6 +1615,20 @@ intel_device_info_init_common(int pci_id, bool building, devinfo->max_constant_urb_size_kb / 2; } + /* + * Gfx 12.5 moved scratch to a surface and SURFTYPE_SCRATCH has this pitch + * restriction: + * + * BSpec 43862 (r52666) + * RENDER_SURFACE_STATE::Surface Pitch + * For surfaces of type SURFTYPE_SCRATCH, valid range of pitch is: + * [63,262143] -> [64B, 256KB] + * + * The pitch of the surface is the scratch size per thread and the surface + * should be large enough to accommodate every physical thread. + */ + devinfo->max_scratch_size_per_thread = devinfo->verx10 >= 125 ? + (256 * 1024) : (2 * 1024 * 1024); intel_device_info_update_cs_workgroup_threads(devinfo); return true; diff --git a/src/intel/dev/intel_device_info.py b/src/intel/dev/intel_device_info.py index 39d42edb9c7..0f0bec49b7b 100644 --- a/src/intel/dev/intel_device_info.py +++ b/src/intel/dev/intel_device_info.py @@ -467,6 +467,8 @@ Struct("intel_device_info", implementation details, the range of scratch ids may be larger than the number of subslices.""")), + Member("uint32_t", "max_scratch_size_per_thread", compiler_field=True), + Member("intel_device_info_urb_desc", "urb"), Member("unsigned", "max_constant_urb_size_kb"), Member("unsigned", "mesh_max_constant_urb_size_kb"),