rusticl: add support for coherent resources

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18793>
This commit is contained in:
Karol Herbst 2022-09-22 15:05:14 +02:00 committed by Marge Bot
parent a5e9e64aae
commit 557f4dd89a
4 changed files with 51 additions and 8 deletions

View file

@ -6,6 +6,7 @@ use crate::core::util::*;
use crate::impl_cl_type_trait;
use mesa_rust::pipe::resource::*;
use mesa_rust::pipe::screen::ResourceType;
use mesa_rust_util::properties::Properties;
use rusticl_opencl_gen::*;
@ -55,7 +56,9 @@ impl Context {
}
if resource.is_none() {
resource = dev.screen().resource_create_buffer(adj_size)
resource = dev
.screen()
.resource_create_buffer(adj_size, ResourceType::Normal)
}
let resource = resource.ok_or(CL_OUT_OF_RESOURCES);
@ -113,9 +116,15 @@ impl Context {
}
if resource.is_none() {
resource = dev
.screen()
.resource_create_texture(width, height, depth, array_size, target, format)
resource = dev.screen().resource_create_texture(
width,
height,
depth,
array_size,
target,
format,
ResourceType::Normal,
)
}
let resource = resource.ok_or(CL_OUT_OF_RESOURCES);

View file

@ -11,6 +11,7 @@ use crate::impl_cl_type_trait;
use mesa_rust::compiler::clc::*;
use mesa_rust::compiler::nir::*;
use mesa_rust::pipe::context::RWFlags;
use mesa_rust::pipe::screen::ResourceType;
use mesa_rust_gen::*;
use mesa_rust_util::math::*;
use mesa_rust_util::serialize::*;
@ -848,7 +849,7 @@ impl Kernel {
let res = Arc::new(
q.device
.screen()
.resource_create_buffer(buf.len() as u32)
.resource_create_buffer(buf.len() as u32, ResourceType::Normal)
.unwrap(),
);
q.device
@ -863,8 +864,12 @@ impl Kernel {
input.extend_from_slice(&cl_prop::<[u64; 3]>(offsets));
}
InternalKernelArgType::PrintfBuffer => {
let buf =
Arc::new(q.device.screen.resource_create_buffer(printf_size).unwrap());
let buf = Arc::new(
q.device
.screen
.resource_create_buffer(printf_size, ResourceType::Normal)
.unwrap(),
);
input.extend_from_slice(&[0; 8]);
resource_info.push((Some(buf.clone()), arg.offset));

View file

@ -59,6 +59,24 @@ impl ComputeParam<Vec<u64>> for PipeScreen {
}
}
#[derive(Clone, Copy)]
pub enum ResourceType {
Normal,
Staging,
}
impl ResourceType {
fn apply(&self, tmpl: &mut pipe_resource) {
match self {
Self::Staging => {
tmpl.set_usage(pipe_resource_usage::PIPE_USAGE_STAGING.0);
tmpl.flags |= PIPE_RESOURCE_FLAG_MAP_PERSISTENT | PIPE_RESOURCE_FLAG_MAP_COHERENT;
}
Self::Normal => {}
}
}
}
impl PipeScreen {
pub(super) fn new(ldev: PipeLoaderDevice, screen: *mut pipe_screen) -> Option<Arc<Self>> {
if screen.is_null() || !has_required_cbs(screen) {
@ -102,7 +120,11 @@ impl PipeScreen {
}
}
pub fn resource_create_buffer(&self, size: u32) -> Option<PipeResource> {
pub fn resource_create_buffer(
&self,
size: u32,
res_type: ResourceType,
) -> Option<PipeResource> {
let mut tmpl = pipe_resource::default();
tmpl.set_target(pipe_texture_target::PIPE_BUFFER);
@ -112,6 +134,8 @@ impl PipeScreen {
tmpl.array_size = 1;
tmpl.bind = PIPE_BIND_GLOBAL;
res_type.apply(&mut tmpl);
self.resource_create(&tmpl)
}
@ -140,6 +164,7 @@ impl PipeScreen {
array_size: u16,
target: pipe_texture_target,
format: pipe_format,
res_type: ResourceType,
) -> Option<PipeResource> {
let mut tmpl = pipe_resource::default();
@ -151,6 +176,8 @@ impl PipeScreen {
tmpl.array_size = array_size;
tmpl.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE;
res_type.apply(&mut tmpl);
self.resource_create(&tmpl)
}

View file

@ -228,6 +228,8 @@ rusticl_mesa_bindings_rs = rust.bindgen(
'--allowlist-function', 'u_.*',
'--allowlist-function', 'util_format_.*',
'--allowlist-type', 'pipe_endian',
'--allowlist-type', 'pipe_resource_usage',
'--bitfield-enum', 'pipe_resource_usage',
'--allowlist-type', 'clc_kernel_arg_access_qualifier',
'--bitfield-enum', 'clc_kernel_arg_access_qualifier',
'--allowlist-type', 'clc_kernel_arg_type_qualifier',