mesa/src/intel/blorp/blorp_nir_builder.h
Paulo Zanoni b52b1a08bf 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>
2026-01-15 04:34:55 +00:00

109 lines
3.7 KiB
C

/*
* Copyright © 2017 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "dev/intel_device_info.h"
#include "compiler/nir/nir_builder.h"
#include "blorp_priv.h"
static inline void
blorp_nir_init_shader(nir_builder *b,
struct blorp_context *blorp,
void *mem_ctx,
mesa_shader_stage stage,
const char *name)
{
const nir_shader_compiler_options *nir_options =
blorp->compiler->nir_options(blorp, stage);
*b = nir_builder_init_simple_shader(stage, nir_options,
"%s", name ? name : "");
ralloc_steal(mem_ctx, b->shader);
if (stage == MESA_SHADER_FRAGMENT)
b->shader->info.fs.origin_upper_left = true;
}
static inline nir_def *
blorp_nir_txf_ms_mcs(nir_builder *b, nir_def *xy_pos, nir_def *layer,
const struct intel_device_info *devinfo)
{
nir_tex_instr *tex = nir_tex_instr_create(b->shader, 1);
tex->op = nir_texop_txf_ms_mcs_intel;
tex->sampler_dim = GLSL_SAMPLER_DIM_MS;
tex->dest_type = nir_type_int32;
nir_def *coord;
if (layer) {
tex->is_array = true;
tex->coord_components = 3;
coord = nir_vec3(b, nir_channel(b, xy_pos, 0),
nir_channel(b, xy_pos, 1),
layer);
} else {
tex->is_array = false;
tex->coord_components = 2;
coord = nir_trim_vector(b, xy_pos, 2);
}
tex->src[0] = nir_tex_src_for_ssa(
nir_tex_src_coord,
devinfo->verx10 >= 125 ? nir_u2u16(b, coord) : coord);
/* Blorp only has one texture and it's bound at unit 0 */
tex->texture_index = 0;
tex->sampler_index = 0;
nir_def_init(&tex->instr, &tex->def, 4, 32);
nir_builder_instr_insert(b, &tex->instr);
return &tex->def;
}
static inline nir_def *
blorp_nir_mcs_is_clear_color(nir_builder *b,
nir_def *mcs,
uint32_t samples)
{
switch (samples) {
case 2:
/* Empirical evidence suggests that the value returned from the
* sampler is not always 0x3 for clear color so we need to mask it.
*/
return nir_ieq_imm(b, nir_iand(b, nir_channel(b, mcs, 0),
nir_imm_int(b, 0x3)),
0x3);
case 4:
return nir_ieq_imm(b, nir_channel(b, mcs, 0), 0xff);
case 8:
return nir_ieq_imm(b, nir_channel(b, mcs, 0), ~0);
case 16:
/* For 16x MSAA, the MCS is actually an ivec2 */
return nir_iand(b, nir_ieq_imm(b, nir_channel(b, mcs, 0), ~0),
nir_ieq_imm(b, nir_channel(b, mcs, 1), ~0));
default:
UNREACHABLE("Invalid sample count");
}
}