1 // 2 // Copyright 2021 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // cl_types.h: Defines common types for the OpenCL support in ANGLE. 7 8 #ifndef LIBANGLE_CLTYPES_H_ 9 #define LIBANGLE_CLTYPES_H_ 10 11 #include "libANGLE/CLBitField.h" 12 #include "libANGLE/CLRefPointer.h" 13 #include "libANGLE/Debug.h" 14 15 #include "common/PackedCLEnums_autogen.h" 16 #include "common/angleutils.h" 17 18 // Include frequently used standard headers 19 #include <algorithm> 20 #include <array> 21 #include <functional> 22 #include <list> 23 #include <memory> 24 #include <string> 25 #include <utility> 26 #include <vector> 27 28 namespace cl 29 { 30 31 class Buffer; 32 class CommandQueue; 33 class Context; 34 class Device; 35 class Event; 36 class Image; 37 class Kernel; 38 class Memory; 39 class Object; 40 class Platform; 41 class Program; 42 class Sampler; 43 44 using BufferPtr = RefPointer<Buffer>; 45 using CommandQueuePtr = RefPointer<CommandQueue>; 46 using ContextPtr = RefPointer<Context>; 47 using DevicePtr = RefPointer<Device>; 48 using EventPtr = RefPointer<Event>; 49 using KernelPtr = RefPointer<Kernel>; 50 using MemoryPtr = RefPointer<Memory>; 51 using PlatformPtr = RefPointer<Platform>; 52 using ProgramPtr = RefPointer<Program>; 53 using SamplerPtr = RefPointer<Sampler>; 54 55 using BufferPtrs = std::vector<BufferPtr>; 56 using DevicePtrs = std::vector<DevicePtr>; 57 using EventPtrs = std::vector<EventPtr>; 58 using KernelPtrs = std::vector<KernelPtr>; 59 using MemoryPtrs = std::vector<MemoryPtr>; 60 using PlatformPtrs = std::vector<PlatformPtr>; 61 using ProgramPtrs = std::vector<ProgramPtr>; 62 63 using WorkgroupSize = std::array<size_t, 3>; 64 using GlobalWorkOffset = std::array<size_t, 3>; 65 using GlobalWorkSize = std::array<size_t, 3>; 66 using WorkgroupCount = std::array<uint32_t, 3>; 67 68 template <typename T> 69 using EventStatusMap = std::array<T, 3>; 70 71 struct ImageDescriptor 72 { 73 MemObjectType type; 74 size_t width; 75 size_t height; 76 size_t depth; 77 size_t arraySize; 78 size_t rowPitch; 79 size_t slicePitch; 80 cl_uint numMipLevels; 81 cl_uint numSamples; 82 }; 83 84 struct MemOffsets 85 { 86 size_t x, y, z; 87 }; 88 89 struct Coordinate 90 { 91 size_t x, y, z; 92 }; 93 94 struct NDRange 95 { NDRangeNDRange96 NDRange(cl_uint workDimensionsIn, 97 const size_t *globalWorkOffsetIn, 98 const size_t *globalWorkSizeIn, 99 const size_t *localWorkSizeIn) 100 : workDimensions(workDimensionsIn), 101 globalWorkOffset({0, 0, 0}), 102 globalWorkSize({1, 1, 1}), 103 localWorkSize({1, 1, 1}), 104 nullLocalWorkSize(localWorkSizeIn == nullptr) 105 { 106 for (cl_uint dim = 0; dim < workDimensionsIn; dim++) 107 { 108 if (globalWorkOffsetIn != nullptr) 109 { 110 globalWorkOffset[dim] = globalWorkOffsetIn[dim]; 111 } 112 if (globalWorkSizeIn != nullptr) 113 { 114 globalWorkSize[dim] = globalWorkSizeIn[dim]; 115 } 116 if (localWorkSizeIn != nullptr) 117 { 118 localWorkSize[dim] = localWorkSizeIn[dim]; 119 } 120 ASSERT(globalWorkSize[dim] != 0); 121 ASSERT(localWorkSize[dim] != 0); 122 } 123 } 124 125 cl_uint workDimensions; 126 GlobalWorkOffset globalWorkOffset; 127 GlobalWorkSize globalWorkSize; 128 WorkgroupSize localWorkSize; 129 bool nullLocalWorkSize{false}; 130 }; 131 132 } // namespace cl 133 134 #endif // LIBANGLE_CLTYPES_H_ 135