Hash :
4532beb0
        
        Author :
  
        
        Date :
2024-12-04T11:46:42
        
      
CL/Vulkan: Set depth and height initial values For types that dont have depth and height set them to 1, and upate query method correspondingly. Updated the test suit to add new tests to the CI, and the following file was autogenerated using `scripts/run_code_generation.py` - `infra/specs/angle.json` Bug: angleproject:382527246 Change-Id: I982f0558248d053759d50b6fc3ca29d389c62acf Signed-off-by: Gowtham Tammana <g.tammana@samsung.com> Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6075440 Reviewed-by: Yuly Novikov <ynovikov@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Austin Annestrand <a.annestrand@samsung.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// cl_utils.cpp: Helper functions for the CL front end
#include "libANGLE/cl_utils.h"
#include "common/PackedCLEnums_autogen.h"
#include "libANGLE/renderer/CLExtensions.h"
namespace cl
{
size_t GetChannelCount(cl_channel_order channelOrder)
{
    size_t count = 0u;
    switch (channelOrder)
    {
        case CL_R:
        case CL_A:
        case CL_LUMINANCE:
        case CL_INTENSITY:
        case CL_DEPTH:
            count = 1u;
            break;
        case CL_RG:
        case CL_RA:
        case CL_Rx:
            count = 2u;
            break;
        case CL_RGB:
        case CL_RGx:
        case CL_sRGB:
            count = 3u;
            break;
        case CL_RGBA:
        case CL_ARGB:
        case CL_BGRA:
        case CL_ABGR:
        case CL_RGBx:
        case CL_sRGBA:
        case CL_sBGRA:
        case CL_sRGBx:
            count = 4u;
            break;
        default:
            break;
    }
    return count;
}
size_t GetElementSize(const cl_image_format &image_format)
{
    size_t size = 0u;
    switch (image_format.image_channel_data_type)
    {
        case CL_SNORM_INT8:
        case CL_UNORM_INT8:
        case CL_SIGNED_INT8:
        case CL_UNSIGNED_INT8:
            size = GetChannelCount(image_format.image_channel_order);
            break;
        case CL_SNORM_INT16:
        case CL_UNORM_INT16:
        case CL_SIGNED_INT16:
        case CL_UNSIGNED_INT16:
        case CL_HALF_FLOAT:
            size = 2u * GetChannelCount(image_format.image_channel_order);
            break;
        case CL_SIGNED_INT32:
        case CL_UNSIGNED_INT32:
        case CL_FLOAT:
            size = 4u * GetChannelCount(image_format.image_channel_order);
            break;
        case CL_UNORM_SHORT_565:
        case CL_UNORM_SHORT_555:
            size = 2u;
            break;
        case CL_UNORM_INT_101010:
        case CL_UNORM_INT_101010_2:
            size = 4u;
            break;
        default:
            break;
    }
    return size;
}
bool IsValidImageFormat(const cl_image_format *imageFormat, const rx::CLExtensions &extensions)
{
    if (imageFormat == nullptr)
    {
        return false;
    }
    switch (imageFormat->image_channel_order)
    {
        case CL_R:
        case CL_A:
        case CL_LUMINANCE:
        case CL_INTENSITY:
        case CL_RG:
        case CL_RA:
        case CL_RGB:
        case CL_RGBA:
        case CL_ARGB:
        case CL_BGRA:
            break;
        case CL_Rx:
        case CL_RGx:
        case CL_RGBx:
            if (extensions.version < CL_MAKE_VERSION(1, 1, 0))
            {
                return false;
            }
            break;
        case CL_ABGR:
        case CL_sRGB:
        case CL_sRGBA:
        case CL_sBGRA:
        case CL_sRGBx:
            if (extensions.version < CL_MAKE_VERSION(2, 0, 0))
            {
                return false;
            }
            break;
        case CL_DEPTH:
            // CL_DEPTH can only be used if channel data type = CL_UNORM_INT16 or CL_FLOAT.
            if (imageFormat->image_channel_data_type != CL_UNORM_INT16 &&
                imageFormat->image_channel_data_type != CL_FLOAT)
            {
                return false;
            }
            if (!extensions.khrDepthImages)
            {
                return false;
            }
            break;
        default:
            return false;
    }
    switch (imageFormat->image_channel_data_type)
    {
        case CL_SNORM_INT8:
        case CL_SNORM_INT16:
        case CL_UNORM_INT8:
        case CL_UNORM_INT16:
        case CL_SIGNED_INT8:
        case CL_SIGNED_INT16:
        case CL_SIGNED_INT32:
        case CL_UNSIGNED_INT8:
        case CL_UNSIGNED_INT16:
        case CL_UNSIGNED_INT32:
        case CL_HALF_FLOAT:
        case CL_FLOAT:
            break;
        case CL_UNORM_SHORT_565:
        case CL_UNORM_SHORT_555:
        case CL_UNORM_INT_101010:
            if (imageFormat->image_channel_order != CL_RGB &&
                imageFormat->image_channel_order != CL_RGBx)
            {
                return false;
            }
            break;
        case CL_UNORM_INT_101010_2:
            if (extensions.version < CL_MAKE_VERSION(2, 1, 0) ||
                imageFormat->image_channel_order != CL_RGBA)
            {
                return false;
            }
            break;
        default:
            return false;
    }
    return true;
}
bool IsImageType(cl::MemObjectType type)
{
    return (type >= cl::MemObjectType::Image2D && type <= cl::MemObjectType::Image1D_Buffer);
}
bool IsBufferType(cl::MemObjectType type)
{
    return type == cl::MemObjectType::Buffer;
}
bool IsArrayType(cl::MemObjectType type)
{
    return (type == cl::MemObjectType::Image1D_Array || type == cl::MemObjectType::Image2D_Array);
}
bool Is3DImage(cl::MemObjectType type)
{
    return (type == cl::MemObjectType::Image3D);
}
bool Is2DImage(cl::MemObjectType type)
{
    return (type == cl::MemObjectType::Image2D || type == cl::MemObjectType::Image2D_Array);
}
bool Is1DImage(cl::MemObjectType type)
{
    return (type >= cl::MemObjectType::Image1D && type <= cl::MemObjectType::Image1D_Buffer);
}
cl::Extents GetExtentFromDescriptor(cl::ImageDescriptor desc)
{
    cl::Extents extent{};
    extent.width  = desc.width;
    extent.height = desc.height;
    extent.depth  = desc.depth;
    // user can supply random values for height and depth for formats that dont need them
    switch (desc.type)
    {
        case cl::MemObjectType::Image1D:
        case cl::MemObjectType::Image1D_Array:
        case cl::MemObjectType::Image1D_Buffer:
            extent.height = 1;
            extent.depth  = 1;
            break;
        case cl::MemObjectType::Image2D:
        case cl::MemObjectType::Image2D_Array:
            extent.depth = 1;
            break;
        default:
            break;
    }
    return extent;
}
thread_local cl_int gClErrorTls;
}  // namespace cl