Blender V5.0
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
58/* Cannot write to a read only image. */
59IMG_TEMPLATE uint imageAtomicAdd(const T &, IntCoord, uint) = delete;
60IMG_TEMPLATE uint imageAtomicMin(const T &, IntCoord, uint) = delete;
61IMG_TEMPLATE uint imageAtomicMax(const T &, IntCoord, uint) = delete;
62IMG_TEMPLATE uint imageAtomicAnd(const T &, IntCoord, uint) = delete;
63IMG_TEMPLATE uint imageAtomicXor(const T &, IntCoord, uint) = delete;
64IMG_TEMPLATE uint imageAtomicOr(const T &, IntCoord, uint) = delete;
65IMG_TEMPLATE uint imageAtomicExchange(const T &, IntCoord, uint) = delete;
66IMG_TEMPLATE uint imageAtomicCompSwap(const T &, IntCoord, uint, uint) = delete;
67
68#undef IMG_TEMPLATE
69
79
86
91
94
95/* Forbid Cube and cube arrays. Bind them as 3D textures instead. */
96
98
99#undef RET
unsigned int uint
#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