mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-24 06:00:22 +01:00
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 <lionel.g.landwerlin@intel.com> Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39046>
This commit is contained in:
parent
f047f0b1be
commit
b52b1a08bf
5 changed files with 63 additions and 26 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
17
src/intel/blorp/blorp_shaders.cl
Normal file
17
src/intel/blorp/blorp_shaders.cl
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue