Blender V5.3
gpu_shader_cxx_image.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
14
15/* Some compilers complain about lack of return values. Keep it short. */
16#define RET \
17 { \
18 return {}; \
19 }
20
21/* -------------------------------------------------------------------- */
24
25template<typename T, int Dimensions, bool Array = false, bool Atomic = false> struct ImageBase {
26 static constexpr int coord_dim = Dimensions + int(Array);
27
31};
32
33#define IMG_TEMPLATE \
34 template<typename T, \
35 typename IntCoord = typename T::int_coord_type, \
36 typename DataVec = typename T::data_vec_type, \
37 typename SizeVec = typename T::size_vec_type>
38
39IMG_TEMPLATE SizeVec imageSize(const T &) RET;
40IMG_TEMPLATE DataVec imageLoad(const T &, IntCoord) RET;
41IMG_TEMPLATE void imageStore(T &, IntCoord, DataVec) {}
43/* Cannot write to a read only image. */
44IMG_TEMPLATE void imageStore(const T &, IntCoord, DataVec) = delete;
45IMG_TEMPLATE void imageFence(const T &) = delete;
46
47#define imageLoadFast imageLoad
48#define imageStoreFast imageStore
49
50IMG_TEMPLATE uint imageAtomicAdd(T &, IntCoord, uint) RET;
51IMG_TEMPLATE uint imageAtomicMin(T &, IntCoord, uint) RET;
52IMG_TEMPLATE uint imageAtomicMax(T &, IntCoord, uint) RET;
53IMG_TEMPLATE uint imageAtomicAnd(T &, IntCoord, uint) RET;
54IMG_TEMPLATE uint imageAtomicXor(T &, IntCoord, uint) RET;
55IMG_TEMPLATE uint imageAtomicOr(T &, IntCoord, uint) RET;
56IMG_TEMPLATE uint imageAtomicExchange(T &, IntCoord, uint) RET;
57IMG_TEMPLATE uint imageAtomicCompSwap(T &, IntCoord, uint, uint) RET;
58IMG_TEMPLATE int imageAtomicAdd(T &, IntCoord, int) RET;
59IMG_TEMPLATE int imageAtomicMin(T &, IntCoord, int) RET;
60IMG_TEMPLATE int imageAtomicMax(T &, IntCoord, int) RET;
61IMG_TEMPLATE int imageAtomicAnd(T &, IntCoord, int) RET;
62IMG_TEMPLATE int imageAtomicXor(T &, IntCoord, int) RET;
63IMG_TEMPLATE int imageAtomicOr(T &, IntCoord, int) RET;
64IMG_TEMPLATE int imageAtomicExchange(T &, IntCoord, int) RET;
65IMG_TEMPLATE int imageAtomicCompSwap(T &, IntCoord, int, int) RET;
66/* Cannot write to a read only image. */
67IMG_TEMPLATE uint imageAtomicAdd(const T &, IntCoord, uint) = delete;
68IMG_TEMPLATE uint imageAtomicMin(const T &, IntCoord, uint) = delete;
69IMG_TEMPLATE uint imageAtomicMax(const T &, IntCoord, uint) = delete;
70IMG_TEMPLATE uint imageAtomicAnd(const T &, IntCoord, uint) = delete;
71IMG_TEMPLATE uint imageAtomicXor(const T &, IntCoord, uint) = delete;
72IMG_TEMPLATE uint imageAtomicOr(const T &, IntCoord, uint) = delete;
73IMG_TEMPLATE uint imageAtomicExchange(const T &, IntCoord, uint) = delete;
74IMG_TEMPLATE uint imageAtomicCompSwap(const T &, IntCoord, uint, uint) = delete;
75IMG_TEMPLATE int imageAtomicAdd(const T &, IntCoord, int) = delete;
76IMG_TEMPLATE int imageAtomicMin(const T &, IntCoord, int) = delete;
77IMG_TEMPLATE int imageAtomicMax(const T &, IntCoord, int) = delete;
78IMG_TEMPLATE int imageAtomicAnd(const T &, IntCoord, int) = delete;
79IMG_TEMPLATE int imageAtomicXor(const T &, IntCoord, int) = delete;
80IMG_TEMPLATE int imageAtomicOr(const T &, IntCoord, int) = delete;
81IMG_TEMPLATE int imageAtomicExchange(const T &, IntCoord, int) = delete;
82IMG_TEMPLATE int imageAtomicCompSwap(const T &, IntCoord, int, int) = delete;
83
84#undef IMG_TEMPLATE
85
95
102
107
110
111/* Forbid Cube and cube arrays. Bind them as 3D textures instead. */
112
114
115#undef RET
#define RET
ImageBase< uint, 2, true, true > uimage2DArrayAtomic
ImageBase< int, 3, false, true > iimage3DAtomic
ImageBase< int, 2 > iimage2D
ImageBase< uint, 2 > uimage2D
ImageBase< int, 2, true, true > iimage2DArrayAtomic
ImageBase< int, 1, true > iimage1DArray
IMG_TEMPLATE uint imageAtomicXor(T &, IntCoord, uint) RET
IMG_TEMPLATE DataVec imageLoad(const T &, IntCoord) RET
IMG_TEMPLATE uint imageAtomicMax(T &, IntCoord, uint) RET
ImageBase< uint, 2, false, true > uimage2DAtomic
IMG_TEMPLATE uint imageAtomicAdd(T &, IntCoord, uint) RET
ImageBase< float, 1, true > image1DArray
ImageBase< uint, 3, false, true > uimage3DAtomic
IMG_TEMPLATE uint imageAtomicAnd(T &, IntCoord, uint) RET
ImageBase< uint, 2, true > uimage2DArray
ImageBase< float, 2, true > image2DArray
ImageBase< int, 1 > iimage1D
ImageBase< float, 2 > image2D
ImageBase< int, 2, true > iimage2DArray
IMG_TEMPLATE void imageFence(T &)
ImageBase< float, 3 > image3D
ImageBase< float, 1 > image1D
IMG_TEMPLATE SizeVec imageSize(const T &) RET
IMG_TEMPLATE uint imageAtomicCompSwap(T &, IntCoord, uint, uint) RET
IMG_TEMPLATE uint imageAtomicMin(T &, IntCoord, uint) RET
ImageBase< uint, 3 > uimage3D
ImageBase< int, 3 > iimage3D
IMG_TEMPLATE uint imageAtomicExchange(T &, IntCoord, uint) RET
ImageBase< int, 2, false, true > iimage2DAtomic
#define IMG_TEMPLATE
IMG_TEMPLATE uint imageAtomicOr(T &, IntCoord, uint) RET
ImageBase< uint, 1, true > uimage1DArray
ImageBase< uint, 1 > uimage1D
IMG_TEMPLATE void imageStore(T &, IntCoord, DataVec)
#define T
VecBase< int, coord_dim > int_coord_type
VecBase< T, 4 > data_vec_type
VecBase< int, coord_dim > size_vec_type
static constexpr int coord_dim