DPC++ Runtime
Runtime libraries for oneAPI DPC++
bindless_images_descriptor.hpp
Go to the documentation of this file.
1 //==------ bindless_images_descriptor.hpp --- SYCL bindless images ---------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <sycl/detail/array.hpp> // for array
12 #include <sycl/exception.hpp> // for errc, exception
13 #include <sycl/image.hpp> // for image_channel_order, image_channel_type
14 #include <sycl/range.hpp> // for range
15 
16 #include <algorithm> // for max
17 #include <stddef.h> // for size_t
18 #include <system_error> // for error_code
19 
20 namespace sycl {
21 inline namespace _V1 {
22 namespace ext::oneapi::experimental {
23 
25 enum class image_type : unsigned int {
26  standard = 0,
27  interop = 1,
28  mipmap = 2,
29  cubemap = 3, /* Not implemented */
30  layered = 4, /* Not implemented */
31 };
32 
35  size_t width;
36  size_t height;
37  size_t depth;
41  unsigned int num_levels;
42 
43  image_descriptor() = default;
44 
48  unsigned int num_levels = 1)
49  : width(dims[0]), height(0), depth(0), channel_order(channel_order),
51 
55  unsigned int num_levels = 1)
56  : width(dims[0]), height(dims[1]), depth(0), channel_order(channel_order),
58 
62  unsigned int num_levels = 1)
63  : width(dims[0]), height(dims[1]), depth(dims[2]),
66 
69  // Check that this descriptor describes a mipmap - otherwise throw
70  if (this->type != image_type::mipmap)
71  throw sycl::exception(
72  sycl::errc::invalid,
73  "Invalid descriptor `image_type` passed to "
74  "`get_mip_level_desc`. A mipmap level descriptor can only be "
75  "requested by a descriptor with mipmap image type!");
76 
77  // Generate a new descriptor which represents the level accordingly
78  // Do not allow height/depth values to be clamped to 1 when naturally 0
79  size_t width = std::max<size_t>(this->width >> level, 1);
80  size_t height = this->height == 0
81  ? this->height
82  : std::max<size_t>(this->height >> level, 1);
83  size_t depth = this->depth == 0 ? this->depth
84  : std::max<size_t>(this->depth >> level, 1);
85 
86  // This will generate the new descriptor with image_type standard
87  // since individual mip levels are standard images
89  {width, height, depth}, this->channel_order, this->channel_type);
90 
91  return levelDesc;
92  }
93 };
94 
95 } // namespace ext::oneapi::experimental
96 } // namespace _V1
97 } // namespace sycl
image_channel_order
Definition: image.hpp:57
image_channel_type
Definition: image.hpp:75
Definition: access.hpp:18
A struct to describe the properties of an image.
image_descriptor(range< 3 > dims, image_channel_order channel_order, image_channel_type channel_type, image_type type=image_type::standard, unsigned int num_levels=1)
image_descriptor get_mip_level_desc(unsigned int level) const
Get the descriptor for a mipmap level.
image_descriptor(range< 1 > dims, image_channel_order channel_order, image_channel_type channel_type, image_type type=image_type::standard, unsigned int num_levels=1)
image_descriptor(range< 2 > dims, image_channel_order channel_order, image_channel_type channel_type, image_type type=image_type::standard, unsigned int num_levels=1)