clover/formats: pass in cl_mem_flags for better format checking

This allows us to advertise more formats depending on how the image is
getting used inside a kernel.

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13424>
This commit is contained in:
Karol Herbst 2020-10-21 05:03:27 +02:00 committed by Dave Airlie
parent f09e6c1c5f
commit b4f9b15dd0
4 changed files with 12 additions and 7 deletions

View File

@ -204,7 +204,7 @@ clCreateImageWithProperties(cl_context d_ctx,
const cl_mem_flags flags = validate_flags(desc->buffer, d_flags, false);
if (!supported_formats(ctx, desc->image_type).count(*format))
if (!supported_formats(ctx, desc->image_type, d_flags).count(*format))
throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED);
std::vector<cl_mem_properties> properties = fill_properties(d_properties);
@ -368,7 +368,7 @@ clGetSupportedImageFormats(cl_context d_ctx, cl_mem_flags flags,
cl_mem_object_type type, cl_uint count,
cl_image_format *r_buf, cl_uint *r_count) try {
auto &ctx = obj(d_ctx);
auto formats = supported_formats(ctx, type);
auto formats = supported_formats(ctx, type, flags);
if (flags & CL_MEM_KERNEL_READ_AND_WRITE) {
if (r_count)

View File

@ -106,7 +106,7 @@ namespace clover {
friend class root_resource;
friend class hard_event;
friend std::set<cl_image_format>
supported_formats(const context &, cl_mem_object_type);
supported_formats(const context &, cl_mem_object_type, cl_mem_flags flags);
const void *get_compiler_options(enum pipe_shader_ir ir) const;
clover::platform &platform;

View File

@ -126,11 +126,15 @@ namespace clover {
}
std::set<cl_image_format>
supported_formats(const context &ctx, cl_mem_object_type type) {
supported_formats(const context &ctx, cl_mem_object_type type, cl_mem_flags flags) {
std::set<cl_image_format> s;
pipe_texture_target target = translate_target(type);
unsigned bindings = (PIPE_BIND_SAMPLER_VIEW |
PIPE_BIND_COMPUTE_RESOURCE);
unsigned bindings = 0;
if (flags & (CL_MEM_READ_ONLY | CL_MEM_READ_WRITE | CL_MEM_KERNEL_READ_AND_WRITE))
bindings |= PIPE_BIND_SAMPLER_VIEW;
if (flags & (CL_MEM_WRITE_ONLY | CL_MEM_READ_WRITE | CL_MEM_KERNEL_READ_AND_WRITE))
bindings |= PIPE_BIND_SHADER_IMAGE;
for (auto f : formats) {
if (all_of([=](const device &dev) {

View File

@ -38,7 +38,8 @@ namespace clover {
/// the given memory object type.
///
std::set<cl_image_format> supported_formats(const context &ctx,
cl_mem_object_type type);
cl_mem_object_type type,
cl_mem_flags flags);
}
static inline bool