rusticl/device/caps: move enough for has_images

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29205>
This commit is contained in:
Karol Herbst 2024-02-16 16:07:32 +01:00 committed by Marge Bot
parent e02b4e0d44
commit 017ae1f02d
3 changed files with 43 additions and 40 deletions

View file

@ -108,9 +108,9 @@ impl CLInfo<cl_device_info> for cl_device_id {
CL_DEVICE_IMAGE_MAX_ARRAY_SIZE => cl_prop::<usize>(dev.image_array_size()),
CL_DEVICE_IMAGE_MAX_BUFFER_SIZE => cl_prop::<usize>(dev.image_buffer_size()),
CL_DEVICE_IMAGE_PITCH_ALIGNMENT => cl_prop::<cl_uint>(dev.image_pitch_alignment()),
CL_DEVICE_IMAGE_SUPPORT => cl_prop::<bool>(dev.image_supported()),
CL_DEVICE_IMAGE2D_MAX_HEIGHT => cl_prop::<usize>(dev.image_2d_size()),
CL_DEVICE_IMAGE2D_MAX_WIDTH => cl_prop::<usize>(dev.image_2d_size()),
CL_DEVICE_IMAGE_SUPPORT => cl_prop::<bool>(dev.caps.has_images),
CL_DEVICE_IMAGE2D_MAX_HEIGHT => cl_prop::<usize>(dev.caps.image_2d_size as usize),
CL_DEVICE_IMAGE2D_MAX_WIDTH => cl_prop::<usize>(dev.caps.image_2d_size as usize),
CL_DEVICE_IMAGE3D_MAX_HEIGHT => cl_prop::<usize>(dev.image_3d_size()),
CL_DEVICE_IMAGE3D_MAX_WIDTH => cl_prop::<usize>(dev.image_3d_size()),
CL_DEVICE_IMAGE3D_MAX_DEPTH => cl_prop::<usize>(dev.image_3d_size()),
@ -182,10 +182,10 @@ impl CLInfo<cl_device_info> for cl_device_id {
CL_DEVICE_MAX_ON_DEVICE_QUEUES => cl_prop::<cl_uint>(0),
CL_DEVICE_MAX_PARAMETER_SIZE => cl_prop::<usize>(dev.param_max_size()),
CL_DEVICE_MAX_PIPE_ARGS => cl_prop::<cl_uint>(0),
CL_DEVICE_MAX_READ_IMAGE_ARGS => cl_prop::<cl_uint>(dev.image_read_count()),
CL_DEVICE_MAX_READ_IMAGE_ARGS => cl_prop::<cl_uint>(dev.caps.max_read_images),
CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS => {
cl_prop::<cl_uint>(if dev.image_read_write_supported() {
dev.image_write_count()
dev.caps.max_write_images
} else {
0
})
@ -194,7 +194,7 @@ impl CLInfo<cl_device_info> for cl_device_id {
CL_DEVICE_MAX_WORK_GROUP_SIZE => cl_prop::<usize>(dev.max_threads_per_block()),
CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS => cl_prop::<cl_uint>(dev.max_grid_dimensions()),
CL_DEVICE_MAX_WORK_ITEM_SIZES => cl_prop::<Vec<usize>>(dev.max_block_sizes()),
CL_DEVICE_MAX_WRITE_IMAGE_ARGS => cl_prop::<cl_uint>(dev.image_write_count()),
CL_DEVICE_MAX_WRITE_IMAGE_ARGS => cl_prop::<cl_uint>(dev.caps.max_write_images),
// TODO proper retrival from devices
CL_DEVICE_MEM_BASE_ADDR_ALIGN => cl_prop::<cl_uint>(0x1000),
CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE => {

View file

@ -442,7 +442,7 @@ fn validate_image_desc(
} else if desc.image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER {
devs.iter().map(|d| d.image_buffer_size()).min()
} else {
devs.iter().map(|d| d.image_2d_size()).min()
devs.iter().map(|d| d.caps.image_2d_size as usize).min()
}
.unwrap();
let max_array = devs.iter().map(|d| d.image_array_size()).min().unwrap();
@ -743,7 +743,7 @@ fn create_image_with_properties(
// CL_DEVICE_IMAGE_SUPPORT specified in the Device Queries table is CL_FALSE).
c.devs
.iter()
.find(|d| d.image_supported())
.find(|d| d.caps.has_images)
.ok_or(CL_INVALID_OPERATION)?;
let (format, elem_size) = validate_image_format(image_format)?;
@ -939,7 +939,7 @@ fn create_sampler_impl(
// CL_DEVICE_IMAGE_SUPPORT specified in the Device Queries table is CL_FALSE).
c.devs
.iter()
.find(|d| d.image_supported())
.find(|d| d.caps.has_images)
.ok_or(CL_INVALID_OPERATION)?;
// CL_INVALID_VALUE if addressing_mode, filter_mode, normalized_coords or a combination of these

View file

@ -50,7 +50,11 @@ pub struct Device {
}
pub struct DeviceCaps {
pub has_images: bool,
pub has_timestamp: bool,
pub image_2d_size: u32,
pub max_read_images: u32,
pub max_write_images: u32,
pub timer_resolution: u32,
}
@ -59,11 +63,33 @@ impl DeviceCaps {
let cap_timestamp = screen.param(pipe_cap::PIPE_CAP_QUERY_TIMESTAMP) != 0;
let timer_resolution = screen.param(pipe_cap::PIPE_CAP_TIMER_RESOLUTION) as u32;
let max_write_images =
Self::shader_param(screen, pipe_shader_cap::PIPE_SHADER_CAP_MAX_SHADER_IMAGES) as u32;
let max_read_images =
Self::shader_param(screen, pipe_shader_cap::PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS) as u32;
let image_2d_size = screen.param(pipe_cap::PIPE_CAP_MAX_TEXTURE_2D_SIZE) as u32;
let has_images =
// The minimum value is 8 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
max_read_images >= 8 &&
// The minimum value is 8 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
max_write_images >= 8 &&
// The minimum value is 2048 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
image_2d_size >= 2048;
Self {
has_images: has_images,
has_timestamp: cap_timestamp && timer_resolution > 0,
image_2d_size: has_images.then_some(image_2d_size).unwrap_or_default(),
max_read_images: has_images.then_some(max_read_images).unwrap_or_default(),
max_write_images: has_images.then_some(max_write_images).unwrap_or_default(),
timer_resolution: timer_resolution,
}
}
fn shader_param(screen: &PipeScreen, cap: pipe_shader_cap) -> i32 {
screen.shader_param(pipe_shader_type::PIPE_SHADER_COMPUTE, cap)
}
}
pub trait HelperContextWrapper {
@ -432,15 +458,15 @@ impl Device {
}
fn check_embedded_profile(&self) -> bool {
if self.image_supported() {
if self.caps.has_images {
// The minimum value is 16 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
if self.max_samplers() < 16 ||
// The minimum value is 128 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
self.image_read_count() < 128 ||
self.caps.max_read_images < 128 ||
// The minimum value is 64 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
self.image_write_count() < 64 ||
self.caps.max_write_images < 64 ||
// The minimum value is 16384 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
self.image_2d_size() < 16384 ||
self.caps.image_2d_size < 16384 ||
// The minimum value is 2048 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
self.image_array_size() < 2048 ||
// The minimum value is 65536 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
@ -483,7 +509,7 @@ impl Device {
let mut res = CLVersion::Cl3_0;
if self.embedded {
if self.image_supported() {
if self.caps.has_images {
let supports_array_writes = !FORMATS
.iter()
.filter(|f| f.req_for_embeded_read_or_write)
@ -497,7 +523,7 @@ impl Device {
}
// TODO: check image 1D, 1Dbuffer, 1Darray and 2Darray support explicitly
if self.image_supported() {
if self.caps.has_images {
// The minimum value is 256 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
if self.image_array_size() < 256 ||
// The minimum value is 2048 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
@ -617,7 +643,7 @@ impl Device {
add_feat(1, 0, 0, "__opencl_c_int64");
}
if self.image_supported() {
if self.caps.has_images {
add_feat(1, 0, 0, "__opencl_c_images");
if self.image2d_from_buffer_supported() {
@ -811,10 +837,6 @@ impl Device {
}
}
pub fn image_2d_size(&self) -> usize {
self.screen.param(pipe_cap::PIPE_CAP_MAX_TEXTURE_2D_SIZE) as usize
}
pub fn image_3d_size(&self) -> usize {
1 << (self.screen.param(pipe_cap::PIPE_CAP_MAX_TEXTURE_3D_LEVELS) - 1)
}
@ -847,25 +869,10 @@ impl Device {
) as usize
}
pub fn image_read_count(&self) -> cl_uint {
self.shader_param(pipe_shader_cap::PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS) as cl_uint
}
pub fn image2d_from_buffer_supported(&self) -> bool {
self.image_pitch_alignment() != 0 && self.image_base_address_alignment() != 0
}
pub fn image_supported(&self) -> bool {
// TODO check CL_DEVICE_IMAGE_SUPPORT reqs
self.shader_param(pipe_shader_cap::PIPE_SHADER_CAP_MAX_SHADER_IMAGES) != 0 &&
// The minimum value is 8 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
self.image_read_count() >= 8 &&
// The minimum value is 8 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
self.image_write_count() >= 8 &&
// The minimum value is 2048 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE
self.image_2d_size() >= 2048
}
pub fn image_read_write_supported(&self) -> bool {
!FORMATS
.iter()
@ -884,10 +891,6 @@ impl Device {
.any(|f| *f & cl_mem_flags::from(CL_MEM_WRITE_ONLY) == 0)
}
pub fn image_write_count(&self) -> cl_uint {
self.shader_param(pipe_shader_cap::PIPE_SHADER_CAP_MAX_SHADER_IMAGES) as cl_uint
}
pub fn little_endian(&self) -> bool {
let endianness = self.screen.param(pipe_cap::PIPE_CAP_ENDIANNESS);
endianness == (pipe_endian::PIPE_ENDIAN_LITTLE as i32)
@ -1058,7 +1061,7 @@ impl Device {
fp16: self.fp16_supported(),
fp64: self.fp64_supported(),
int64: self.int64_supported(),
images: self.image_supported(),
images: self.caps.has_images,
images_read_write: self.image_read_write_supported(),
images_write_3d: self.image_3d_write_supported(),
integer_dot_product: true,