Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 1 | // XGL tests |
| 2 | // |
| 3 | // Copyright (C) 2014 LunarG, Inc. |
| 4 | // |
| 5 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | // copy of this software and associated documentation files (the "Software"), |
| 7 | // to deal in the Software without restriction, including without limitation |
| 8 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | // and/or sell copies of the Software, and to permit persons to whom the |
| 10 | // Software is furnished to do so, subject to the following conditions: |
| 11 | // |
| 12 | // The above copyright notice and this permission notice shall be included |
| 13 | // in all copies or substantial portions of the Software. |
| 14 | // |
| 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | // DEALINGS IN THE SOFTWARE. |
| 22 | |
| 23 | #ifndef XGLTESTBINDING_H |
| 24 | #define XGLTESTBINDING_H |
| 25 | |
| 26 | #include <vector> |
| 27 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 28 | #include "xgl.h" |
| 29 | |
| 30 | namespace xgl_testing { |
| 31 | |
| 32 | typedef void (*ErrorCallback)(const char *expr, const char *file, unsigned int line, const char *function); |
| 33 | void set_error_callback(ErrorCallback callback); |
| 34 | |
| 35 | class PhysicalGpu; |
| 36 | class BaseObject; |
| 37 | class Object; |
| 38 | class DynamicStateObject; |
| 39 | class Device; |
| 40 | class Queue; |
| 41 | class GpuMemory; |
| 42 | class Fence; |
| 43 | class QueueSemaphore; |
| 44 | class Event; |
| 45 | class QueryPool; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 46 | class Buffer; |
| 47 | class BufferView; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 48 | class Image; |
| 49 | class ImageView; |
| 50 | class ColorAttachmentView; |
| 51 | class DepthStencilView; |
| 52 | class Shader; |
| 53 | class Pipeline; |
| 54 | class PipelineDelta; |
| 55 | class Sampler; |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 56 | class DescriptorSetLayout; |
| 57 | class DescriptorSetRegion; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 58 | class DescriptorSet; |
| 59 | class DynamicVpStateObject; |
| 60 | class DynamicRsStateObject; |
| 61 | class DynamicMsaaStateObject; |
| 62 | class DynamicCbStateObject; |
| 63 | class DynamicDsStateObject; |
| 64 | class CmdBuffer; |
| 65 | |
| 66 | class PhysicalGpu { |
| 67 | public: |
| 68 | explicit PhysicalGpu(XGL_PHYSICAL_GPU gpu) : gpu_(gpu) {} |
| 69 | |
| 70 | const XGL_PHYSICAL_GPU &obj() const { return gpu_; } |
| 71 | |
| 72 | // xglGetGpuInfo() |
| 73 | XGL_PHYSICAL_GPU_PROPERTIES properties() const; |
| 74 | XGL_PHYSICAL_GPU_PERFORMANCE performance() const; |
| 75 | XGL_PHYSICAL_GPU_MEMORY_PROPERTIES memory_properties() const; |
| 76 | std::vector<XGL_PHYSICAL_GPU_QUEUE_PROPERTIES> queue_properties() const; |
| 77 | |
| 78 | // xglGetProcAddr() |
| 79 | void *get_proc(const char *name) const { return xglGetProcAddr(gpu_, name); } |
| 80 | |
| 81 | // xglGetExtensionSupport() |
| 82 | bool has_extension(const char *ext) const { return (xglGetExtensionSupport(gpu_, ext) == XGL_SUCCESS); } |
| 83 | std::vector<const char *> extensions() const; |
| 84 | |
| 85 | // xglEnumerateLayers() |
| 86 | std::vector<const char *> layers(std::vector<char> &buf) const; |
| 87 | |
| 88 | // xglGetMultiGpuCompatibility() |
| 89 | XGL_GPU_COMPATIBILITY_INFO compatibility(const PhysicalGpu &other) const; |
| 90 | |
| 91 | private: |
| 92 | XGL_PHYSICAL_GPU gpu_; |
| 93 | }; |
| 94 | |
| 95 | class BaseObject { |
| 96 | public: |
| 97 | const XGL_BASE_OBJECT &obj() const { return obj_; } |
| 98 | bool initialized() const { return (obj_ != XGL_NULL_HANDLE); } |
| 99 | |
| 100 | // xglGetObjectInfo() |
| 101 | uint32_t memory_allocation_count() const; |
| 102 | std::vector<XGL_MEMORY_REQUIREMENTS> memory_requirements() const; |
| 103 | |
| 104 | protected: |
| 105 | explicit BaseObject() : obj_(XGL_NULL_HANDLE), own_obj_(false) {} |
| 106 | explicit BaseObject(XGL_BASE_OBJECT obj) : obj_(XGL_NULL_HANDLE), own_obj_(false) { init(obj); } |
| 107 | |
| 108 | void init(XGL_BASE_OBJECT obj, bool own); |
| 109 | void init(XGL_BASE_OBJECT obj) { init(obj, true); } |
| 110 | |
| 111 | void reinit(XGL_BASE_OBJECT obj, bool own); |
| 112 | void reinit(XGL_BASE_OBJECT obj) { reinit(obj, true); } |
| 113 | |
Tony Barbour | 4f66a16 | 2015-01-23 11:48:13 -0700 | [diff] [blame] | 114 | bool own() const { return own_obj_; } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 115 | |
| 116 | private: |
| 117 | // base objects are non-copyable |
| 118 | BaseObject(const BaseObject &); |
| 119 | BaseObject &operator=(const BaseObject &); |
| 120 | |
| 121 | XGL_BASE_OBJECT obj_; |
| 122 | bool own_obj_; |
| 123 | }; |
| 124 | |
| 125 | class Object : public BaseObject { |
| 126 | public: |
| 127 | const XGL_OBJECT &obj() const { return reinterpret_cast<const XGL_OBJECT &>(BaseObject::obj()); } |
| 128 | |
| 129 | // xglBindObjectMemory() |
| 130 | void bind_memory(uint32_t alloc_idx, const GpuMemory &mem, XGL_GPU_SIZE mem_offset); |
| 131 | void unbind_memory(uint32_t alloc_idx); |
| 132 | void unbind_memory(); |
| 133 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 134 | // xglBindObjectMemoryRange() |
| 135 | void bind_memory(uint32_t alloc_idx, XGL_GPU_SIZE offset, XGL_GPU_SIZE size, |
| 136 | const GpuMemory &mem, XGL_GPU_SIZE mem_offset); |
| 137 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 138 | // Unless an object is initialized with init_no_mem(), memories are |
| 139 | // automatically allocated and bound. These methods can be used to get |
| 140 | // the memories (for XGL_MEMORY_REFs), or to map/unmap the primary memory. |
| 141 | std::vector<XGL_GPU_MEMORY> memories() const; |
| 142 | |
| 143 | const void *map(XGL_FLAGS flags) const; |
| 144 | void *map(XGL_FLAGS flags); |
| 145 | const void *map() const { return map(0); } |
| 146 | void *map() { return map(0); } |
| 147 | |
| 148 | void unmap() const; |
| 149 | |
| 150 | protected: |
| 151 | explicit Object() : mem_alloc_count_(0), internal_mems_(NULL), primary_mem_(NULL) {} |
| 152 | explicit Object(XGL_OBJECT obj) : mem_alloc_count_(0), internal_mems_(NULL), primary_mem_(NULL) { init(obj); } |
| 153 | ~Object() { cleanup(); } |
| 154 | |
| 155 | void init(XGL_OBJECT obj, bool own); |
| 156 | void init(XGL_OBJECT obj) { init(obj, true); } |
| 157 | |
| 158 | void reinit(XGL_OBJECT obj, bool own); |
| 159 | void reinit(XGL_OBJECT obj) { init(obj, true); } |
| 160 | |
| 161 | // allocate and bind internal memories |
Jon Ashburn | 8a5da75 | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 162 | void alloc_memory(const Device &dev, bool for_linear_img, bool for_img); |
| 163 | void alloc_memory(const Device &dev) { alloc_memory(dev, false, false); } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 164 | void alloc_memory(const std::vector<XGL_GPU_MEMORY> &mems); |
| 165 | |
| 166 | private: |
| 167 | void cleanup(); |
| 168 | |
| 169 | uint32_t mem_alloc_count_; |
| 170 | GpuMemory *internal_mems_; |
| 171 | GpuMemory *primary_mem_; |
| 172 | }; |
| 173 | |
| 174 | class DynamicStateObject : public Object { |
| 175 | public: |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 176 | const XGL_DYNAMIC_STATE_OBJECT &obj() const { return reinterpret_cast<const XGL_DYNAMIC_STATE_OBJECT &>(Object::obj()); } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 177 | |
| 178 | protected: |
| 179 | explicit DynamicStateObject() {} |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 180 | explicit DynamicStateObject(XGL_DYNAMIC_STATE_OBJECT obj) : Object(obj) {} |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | template<typename T, class C> |
| 184 | class DerivedObject : public C { |
| 185 | public: |
| 186 | const T &obj() const { return reinterpret_cast<const T &>(C::obj()); } |
| 187 | |
| 188 | protected: |
| 189 | typedef T obj_type; |
| 190 | typedef C base_type; |
| 191 | |
| 192 | explicit DerivedObject() {} |
| 193 | explicit DerivedObject(T obj) : C(obj) {} |
| 194 | }; |
| 195 | |
| 196 | class Device : public DerivedObject<XGL_DEVICE, BaseObject> { |
| 197 | public: |
| 198 | explicit Device(XGL_PHYSICAL_GPU gpu) : gpu_(gpu) {} |
| 199 | ~Device(); |
| 200 | |
| 201 | // xglCreateDevice() |
| 202 | void init(const XGL_DEVICE_CREATE_INFO &info); |
Chia-I Wu | 510c999 | 2015-01-06 10:40:45 +0800 | [diff] [blame] | 203 | void init(bool enable_layers); // all queues, all extensions, etc |
| 204 | void init() { init(false); }; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 205 | |
| 206 | const PhysicalGpu &gpu() const { return gpu_; } |
| 207 | |
| 208 | // xglGetDeviceQueue() |
| 209 | const std::vector<Queue *> &graphics_queues() { return queues_[GRAPHICS]; } |
| 210 | const std::vector<Queue *> &compute_queues() { return queues_[COMPUTE]; } |
| 211 | const std::vector<Queue *> &dma_queues() { return queues_[DMA]; } |
| 212 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 213 | |
| 214 | struct Format { |
| 215 | XGL_FORMAT format; |
| 216 | XGL_IMAGE_TILING tiling; |
| 217 | XGL_FLAGS features; |
| 218 | }; |
| 219 | // xglGetFormatInfo() |
| 220 | XGL_FORMAT_PROPERTIES format_properties(XGL_FORMAT format); |
| 221 | const std::vector<Format> &formats() const { return formats_; } |
| 222 | |
| 223 | // xglDeviceWaitIdle() |
| 224 | void wait(); |
| 225 | |
| 226 | // xglWaitForFences() |
| 227 | XGL_RESULT wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout); |
| 228 | XGL_RESULT wait(const Fence &fence) { return wait(std::vector<const Fence *>(1, &fence), true, (uint64_t) -1); } |
| 229 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 230 | // xglBeginDescriptorRegionUpdate() |
| 231 | // xglEndDescriptorRegionUpdate() |
| 232 | void begin_descriptor_region_update(XGL_DESCRIPTOR_UPDATE_MODE mode); |
| 233 | void end_descriptor_region_update(CmdBuffer &cmd); |
| 234 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 235 | private: |
| 236 | enum QueueIndex { |
| 237 | GRAPHICS, |
| 238 | COMPUTE, |
| 239 | DMA, |
| 240 | QUEUE_COUNT, |
| 241 | }; |
| 242 | |
| 243 | void init_queues(); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 244 | void init_formats(); |
| 245 | |
| 246 | PhysicalGpu gpu_; |
| 247 | |
| 248 | std::vector<Queue *> queues_[QUEUE_COUNT]; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 249 | std::vector<Format> formats_; |
| 250 | }; |
| 251 | |
| 252 | class Queue : public DerivedObject<XGL_QUEUE, BaseObject> { |
| 253 | public: |
| 254 | explicit Queue(XGL_QUEUE queue) : DerivedObject(queue) {} |
| 255 | |
| 256 | // xglQueueSubmit() |
| 257 | void submit(const std::vector<const CmdBuffer *> &cmds, const std::vector<XGL_MEMORY_REF> &mem_refs, Fence &fence); |
| 258 | void submit(const CmdBuffer &cmd, const std::vector<XGL_MEMORY_REF> &mem_refs, Fence &fence); |
| 259 | void submit(const CmdBuffer &cmd, const std::vector<XGL_MEMORY_REF> &mem_refs); |
| 260 | |
| 261 | // xglQueueSetGlobalMemReferences() |
| 262 | void set_global_mem_references(const std::vector<XGL_MEMORY_REF> &mem_refs); |
| 263 | |
| 264 | // xglQueueWaitIdle() |
| 265 | void wait(); |
| 266 | |
| 267 | // xglSignalQueueSemaphore() |
| 268 | // xglWaitQueueSemaphore() |
| 269 | void signal_semaphore(QueueSemaphore &sem); |
| 270 | void wait_semaphore(QueueSemaphore &sem); |
| 271 | }; |
| 272 | |
| 273 | class GpuMemory : public DerivedObject<XGL_GPU_MEMORY, BaseObject> { |
| 274 | public: |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 275 | ~GpuMemory(); |
| 276 | |
| 277 | // xglAllocMemory() |
| 278 | void init(const Device &dev, const XGL_MEMORY_ALLOC_INFO &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 279 | // xglPinSystemMemory() |
| 280 | void init(const Device &dev, size_t size, const void *data); |
| 281 | // xglOpenSharedMemory() |
| 282 | void init(const Device &dev, const XGL_MEMORY_OPEN_INFO &info); |
| 283 | // xglOpenPeerMemory() |
| 284 | void init(const Device &dev, const XGL_PEER_MEMORY_OPEN_INFO &info); |
| 285 | |
| 286 | void init(XGL_GPU_MEMORY mem) { BaseObject::init(mem, false); } |
| 287 | |
| 288 | // xglSetMemoryPriority() |
| 289 | void set_priority(XGL_MEMORY_PRIORITY priority); |
| 290 | |
| 291 | // xglMapMemory() |
| 292 | const void *map(XGL_FLAGS flags) const; |
| 293 | void *map(XGL_FLAGS flags); |
| 294 | const void *map() const { return map(0); } |
| 295 | void *map() { return map(0); } |
| 296 | |
| 297 | // xglUnmapMemory() |
| 298 | void unmap() const; |
| 299 | |
Jon Ashburn | 8a5da75 | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 300 | static XGL_MEMORY_ALLOC_INFO alloc_info(const XGL_MEMORY_REQUIREMENTS &reqs, |
Jon Ashburn | 25bbe46 | 2015-01-20 08:50:12 -0700 | [diff] [blame] | 301 | const XGL_MEMORY_ALLOC_INFO *next_info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | class Fence : public DerivedObject<XGL_FENCE, Object> { |
| 305 | public: |
| 306 | // xglCreateFence() |
| 307 | void init(const Device &dev, const XGL_FENCE_CREATE_INFO &info); |
| 308 | |
| 309 | // xglGetFenceStatus() |
| 310 | XGL_RESULT status() const { return xglGetFenceStatus(obj()); } |
| 311 | |
| 312 | static XGL_FENCE_CREATE_INFO create_info(XGL_FLAGS flags); |
| 313 | }; |
| 314 | |
| 315 | class QueueSemaphore : public DerivedObject<XGL_QUEUE_SEMAPHORE, Object> { |
| 316 | public: |
| 317 | // xglCreateQueueSemaphore() |
| 318 | void init(const Device &dev, const XGL_QUEUE_SEMAPHORE_CREATE_INFO &info); |
| 319 | // xglOpenSharedQueueSemaphore() |
| 320 | void init(const Device &dev, const XGL_QUEUE_SEMAPHORE_OPEN_INFO &info); |
| 321 | |
| 322 | static XGL_QUEUE_SEMAPHORE_CREATE_INFO create_info(uint32_t init_count, XGL_FLAGS flags); |
| 323 | }; |
| 324 | |
| 325 | class Event : public DerivedObject<XGL_EVENT, Object> { |
| 326 | public: |
| 327 | // xglCreateEvent() |
| 328 | void init(const Device &dev, const XGL_EVENT_CREATE_INFO &info); |
| 329 | |
| 330 | // xglGetEventStatus() |
| 331 | // xglSetEvent() |
| 332 | // xglResetEvent() |
| 333 | XGL_RESULT status() const { return xglGetEventStatus(obj()); } |
| 334 | void set(); |
| 335 | void reset(); |
| 336 | |
| 337 | static XGL_EVENT_CREATE_INFO create_info(XGL_FLAGS flags); |
| 338 | }; |
| 339 | |
| 340 | class QueryPool : public DerivedObject<XGL_QUERY_POOL, Object> { |
| 341 | public: |
| 342 | // xglCreateQueryPool() |
| 343 | void init(const Device &dev, const XGL_QUERY_POOL_CREATE_INFO &info); |
| 344 | |
| 345 | // xglGetQueryPoolResults() |
| 346 | XGL_RESULT results(uint32_t start, uint32_t count, size_t size, void *data); |
| 347 | |
| 348 | static XGL_QUERY_POOL_CREATE_INFO create_info(XGL_QUERY_TYPE type, uint32_t slot_count); |
| 349 | }; |
| 350 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 351 | class Buffer : public DerivedObject<XGL_BUFFER, Object> { |
| 352 | public: |
| 353 | explicit Buffer() {} |
| 354 | explicit Buffer(const Device &dev, const XGL_BUFFER_CREATE_INFO &info) { init(dev, info); } |
| 355 | explicit Buffer(const Device &dev, XGL_GPU_SIZE size) { init(dev, size); } |
| 356 | |
| 357 | // xglCreateBuffer() |
| 358 | void init(const Device &dev, const XGL_BUFFER_CREATE_INFO &info); |
| 359 | void init(const Device &dev, XGL_GPU_SIZE size) { init(dev, create_info(size, 0)); } |
| 360 | void init_no_mem(const Device &dev, const XGL_BUFFER_CREATE_INFO &info); |
| 361 | |
| 362 | static XGL_BUFFER_CREATE_INFO create_info(XGL_GPU_SIZE size, XGL_FLAGS usage); |
| 363 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 364 | XGL_BUFFER_MEMORY_BARRIER buffer_memory_barrier(XGL_FLAGS output_mask, XGL_FLAGS input_mask, |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 365 | XGL_GPU_SIZE offset, XGL_GPU_SIZE size) const |
| 366 | { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 367 | XGL_BUFFER_MEMORY_BARRIER barrier = {}; |
| 368 | barrier.sType = XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 369 | barrier.buffer = obj(); |
| 370 | barrier.outputMask = output_mask; |
| 371 | barrier.inputMask = input_mask; |
| 372 | barrier.offset = offset; |
| 373 | barrier.size = size; |
| 374 | return barrier; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 375 | } |
| 376 | private: |
| 377 | XGL_BUFFER_CREATE_INFO create_info_; |
| 378 | }; |
| 379 | |
| 380 | class BufferView : public DerivedObject<XGL_BUFFER_VIEW, Object> { |
| 381 | public: |
| 382 | // xglCreateBufferView() |
| 383 | void init(const Device &dev, const XGL_BUFFER_VIEW_CREATE_INFO &info); |
| 384 | }; |
| 385 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 386 | class Image : public DerivedObject<XGL_IMAGE, Object> { |
| 387 | public: |
| 388 | explicit Image() : format_features_(0) {} |
| 389 | explicit Image(const Device &dev, const XGL_IMAGE_CREATE_INFO &info) : format_features_(0) { init(dev, info); } |
| 390 | |
| 391 | // xglCreateImage() |
| 392 | void init(const Device &dev, const XGL_IMAGE_CREATE_INFO &info); |
| 393 | void init_no_mem(const Device &dev, const XGL_IMAGE_CREATE_INFO &info); |
| 394 | // xglOpenPeerImage() |
| 395 | void init(const Device &dev, const XGL_PEER_IMAGE_OPEN_INFO &info, const XGL_IMAGE_CREATE_INFO &original_info); |
| 396 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 397 | // xglBindImageMemoryRange() |
| 398 | void bind_memory(uint32_t alloc_idx, const XGL_IMAGE_MEMORY_BIND_INFO &info, |
| 399 | const GpuMemory &mem, XGL_GPU_SIZE mem_offset); |
| 400 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 401 | // xglGetImageSubresourceInfo() |
| 402 | XGL_SUBRESOURCE_LAYOUT subresource_layout(const XGL_IMAGE_SUBRESOURCE &subres) const; |
| 403 | |
| 404 | bool transparent() const; |
| 405 | bool copyable() const { return (format_features_ & XGL_FORMAT_IMAGE_COPY_BIT); } |
| 406 | |
| 407 | XGL_IMAGE_SUBRESOURCE_RANGE subresource_range(XGL_IMAGE_ASPECT aspect) const { return subresource_range(create_info_, aspect); } |
| 408 | XGL_EXTENT3D extent() const { return create_info_.extent; } |
| 409 | XGL_EXTENT3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); } |
Tony Barbour | a53a694 | 2015-02-25 11:25:11 -0700 | [diff] [blame] | 410 | XGL_FORMAT format() const {return create_info_.format;} |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 411 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 412 | XGL_IMAGE_MEMORY_BARRIER image_memory_barrier(XGL_FLAGS output_mask, XGL_FLAGS input_mask, |
| 413 | XGL_IMAGE_LAYOUT old_layout, |
| 414 | XGL_IMAGE_LAYOUT new_layout, |
| 415 | const XGL_IMAGE_SUBRESOURCE_RANGE &range) const |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 416 | { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 417 | XGL_IMAGE_MEMORY_BARRIER barrier = {}; |
| 418 | barrier.sType = XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 419 | barrier.outputMask = output_mask; |
| 420 | barrier.inputMask = input_mask; |
| 421 | barrier.oldLayout = old_layout; |
| 422 | barrier.newLayout = new_layout; |
| 423 | barrier.image = obj(); |
| 424 | barrier.subresourceRange = range; |
| 425 | return barrier; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static XGL_IMAGE_CREATE_INFO create_info(); |
| 429 | static XGL_IMAGE_SUBRESOURCE subresource(XGL_IMAGE_ASPECT aspect, uint32_t mip_level, uint32_t array_slice); |
| 430 | static XGL_IMAGE_SUBRESOURCE subresource(const XGL_IMAGE_SUBRESOURCE_RANGE &range, uint32_t mip_level, uint32_t array_slice); |
| 431 | static XGL_IMAGE_SUBRESOURCE_RANGE subresource_range(XGL_IMAGE_ASPECT aspect, uint32_t base_mip_level, uint32_t mip_levels, |
| 432 | uint32_t base_array_slice, uint32_t array_size); |
| 433 | static XGL_IMAGE_SUBRESOURCE_RANGE subresource_range(const XGL_IMAGE_CREATE_INFO &info, XGL_IMAGE_ASPECT aspect); |
| 434 | static XGL_IMAGE_SUBRESOURCE_RANGE subresource_range(const XGL_IMAGE_SUBRESOURCE &subres); |
| 435 | |
| 436 | static XGL_EXTENT2D extent(int32_t width, int32_t height); |
| 437 | static XGL_EXTENT2D extent(const XGL_EXTENT2D &extent, uint32_t mip_level); |
| 438 | static XGL_EXTENT2D extent(const XGL_EXTENT3D &extent); |
| 439 | |
| 440 | static XGL_EXTENT3D extent(int32_t width, int32_t height, int32_t depth); |
| 441 | static XGL_EXTENT3D extent(const XGL_EXTENT3D &extent, uint32_t mip_level); |
| 442 | |
| 443 | private: |
| 444 | void init_info(const Device &dev, const XGL_IMAGE_CREATE_INFO &info); |
| 445 | |
| 446 | XGL_IMAGE_CREATE_INFO create_info_; |
| 447 | XGL_FLAGS format_features_; |
| 448 | }; |
| 449 | |
| 450 | class ImageView : public DerivedObject<XGL_IMAGE_VIEW, Object> { |
| 451 | public: |
| 452 | // xglCreateImageView() |
| 453 | void init(const Device &dev, const XGL_IMAGE_VIEW_CREATE_INFO &info); |
| 454 | }; |
| 455 | |
| 456 | class ColorAttachmentView : public DerivedObject<XGL_COLOR_ATTACHMENT_VIEW, Object> { |
| 457 | public: |
| 458 | // xglCreateColorAttachmentView() |
| 459 | void init(const Device &dev, const XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO &info); |
| 460 | }; |
| 461 | |
| 462 | class DepthStencilView : public DerivedObject<XGL_DEPTH_STENCIL_VIEW, Object> { |
| 463 | public: |
| 464 | // xglCreateDepthStencilView() |
| 465 | void init(const Device &dev, const XGL_DEPTH_STENCIL_VIEW_CREATE_INFO &info); |
| 466 | }; |
| 467 | |
| 468 | class Shader : public DerivedObject<XGL_SHADER, Object> { |
| 469 | public: |
| 470 | // xglCreateShader() |
| 471 | void init(const Device &dev, const XGL_SHADER_CREATE_INFO &info); |
| 472 | XGL_RESULT init_try(const Device &dev, const XGL_SHADER_CREATE_INFO &info); |
| 473 | |
| 474 | static XGL_SHADER_CREATE_INFO create_info(size_t code_size, const void *code, XGL_FLAGS flags); |
| 475 | }; |
| 476 | |
| 477 | class Pipeline : public DerivedObject<XGL_PIPELINE, Object> { |
| 478 | public: |
| 479 | // xglCreateGraphicsPipeline() |
| 480 | void init(const Device &dev, const XGL_GRAPHICS_PIPELINE_CREATE_INFO &info); |
| 481 | // xglCreateComputePipeline() |
| 482 | void init(const Device &dev, const XGL_COMPUTE_PIPELINE_CREATE_INFO &info); |
| 483 | // xglLoadPipeline() |
| 484 | void init(const Device&dev, size_t size, const void *data); |
| 485 | |
| 486 | // xglStorePipeline() |
| 487 | size_t store(size_t size, void *data); |
| 488 | }; |
| 489 | |
| 490 | class PipelineDelta : public DerivedObject<XGL_PIPELINE_DELTA, Object> { |
| 491 | public: |
| 492 | // xglCreatePipelineDelta() |
| 493 | void init(const Device &dev, const Pipeline &p1, const Pipeline &p2); |
| 494 | }; |
| 495 | |
| 496 | class Sampler : public DerivedObject<XGL_SAMPLER, Object> { |
| 497 | public: |
| 498 | // xglCreateSampler() |
| 499 | void init(const Device &dev, const XGL_SAMPLER_CREATE_INFO &info); |
| 500 | }; |
| 501 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 502 | class DescriptorSetLayout : public DerivedObject<XGL_DESCRIPTOR_SET_LAYOUT, Object> { |
| 503 | public: |
| 504 | // xglCreateDescriptorSetLayout() |
| 505 | void init(const Device &dev, XGL_FLAGS stage_mask, |
| 506 | const std::vector<uint32_t> &bind_points, |
| 507 | const DescriptorSetLayout &prior_layout, |
| 508 | const XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO &info); |
| 509 | void init(const Device &dev, uint32_t bind_point, |
| 510 | const DescriptorSetLayout &prior_layout, |
| 511 | const XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO &info); |
| 512 | void init(const Device &dev, uint32_t bind_point, |
| 513 | const XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO &info) { init(dev, bind_point, DescriptorSetLayout(), info); } |
| 514 | }; |
| 515 | |
| 516 | class DescriptorRegion : public DerivedObject<XGL_DESCRIPTOR_REGION, Object> { |
| 517 | public: |
| 518 | // xglCreateDescriptorRegion() |
| 519 | void init(const Device &dev, XGL_DESCRIPTOR_REGION_USAGE usage, |
| 520 | uint32_t max_sets, const XGL_DESCRIPTOR_REGION_CREATE_INFO &info); |
| 521 | |
| 522 | // xglClearDescriptorRegion() |
| 523 | void clear(); |
| 524 | |
| 525 | // xglAllocDescriptorSets() |
| 526 | std::vector<DescriptorSet *> alloc_sets(XGL_DESCRIPTOR_SET_USAGE usage, const std::vector<const DescriptorSetLayout *> &layouts); |
| 527 | std::vector<DescriptorSet *> alloc_sets(XGL_DESCRIPTOR_SET_USAGE usage, const DescriptorSetLayout &layout, uint32_t count); |
| 528 | DescriptorSet *alloc_sets(XGL_DESCRIPTOR_SET_USAGE usage, const DescriptorSetLayout &layout); |
| 529 | |
| 530 | // xglClearDescriptorSets() |
| 531 | void clear_sets(const std::vector<DescriptorSet *> &sets); |
| 532 | void clear_sets(DescriptorSet &set) { clear_sets(std::vector<DescriptorSet *>(1, &set)); } |
| 533 | }; |
| 534 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 535 | class DescriptorSet : public DerivedObject<XGL_DESCRIPTOR_SET, Object> { |
| 536 | public: |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 537 | explicit DescriptorSet(XGL_DESCRIPTOR_SET set) : DerivedObject(set) {} |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 538 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 539 | // xglUpdateDescriptors() |
| 540 | void update(const void *update_chain); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 541 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 542 | static XGL_UPDATE_SAMPLERS update(uint32_t index, uint32_t count, const XGL_SAMPLER *samplers); |
| 543 | static XGL_UPDATE_SAMPLERS update(uint32_t index, const std::vector<XGL_SAMPLER> &samplers); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 544 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 545 | static XGL_UPDATE_SAMPLER_TEXTURES update(uint32_t index, uint32_t count, const XGL_SAMPLER_IMAGE_VIEW_INFO *textures); |
| 546 | static XGL_UPDATE_SAMPLER_TEXTURES update(uint32_t index, const std::vector<XGL_SAMPLER_IMAGE_VIEW_INFO> &textures); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 547 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 548 | static XGL_UPDATE_IMAGES update(XGL_DESCRIPTOR_TYPE type, uint32_t index, uint32_t count, const XGL_IMAGE_VIEW_ATTACH_INFO * const *views); |
| 549 | static XGL_UPDATE_IMAGES update(XGL_DESCRIPTOR_TYPE type, uint32_t index, const std::vector<const XGL_IMAGE_VIEW_ATTACH_INFO *> &views); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 550 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 551 | static XGL_UPDATE_BUFFERS update(XGL_DESCRIPTOR_TYPE type, uint32_t index, uint32_t count, const XGL_BUFFER_VIEW_ATTACH_INFO * const *views); |
| 552 | static XGL_UPDATE_BUFFERS update(XGL_DESCRIPTOR_TYPE type, uint32_t index, const std::vector<const XGL_BUFFER_VIEW_ATTACH_INFO *> &views); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 553 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 554 | static XGL_UPDATE_AS_COPY update(XGL_DESCRIPTOR_TYPE type, uint32_t index, uint32_t count, const DescriptorSet &set); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 555 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 556 | static XGL_BUFFER_VIEW_ATTACH_INFO attach_info(const BufferView &view); |
| 557 | static XGL_IMAGE_VIEW_ATTACH_INFO attach_info(const ImageView &view, XGL_IMAGE_LAYOUT layout); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 558 | }; |
| 559 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 560 | class DynamicVpStateObject : public DerivedObject<XGL_DYNAMIC_VP_STATE_OBJECT, DynamicStateObject> { |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 561 | public: |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 562 | // xglCreateDynamicViewportState() |
| 563 | void init(const Device &dev, const XGL_DYNAMIC_VP_STATE_CREATE_INFO &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 564 | }; |
| 565 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 566 | class DynamicRsStateObject : public DerivedObject<XGL_DYNAMIC_RS_STATE_OBJECT, DynamicStateObject> { |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 567 | public: |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 568 | // xglCreateDynamicRasterState() |
| 569 | void init(const Device &dev, const XGL_DYNAMIC_RS_STATE_CREATE_INFO &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 570 | }; |
| 571 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 572 | class DynamicCbStateObject : public DerivedObject<XGL_DYNAMIC_CB_STATE_OBJECT, DynamicStateObject> { |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 573 | public: |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 574 | // xglCreateDynamicColorBlendState() |
| 575 | void init(const Device &dev, const XGL_DYNAMIC_CB_STATE_CREATE_INFO &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 576 | }; |
| 577 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 578 | class DynamicDsStateObject : public DerivedObject<XGL_DYNAMIC_DS_STATE_OBJECT, DynamicStateObject> { |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 579 | public: |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 580 | // xglCreateDynamicDepthStencilState() |
| 581 | void init(const Device &dev, const XGL_DYNAMIC_DS_STATE_CREATE_INFO &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 582 | }; |
| 583 | |
| 584 | class CmdBuffer : public DerivedObject<XGL_CMD_BUFFER, Object> { |
| 585 | public: |
| 586 | explicit CmdBuffer() {} |
| 587 | explicit CmdBuffer(const Device &dev, const XGL_CMD_BUFFER_CREATE_INFO &info) { init(dev, info); } |
| 588 | |
| 589 | // xglCreateCommandBuffer() |
| 590 | void init(const Device &dev, const XGL_CMD_BUFFER_CREATE_INFO &info); |
| 591 | |
| 592 | // xglBeginCommandBuffer() |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 593 | void begin(const XGL_CMD_BUFFER_BEGIN_INFO *info); |
| 594 | void begin(XGL_RENDER_PASS renderpass_obj); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 595 | void begin(); |
| 596 | |
| 597 | // xglEndCommandBuffer() |
| 598 | // xglResetCommandBuffer() |
| 599 | void end(); |
| 600 | void reset(); |
| 601 | |
| 602 | static XGL_CMD_BUFFER_CREATE_INFO create_info(XGL_QUEUE_TYPE type); |
| 603 | }; |
| 604 | |
| 605 | inline const void *Object::map(XGL_FLAGS flags) const |
| 606 | { |
| 607 | return (primary_mem_) ? primary_mem_->map(flags) : NULL; |
| 608 | } |
| 609 | |
| 610 | inline void *Object::map(XGL_FLAGS flags) |
| 611 | { |
| 612 | return (primary_mem_) ? primary_mem_->map(flags) : NULL; |
| 613 | } |
| 614 | |
| 615 | inline void Object::unmap() const |
| 616 | { |
| 617 | if (primary_mem_) |
| 618 | primary_mem_->unmap(); |
| 619 | } |
| 620 | |
Jon Ashburn | 8a5da75 | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 621 | inline XGL_MEMORY_ALLOC_INFO GpuMemory::alloc_info(const XGL_MEMORY_REQUIREMENTS &reqs, |
Jon Ashburn | 25bbe46 | 2015-01-20 08:50:12 -0700 | [diff] [blame] | 622 | const XGL_MEMORY_ALLOC_INFO *next_info) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 623 | { |
| 624 | XGL_MEMORY_ALLOC_INFO info = {}; |
| 625 | info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
Jon Ashburn | 25bbe46 | 2015-01-20 08:50:12 -0700 | [diff] [blame] | 626 | if (next_info != NULL) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 627 | info.pNext = (void *) next_info; |
Jon Ashburn | 8a5da75 | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 628 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 629 | info.allocationSize = reqs.size; |
Jon Ashburn | e479243 | 2015-01-20 13:55:32 -0700 | [diff] [blame] | 630 | info.memProps = reqs.memProps; |
Jon Ashburn | e01ff7a | 2015-01-20 15:06:59 -0700 | [diff] [blame] | 631 | info.memType = reqs.memType; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 632 | info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 633 | return info; |
| 634 | } |
| 635 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 636 | inline XGL_BUFFER_CREATE_INFO Buffer::create_info(XGL_GPU_SIZE size, XGL_FLAGS usage) |
| 637 | { |
| 638 | XGL_BUFFER_CREATE_INFO info = {}; |
| 639 | info.sType = XGL_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 640 | info.size = size; |
| 641 | info.usage = usage; |
| 642 | return info; |
| 643 | } |
| 644 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 645 | inline XGL_FENCE_CREATE_INFO Fence::create_info(XGL_FLAGS flags) |
| 646 | { |
| 647 | XGL_FENCE_CREATE_INFO info = {}; |
| 648 | info.sType = XGL_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 649 | info.flags = flags; |
| 650 | return info; |
| 651 | } |
| 652 | |
| 653 | inline XGL_QUEUE_SEMAPHORE_CREATE_INFO QueueSemaphore::create_info(uint32_t init_count, XGL_FLAGS flags) |
| 654 | { |
| 655 | XGL_QUEUE_SEMAPHORE_CREATE_INFO info = {}; |
Mark Lobodzinski | e0d8788 | 2015-01-26 10:34:00 -0600 | [diff] [blame] | 656 | info.sType = XGL_STRUCTURE_TYPE_QUEUE_SEMAPHORE_CREATE_INFO; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 657 | info.initialCount = init_count; |
| 658 | info.flags = flags; |
| 659 | return info; |
| 660 | } |
| 661 | |
| 662 | inline XGL_EVENT_CREATE_INFO Event::create_info(XGL_FLAGS flags) |
| 663 | { |
| 664 | XGL_EVENT_CREATE_INFO info = {}; |
| 665 | info.sType = XGL_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 666 | info.flags = flags; |
| 667 | return info; |
| 668 | } |
| 669 | |
| 670 | inline XGL_QUERY_POOL_CREATE_INFO QueryPool::create_info(XGL_QUERY_TYPE type, uint32_t slot_count) |
| 671 | { |
| 672 | XGL_QUERY_POOL_CREATE_INFO info = {}; |
| 673 | info.sType = XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 674 | info.queryType = type; |
| 675 | info.slots = slot_count; |
| 676 | return info; |
| 677 | } |
| 678 | |
| 679 | inline XGL_IMAGE_CREATE_INFO Image::create_info() |
| 680 | { |
| 681 | XGL_IMAGE_CREATE_INFO info = {}; |
| 682 | info.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 683 | info.extent.width = 1; |
| 684 | info.extent.height = 1; |
| 685 | info.extent.depth = 1; |
| 686 | info.mipLevels = 1; |
| 687 | info.arraySize = 1; |
| 688 | info.samples = 1; |
| 689 | return info; |
| 690 | } |
| 691 | |
| 692 | inline XGL_IMAGE_SUBRESOURCE Image::subresource(XGL_IMAGE_ASPECT aspect, uint32_t mip_level, uint32_t array_slice) |
| 693 | { |
| 694 | XGL_IMAGE_SUBRESOURCE subres = {}; |
| 695 | subres.aspect = aspect; |
| 696 | subres.mipLevel = mip_level; |
| 697 | subres.arraySlice = array_slice; |
| 698 | return subres; |
| 699 | } |
| 700 | |
| 701 | inline XGL_IMAGE_SUBRESOURCE Image::subresource(const XGL_IMAGE_SUBRESOURCE_RANGE &range, uint32_t mip_level, uint32_t array_slice) |
| 702 | { |
| 703 | return subresource(range.aspect, range.baseMipLevel + mip_level, range.baseArraySlice + array_slice); |
| 704 | } |
| 705 | |
| 706 | inline XGL_IMAGE_SUBRESOURCE_RANGE Image::subresource_range(XGL_IMAGE_ASPECT aspect, uint32_t base_mip_level, uint32_t mip_levels, |
| 707 | uint32_t base_array_slice, uint32_t array_size) |
| 708 | { |
| 709 | XGL_IMAGE_SUBRESOURCE_RANGE range = {}; |
| 710 | range.aspect = aspect; |
| 711 | range.baseMipLevel = base_mip_level; |
| 712 | range.mipLevels = mip_levels; |
| 713 | range.baseArraySlice = base_array_slice; |
| 714 | range.arraySize = array_size; |
| 715 | return range; |
| 716 | } |
| 717 | |
| 718 | inline XGL_IMAGE_SUBRESOURCE_RANGE Image::subresource_range(const XGL_IMAGE_CREATE_INFO &info, XGL_IMAGE_ASPECT aspect) |
| 719 | { |
| 720 | return subresource_range(aspect, 0, info.mipLevels, 0, info.arraySize); |
| 721 | } |
| 722 | |
| 723 | inline XGL_IMAGE_SUBRESOURCE_RANGE Image::subresource_range(const XGL_IMAGE_SUBRESOURCE &subres) |
| 724 | { |
| 725 | return subresource_range(subres.aspect, subres.mipLevel, 1, subres.arraySlice, 1); |
| 726 | } |
| 727 | |
| 728 | inline XGL_EXTENT2D Image::extent(int32_t width, int32_t height) |
| 729 | { |
| 730 | XGL_EXTENT2D extent = {}; |
| 731 | extent.width = width; |
| 732 | extent.height = height; |
| 733 | return extent; |
| 734 | } |
| 735 | |
| 736 | inline XGL_EXTENT2D Image::extent(const XGL_EXTENT2D &extent, uint32_t mip_level) |
| 737 | { |
| 738 | const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1; |
| 739 | const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1; |
| 740 | return Image::extent(width, height); |
| 741 | } |
| 742 | |
| 743 | inline XGL_EXTENT2D Image::extent(const XGL_EXTENT3D &extent) |
| 744 | { |
| 745 | return Image::extent(extent.width, extent.height); |
| 746 | } |
| 747 | |
| 748 | inline XGL_EXTENT3D Image::extent(int32_t width, int32_t height, int32_t depth) |
| 749 | { |
| 750 | XGL_EXTENT3D extent = {}; |
| 751 | extent.width = width; |
| 752 | extent.height = height; |
| 753 | extent.depth = depth; |
| 754 | return extent; |
| 755 | } |
| 756 | |
| 757 | inline XGL_EXTENT3D Image::extent(const XGL_EXTENT3D &extent, uint32_t mip_level) |
| 758 | { |
| 759 | const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1; |
| 760 | const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1; |
| 761 | const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1; |
| 762 | return Image::extent(width, height, depth); |
| 763 | } |
| 764 | |
| 765 | inline XGL_SHADER_CREATE_INFO Shader::create_info(size_t code_size, const void *code, XGL_FLAGS flags) |
| 766 | { |
| 767 | XGL_SHADER_CREATE_INFO info = {}; |
| 768 | info.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
| 769 | info.codeSize = code_size; |
| 770 | info.pCode = code; |
| 771 | info.flags = flags; |
| 772 | return info; |
| 773 | } |
| 774 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 775 | inline XGL_BUFFER_VIEW_ATTACH_INFO DescriptorSet::attach_info(const BufferView &view) |
| 776 | { |
| 777 | XGL_BUFFER_VIEW_ATTACH_INFO info = {}; |
| 778 | info.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_ATTACH_INFO; |
| 779 | info.view = view.obj(); |
| 780 | return info; |
| 781 | } |
| 782 | |
| 783 | inline XGL_IMAGE_VIEW_ATTACH_INFO DescriptorSet::attach_info(const ImageView &view, XGL_IMAGE_LAYOUT layout) |
| 784 | { |
| 785 | XGL_IMAGE_VIEW_ATTACH_INFO info = {}; |
| 786 | info.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO; |
| 787 | info.view = view.obj(); |
| 788 | info.layout = layout; |
| 789 | return info; |
| 790 | } |
| 791 | |
| 792 | inline XGL_UPDATE_SAMPLERS DescriptorSet::update(uint32_t index, uint32_t count, const XGL_SAMPLER *samplers) |
| 793 | { |
| 794 | XGL_UPDATE_SAMPLERS info = {}; |
| 795 | info.sType = XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS; |
| 796 | info.index = index; |
| 797 | info.count = count; |
| 798 | info.pSamplers = samplers; |
| 799 | return info; |
| 800 | } |
| 801 | |
| 802 | inline XGL_UPDATE_SAMPLERS DescriptorSet::update(uint32_t index, const std::vector<XGL_SAMPLER> &samplers) |
| 803 | { |
| 804 | return update(index, samplers.size(), &samplers[0]); |
| 805 | } |
| 806 | |
| 807 | inline XGL_UPDATE_SAMPLER_TEXTURES DescriptorSet::update(uint32_t index, uint32_t count, const XGL_SAMPLER_IMAGE_VIEW_INFO *textures) |
| 808 | { |
| 809 | XGL_UPDATE_SAMPLER_TEXTURES info = {}; |
| 810 | info.sType = XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES; |
| 811 | info.index = index; |
| 812 | info.count = count; |
| 813 | info.pSamplerImageViews = textures; |
| 814 | return info; |
| 815 | } |
| 816 | |
| 817 | inline XGL_UPDATE_SAMPLER_TEXTURES DescriptorSet::update(uint32_t index, const std::vector<XGL_SAMPLER_IMAGE_VIEW_INFO> &textures) |
| 818 | { |
| 819 | return update(index, textures.size(), &textures[0]); |
| 820 | } |
| 821 | |
| 822 | inline XGL_UPDATE_IMAGES DescriptorSet::update(XGL_DESCRIPTOR_TYPE type, uint32_t index, uint32_t count, |
| 823 | const XGL_IMAGE_VIEW_ATTACH_INFO * const *views) |
| 824 | { |
| 825 | XGL_UPDATE_IMAGES info = {}; |
| 826 | info.sType = XGL_STRUCTURE_TYPE_UPDATE_IMAGES; |
| 827 | info.descriptorType = type; |
| 828 | info.index = index; |
| 829 | info.count = count; |
| 830 | info.pImageViews = views; |
| 831 | return info; |
| 832 | } |
| 833 | |
| 834 | inline XGL_UPDATE_IMAGES DescriptorSet::update(XGL_DESCRIPTOR_TYPE type, uint32_t index, |
| 835 | const std::vector<const XGL_IMAGE_VIEW_ATTACH_INFO *> &views) |
| 836 | { |
| 837 | return update(type, index, views.size(), &views[0]); |
| 838 | } |
| 839 | |
| 840 | inline XGL_UPDATE_BUFFERS DescriptorSet::update(XGL_DESCRIPTOR_TYPE type, uint32_t index, uint32_t count, |
| 841 | const XGL_BUFFER_VIEW_ATTACH_INFO * const *views) |
| 842 | { |
| 843 | XGL_UPDATE_BUFFERS info = {}; |
| 844 | info.sType = XGL_STRUCTURE_TYPE_UPDATE_BUFFERS; |
| 845 | info.descriptorType = type; |
| 846 | info.index = index; |
| 847 | info.count = count; |
| 848 | info.pBufferViews = views; |
| 849 | return info; |
| 850 | } |
| 851 | |
| 852 | inline XGL_UPDATE_BUFFERS DescriptorSet::update(XGL_DESCRIPTOR_TYPE type, uint32_t index, |
| 853 | const std::vector<const XGL_BUFFER_VIEW_ATTACH_INFO *> &views) |
| 854 | { |
| 855 | return update(type, index, views.size(), &views[0]); |
| 856 | } |
| 857 | |
| 858 | inline XGL_UPDATE_AS_COPY DescriptorSet::update(XGL_DESCRIPTOR_TYPE type, uint32_t index, uint32_t count, const DescriptorSet &set) |
| 859 | { |
| 860 | XGL_UPDATE_AS_COPY info = {}; |
| 861 | info.sType = XGL_STRUCTURE_TYPE_UPDATE_AS_COPY; |
| 862 | info.descriptorType = type; |
| 863 | info.descriptorIndex = index; // whose index? |
| 864 | info.count = count; |
| 865 | info.descriptorSet = set.obj(); |
| 866 | return info; |
| 867 | } |
| 868 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 869 | inline XGL_CMD_BUFFER_CREATE_INFO CmdBuffer::create_info(XGL_QUEUE_TYPE type) |
| 870 | { |
| 871 | XGL_CMD_BUFFER_CREATE_INFO info = {}; |
| 872 | info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO; |
| 873 | info.queueType = type; |
| 874 | return info; |
| 875 | } |
| 876 | |
| 877 | }; // namespace xgl_testing |
| 878 | |
| 879 | #endif // XGLTESTBINDING_H |