rusticl/kernel: inline samplers

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15439>
This commit is contained in:
Karol Herbst 2022-03-30 05:01:50 +02:00 committed by Marge Bot
parent 0423f0701e
commit 25b8a34b48
3 changed files with 82 additions and 6 deletions

View file

@ -51,6 +51,7 @@ pub enum InternalKernelArgType {
ConstantBuffer,
GlobalWorkOffsets,
PrintfBuffer,
InlineSampler((cl_addressing_mode, cl_filter_mode, bool)),
}
#[derive(Clone)]
@ -274,7 +275,34 @@ fn lower_and_optimize_nir_late(
&dv_opts,
);
// TODO inline samplers
// asign locations for inline samplers
let mut last_loc = -1;
for v in nir
.variables_with_mode(nir_variable_mode::nir_var_uniform | nir_variable_mode::nir_var_image)
{
if unsafe { !glsl_type_is_sampler(v.type_) } {
last_loc = v.data.location;
continue;
}
let s = unsafe { v.data.anon_1.sampler };
if s.is_inline_sampler() != 0 {
last_loc += 1;
v.data.location = last_loc;
res.push(InternalKernelArg {
kind: InternalKernelArgType::InlineSampler(Sampler::nir_to_cl(
s.addressing_mode(),
s.filter_mode(),
s.normalized_coordinates(),
)),
offset: 0,
size: 0,
});
} else {
last_loc = v.data.location;
}
}
nir.pass1(nir_lower_readonly_images_to_tex, false);
nir.pass0(nir_lower_cl_images);
@ -497,7 +525,9 @@ impl Kernel {
let mut printf_buf = None;
for arg in &self.internal_args {
input.append(&mut vec![0; arg.offset - input.len()]);
if arg.offset > input.len() {
input.resize(arg.offset, 0);
}
match arg.kind {
InternalKernelArgType::ConstantBuffer => {
input.extend_from_slice(&[0; 8]);
@ -528,6 +558,9 @@ impl Kernel {
printf_buf = Some(buf);
}
InternalKernelArgType::InlineSampler(cl) => {
samplers.push(Sampler::cl_to_pipe(cl));
}
}
}

View file

@ -878,10 +878,43 @@ impl Sampler {
})
}
pub fn pipe(&self) -> pipe_sampler_state {
pub fn nir_to_cl(
addressing_mode: u32,
filter_mode: u32,
normalized_coords: u32,
) -> (cl_addressing_mode, cl_filter_mode, bool) {
let addr_mode = match addressing_mode {
cl_sampler_addressing_mode::SAMPLER_ADDRESSING_MODE_NONE => CL_ADDRESS_NONE,
cl_sampler_addressing_mode::SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE => {
CL_ADDRESS_CLAMP_TO_EDGE
}
cl_sampler_addressing_mode::SAMPLER_ADDRESSING_MODE_CLAMP => CL_ADDRESS_CLAMP,
cl_sampler_addressing_mode::SAMPLER_ADDRESSING_MODE_REPEAT => CL_ADDRESS_REPEAT,
cl_sampler_addressing_mode::SAMPLER_ADDRESSING_MODE_REPEAT_MIRRORED => {
CL_ADDRESS_MIRRORED_REPEAT
}
_ => panic!("unkown addressing_mode"),
};
let filter = match filter_mode {
cl_sampler_filter_mode::SAMPLER_FILTER_MODE_NEAREST => CL_FILTER_NEAREST,
cl_sampler_filter_mode::SAMPLER_FILTER_MODE_LINEAR => CL_FILTER_LINEAR,
_ => panic!("unkown filter_mode"),
};
(addr_mode, filter, normalized_coords != 0)
}
pub fn cl_to_pipe(
(addressing_mode, filter_mode, normalized_coords): (
cl_addressing_mode,
cl_filter_mode,
bool,
),
) -> pipe_sampler_state {
let mut res = pipe_sampler_state::default();
let wrap = match self.addressing_mode {
let wrap = match addressing_mode {
CL_ADDRESS_CLAMP_TO_EDGE => pipe_tex_wrap::PIPE_TEX_WRAP_CLAMP_TO_EDGE,
CL_ADDRESS_CLAMP => pipe_tex_wrap::PIPE_TEX_WRAP_CLAMP_TO_BORDER,
CL_ADDRESS_REPEAT => pipe_tex_wrap::PIPE_TEX_WRAP_REPEAT,
@ -890,7 +923,7 @@ impl Sampler {
_ => pipe_tex_wrap::PIPE_TEX_WRAP_CLAMP_TO_EDGE,
};
let img_filter = match self.filter_mode {
let img_filter = match filter_mode {
CL_FILTER_NEAREST => pipe_tex_filter::PIPE_TEX_FILTER_NEAREST,
CL_FILTER_LINEAR => pipe_tex_filter::PIPE_TEX_FILTER_LINEAR,
_ => panic!("unkown filter_mode"),
@ -898,11 +931,19 @@ impl Sampler {
res.set_min_img_filter(img_filter);
res.set_mag_img_filter(img_filter);
res.set_normalized_coords(self.normalized_coords.into());
res.set_normalized_coords(normalized_coords.into());
res.set_wrap_r(wrap);
res.set_wrap_s(wrap);
res.set_wrap_t(wrap);
res
}
pub fn pipe(&self) -> pipe_sampler_state {
Self::cl_to_pipe((
self.addressing_mode,
self.filter_mode,
self.normalized_coords,
))
}
}

View file

@ -220,6 +220,8 @@ rusticl_mesa_bindings_rs = rust.bindgen(
'--constified-enum-module', 'pipe_tex_filter',
'--allowlist-type', 'gl_access_qualifier',
'--bitfield-enum', 'gl_access_qualifier',
'--allowlist-type', 'cl_sampler_.*_mode',
'--constified-enum-module', 'cl_sampler_.*_mode',
],
)