From 0ec5e50d8afaf5a0ffee0c87437907fa642008d7 Mon Sep 17 00:00:00 2001 From: Edward O'Callaghan Date: Fri, 18 Nov 2016 15:24:18 +1100 Subject: [PATCH] clover: Implement CL_MEM_OBJECT_IMAGE2D_ARRAY v2: Ensure we pass in row_pitch state as well. v3 (Karol): Pull in changes from later commits Signed-off-by: Edward O'Callaghan Signed-off-by: Karol Herbst Reviewed-by: Dave Airlie Part-of: --- src/gallium/frontends/clover/api/memory.cpp | 23 ++++++++++++++++++++++- src/gallium/frontends/clover/api/transfer.cpp | 10 +++++++++- src/gallium/frontends/clover/core/memory.cpp | 11 +++++++++++ src/gallium/frontends/clover/core/memory.hpp | 11 +++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/gallium/frontends/clover/api/memory.cpp b/src/gallium/frontends/clover/api/memory.cpp index 4ce0d3c..668d86b 100644 --- a/src/gallium/frontends/clover/api/memory.cpp +++ b/src/gallium/frontends/clover/api/memory.cpp @@ -243,6 +243,28 @@ clCreateImageWithProperties(cl_context d_ctx, desc->image_width, desc->image_height, row_pitch, host_ptr); + case CL_MEM_OBJECT_IMAGE2D_ARRAY: { + if (!desc->image_width || !desc->image_height || !desc->image_array_size) + throw error(CL_INVALID_IMAGE_SIZE); + + if (all_of([=](const device &dev) { + const size_t max = dev.max_image_size(); + const size_t amax = dev.max_image_array_number(); + return (desc->image_width > max || + desc->image_height > max || + desc->image_array_size > amax); + }, ctx.devices())) + throw error(CL_INVALID_IMAGE_SIZE); + + const size_t slice_pitch = desc->image_slice_pitch ? + desc->image_slice_pitch : row_pitch * desc->image_height; + + return new image2d_array(ctx, properties, flags, format, + desc->image_width, desc->image_height, + desc->image_array_size, row_pitch, + slice_pitch, host_ptr); + } + case CL_MEM_OBJECT_IMAGE3D: { if (!desc->image_width || !desc->image_height || !desc->image_depth) throw error(CL_INVALID_IMAGE_SIZE); @@ -266,7 +288,6 @@ clCreateImageWithProperties(cl_context d_ctx, case CL_MEM_OBJECT_IMAGE1D_ARRAY: case CL_MEM_OBJECT_IMAGE1D_BUFFER: - case CL_MEM_OBJECT_IMAGE2D_ARRAY: // XXX - Not implemented. throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED); diff --git a/src/gallium/frontends/clover/api/transfer.cpp b/src/gallium/frontends/clover/api/transfer.cpp index fd089fb..d802043 100644 --- a/src/gallium/frontends/clover/api/transfer.cpp +++ b/src/gallium/frontends/clover/api/transfer.cpp @@ -104,7 +104,8 @@ namespace { void validate_object(command_queue &q, image &img, const vector_t &orig, const vector_t ®ion) { - vector_t size = { img.width(), img.height(), img.depth() }; + size_t depth = img.type() == CL_MEM_OBJECT_IMAGE2D_ARRAY ? img.array_size() : img.depth(); + vector_t size = { img.width(), img.height(), depth }; const auto &dev = q.device(); if (!dev.image_support()) @@ -132,6 +133,13 @@ namespace { throw error(CL_INVALID_IMAGE_SIZE); break; } + case CL_MEM_OBJECT_IMAGE2D_ARRAY: { + const size_t max_size = dev.max_image_size(); + const size_t max_array = dev.max_image_array_number(); + if (img.width() > max_size || img.height() > max_size || img.array_size() > max_array) + throw error(CL_INVALID_IMAGE_SIZE); + break; + } case CL_MEM_OBJECT_IMAGE3D: { const size_t max = dev.max_image_size_3d(); if (img.width() > max || img.height() > max || img.depth() > max) diff --git a/src/gallium/frontends/clover/core/memory.cpp b/src/gallium/frontends/clover/core/memory.cpp index 251fad2..a59972f 100644 --- a/src/gallium/frontends/clover/core/memory.cpp +++ b/src/gallium/frontends/clover/core/memory.cpp @@ -280,6 +280,17 @@ image2d::image2d(clover::context &ctx, row_pitch, 0, height * row_pitch, host_ptr, nullptr) { } +image2d_array::image2d_array(clover::context &ctx, + std::vector properties, + cl_mem_flags flags, + const cl_image_format *format, + size_t width, size_t height, size_t array_size, + size_t row_pitch, size_t slice_pitch, + void *host_ptr) : + basic_image(ctx, properties, flags, format, width, height, 1, array_size, + row_pitch, slice_pitch, slice_pitch * array_size, host_ptr, nullptr) { +} + image3d::image3d(clover::context &ctx, std::vector properties, cl_mem_flags flags, diff --git a/src/gallium/frontends/clover/core/memory.hpp b/src/gallium/frontends/clover/core/memory.hpp index 38cda7c..72d9d32 100644 --- a/src/gallium/frontends/clover/core/memory.hpp +++ b/src/gallium/frontends/clover/core/memory.hpp @@ -205,6 +205,17 @@ namespace clover { void *host_ptr); }; + class image2d_array : public basic_image { + public: + image2d_array(clover::context &ctx, + std::vector properties, + cl_mem_flags flags, + const cl_image_format *format, + size_t width, size_t height, size_t array_size, + size_t row_pitch, size_t slice_pitch, + void *host_ptr); + }; + class image3d : public basic_image{ public: image3d(clover::context &ctx, -- 2.7.4