From b52b1a08bfa93d757f39cef0df46ff3cec8ff96d Mon Sep 17 00:00:00 2001 From: Paulo Zanoni Date: Wed, 17 Dec 2025 16:44:31 -0800 Subject: [PATCH] intel/blorp: add blorp_shaders.cl This gives us the infrastructure that allows us to slowly migrate pieces of blorp shaders from NIR to OpenCL, which, IMHO, are much easier to read. We can't fully migrate everything due to all the conditional building we do with these shaders, but I'm sure we'll find opportunities to replace some NIR with OpenCL eventually. The conversion of blorp_check_in_bounds() serves as the first example. I also plan to have the shaders from the new indirect copy extension be OpenCL shaders (mixed with some NIR as well), so having this patch merged now will reduce the diff for the extension later. Thanks to Alyssa Rosenzweig for her help here. v2: - Use SPDX (Alyssa). - Use nir_trim_vector() (Alyssa). - Adjust CL variable declaration (Alyssa). Reviewed-by: Lionel Landwerlin Signed-off-by: Paulo Zanoni Part-of: --- src/intel/blorp/blorp_blit.c | 6 +++-- src/intel/blorp/blorp_clear.c | 4 ++- src/intel/blorp/blorp_nir_builder.h | 21 --------------- src/intel/blorp/blorp_shaders.cl | 17 ++++++++++++ src/intel/blorp/meson.build | 41 +++++++++++++++++++++++++++-- 5 files changed, 63 insertions(+), 26 deletions(-) create mode 100644 src/intel/blorp/blorp_shaders.cl diff --git a/src/intel/blorp/blorp_blit.c b/src/intel/blorp/blorp_blit.c index 8e325da23ab..cb91371ead3 100644 --- a/src/intel/blorp/blorp_blit.c +++ b/src/intel/blorp/blorp_blit.c @@ -25,6 +25,7 @@ #include "compiler/nir/nir_format_convert.h" #include "blorp_priv.h" +#include "blorp_shaders.h" #include "dev/intel_debug.h" #include "dev/intel_device_info.h" @@ -1285,8 +1286,9 @@ blorp_build_nir_shader(struct blorp_context *blorp, nir_if *bounds_if = NULL; if (key->use_kill) { nir_def *bounds_rect = nir_load_var(&b, v.v_bounds_rect); - nir_def *in_bounds = blorp_check_in_bounds(&b, bounds_rect, - dst_pos); + nir_def *in_bounds = + blorp_check_in_bounds(&b, bounds_rect, + nir_trim_vector(&b, dst_pos, 2)); if (!compute) nir_discard_if(&b, nir_inot(&b, in_bounds)); else diff --git a/src/intel/blorp/blorp_clear.c b/src/intel/blorp/blorp_clear.c index 68b00a5b653..329161da55b 100644 --- a/src/intel/blorp/blorp_clear.c +++ b/src/intel/blorp/blorp_clear.c @@ -29,6 +29,7 @@ #include "util/u_math.h" #include "blorp_priv.h" +#include "blorp_shaders.h" #include "dev/intel_debug.h" #include "dev/intel_device_info.h" @@ -165,7 +166,8 @@ blorp_params_get_clear_kernel_cs(struct blorp_batch *batch, nir_variable *v_bounds_rect = BLORP_CREATE_NIR_INPUT(b.shader, clear.bounds_rect, glsl_vec4_type()); nir_def *bounds_rect = nir_load_var(&b, v_bounds_rect); - nir_def *in_bounds = blorp_check_in_bounds(&b, bounds_rect, dst_pos); + nir_def *in_bounds = + blorp_check_in_bounds(&b, bounds_rect, nir_trim_vector(&b, dst_pos, 2)); if (clear_rgb_as_red) { nir_def *comp = nir_umod_imm(&b, nir_channel(&b, dst_pos, 0), 3); diff --git a/src/intel/blorp/blorp_nir_builder.h b/src/intel/blorp/blorp_nir_builder.h index 1dbd29b73b8..e3702cbbe78 100644 --- a/src/intel/blorp/blorp_nir_builder.h +++ b/src/intel/blorp/blorp_nir_builder.h @@ -107,24 +107,3 @@ blorp_nir_mcs_is_clear_color(nir_builder *b, UNREACHABLE("Invalid sample count"); } } - -static inline nir_def * -blorp_check_in_bounds(nir_builder *b, - nir_def *bounds_rect, - nir_def *pos) -{ - nir_def *x0 = nir_channel(b, bounds_rect, 0); - nir_def *x1 = nir_channel(b, bounds_rect, 1); - nir_def *y0 = nir_channel(b, bounds_rect, 2); - nir_def *y1 = nir_channel(b, bounds_rect, 3); - - nir_def *c0 = nir_uge(b, nir_channel(b, pos, 0), x0); - nir_def *c1 = nir_ult(b, nir_channel(b, pos, 0), x1); - nir_def *c2 = nir_uge(b, nir_channel(b, pos, 1), y0); - nir_def *c3 = nir_ult(b, nir_channel(b, pos, 1), y1); - - nir_def *in_bounds = - nir_iand(b, nir_iand(b, c0, c1), nir_iand(b, c2, c3)); - - return in_bounds; -} diff --git a/src/intel/blorp/blorp_shaders.cl b/src/intel/blorp/blorp_shaders.cl new file mode 100644 index 00000000000..08dd30a37f9 --- /dev/null +++ b/src/intel/blorp/blorp_shaders.cl @@ -0,0 +1,17 @@ +/* Copyright © 2025 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#include "compiler/libcl/libcl.h" +#include "compiler/nir/nir_defines.h" +#include "compiler/shader_enums.h" + +bool +blorp_check_in_bounds(uint4 bounds_rect, uint2 pos) +{ + uint x0 = bounds_rect[0], x1 = bounds_rect[1]; + uint y0 = bounds_rect[2], y1 = bounds_rect[3]; + + return pos.x >= x0 && pos.x < x1 && + pos.y >= y0 && pos.y < y1; +} diff --git a/src/intel/blorp/meson.build b/src/intel/blorp/meson.build index bf4e2c4b093..1b82cc5ce1f 100644 --- a/src/intel/blorp/meson.build +++ b/src/intel/blorp/meson.build @@ -1,6 +1,37 @@ # Copyright © 2017 Intel Corporation # SPDX-License-Identifier: MIT +blorp_shader_files = files( + 'blorp_shaders.cl', +) + +blorp_shaders_spv = custom_target( + input : blorp_shader_files, + output : 'blorp_shaders.spv', + command : [ + prog_mesa_clc, '-o', '@OUTPUT@', '--depfile', '@DEPFILE@', + blorp_shader_files, '--', + '-I' + join_paths(meson.project_source_root(), 'include'), + '-I' + join_paths(meson.project_source_root(), 'src/compiler/libcl'), + '-I' + join_paths(meson.project_source_root(), 'src'), + '-I' + join_paths(meson.current_source_dir(), '.'), + cl_args, + ], + depends : [gen_cl_xml_pack], + depfile : 'blorp_shaders.h.d', +) + +blorp_shaders = custom_target( + input : blorp_shaders_spv, + output : ['blorp_shaders.cpp', 'blorp_shaders.h'], + command : [prog_vtn_bindgen2, blorp_shaders_spv, '@OUTPUT0@', '@OUTPUT1@'], +) + +idep_blorp_shaders = declare_dependency( + sources : [blorp_shaders], + include_directories : include_directories('.'), +) + files_libblorp = files( 'blorp.c', 'blorp.h', @@ -26,7 +57,10 @@ libblorp = static_library( include_directories : [inc_include, inc_src, inc_intel, inc_intel_compiler], c_args : [no_override_init_args], gnu_symbol_visibility : 'hidden', - dependencies : [idep_nir_headers, idep_genxml, idep_mesautil, idep_intel_dev], + dependencies : [ + idep_nir_headers, idep_genxml, idep_mesautil, idep_intel_dev, + idep_blorp_shaders + ], build_by_default: false, ) @@ -41,7 +75,10 @@ if with_intel_elk include_directories : [inc_include, inc_src, inc_intel], c_args : [no_override_init_args], gnu_symbol_visibility : 'hidden', - dependencies : [idep_nir_headers, idep_genxml, idep_mesautil, idep_intel_dev], + dependencies : [ + idep_nir_headers, idep_genxml, idep_mesautil, idep_intel_dev, + idep_blorp_shaders + ], build_by_default: true, # FIXME XXX )