use crate::api::icd::*;
use crate::core::device::*;
+use crate::core::format::*;
use crate::core::memory::*;
use crate::core::util::*;
use crate::impl_cl_type_trait;
use mesa_rust::pipe::resource::*;
use mesa_rust::pipe::screen::ResourceType;
-use mesa_rust_gen::*;
use mesa_rust_util::properties::Properties;
use rusticl_opencl_gen::*;
pub fn create_texture(
&self,
desc: &cl_image_desc,
- format: pipe_format,
+ format: &cl_image_format,
user_ptr: *mut c_void,
copy: bool,
res_type: ResourceType,
) -> CLResult<HashMap<&'static Device, Arc<PipeResource>>> {
+ let pipe_format = format.to_pipe_format().unwrap();
+
let width = desc
.image_width
.try_into()
let mut res = HashMap::new();
for &dev in &self.devs {
let mut resource = None;
+ let enable_bind_as_image =
+ (dev.formats[format][&desc.image_type] as u32 & CL_MEM_WRITE_ONLY) != 0;
// we can't specify custom pitches/slices, so this won't work for non 1D images
if !user_ptr.is_null() && !copy && desc.image_type == CL_MEM_OBJECT_IMAGE1D {
resource = dev.screen().resource_create_texture_from_user(
- width, height, depth, array_size, target, format, user_ptr,
+ width,
+ height,
+ depth,
+ array_size,
+ target,
+ pipe_format,
+ user_ptr,
+ enable_bind_as_image,
)
}
if resource.is_none() {
resource = dev.screen().resource_create_texture(
- width, height, depth, array_size, target, format, res_type,
+ width,
+ height,
+ depth,
+ array_size,
+ target,
+ pipe_format,
+ res_type,
+ enable_bind_as_image,
)
}
ResourceType::Normal
};
- let pipe_format = image_format.to_pipe_format().unwrap();
let texture = if parent.is_none() {
Some(context.create_texture(
&image_desc,
- pipe_format,
+ image_format,
host_ptr,
bit_check(flags, CL_MEM_COPY_HOST_PTR),
res_type,
ptr::null_mut()
};
+ let pipe_format = image_format.to_pipe_format().unwrap();
Ok(Arc::new(Self {
base: CLObjectBase::new(),
context: context,
cl_mem_type_to_texture_target(self.image_desc.image_type),
self.pipe_format,
ResourceType::Staging,
+ false,
)
.ok_or(CL_OUT_OF_RESOURCES)?;
let tx = ctx.texture_map_coherent(&shadow, bx, rw);
target: pipe_texture_target,
format: pipe_format,
res_type: ResourceType,
+ support_image: bool,
) -> Option<PipeResource> {
let mut tmpl = pipe_resource::default();
tmpl.height0 = height;
tmpl.depth0 = depth;
tmpl.array_size = array_size;
- tmpl.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE;
+ tmpl.bind = PIPE_BIND_SAMPLER_VIEW;
+
+ if support_image {
+ tmpl.bind |= PIPE_BIND_SHADER_IMAGE;
+ }
res_type.apply(&mut tmpl);
target: pipe_texture_target,
format: pipe_format,
mem: *mut c_void,
+ support_image: bool,
) -> Option<PipeResource> {
let mut tmpl = pipe_resource::default();
tmpl.height0 = height;
tmpl.depth0 = depth;
tmpl.array_size = array_size;
- tmpl.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE;
+ tmpl.bind = PIPE_BIND_SAMPLER_VIEW;
+
+ if support_image {
+ tmpl.bind |= PIPE_BIND_SHADER_IMAGE;
+ }
self.resource_create_from_user(&tmpl, mem)
}