98 "Buffer size need to be aligned to size of float4.");
167template<
typename T,
int64_t len,
bool device_only>
175 const char *
name_ =
"UniformBuffer";
210template<
typename T,
int64_t len,
bool device_only>
218 const char *
name_ =
"StorageBuffer";
294 MEM_freeN(
static_cast<void *
>(this->data_));
309 this->data_ =
static_cast<T *
>(
this);
314 *
static_cast<T *
>(
this) = other;
331 bool device_only =
false>
343 MEM_freeN(
static_cast<void *
>(this->data_));
350 if (new_size != this->len_) {
353 memcpy(new_data_, this->data_,
min_uu(this->len_, new_size) *
sizeof(
T));
354 MEM_freeN(
static_cast<void *
>(this->data_));
355 this->data_ = new_data_;
358 this->len_ = new_size;
368 if (index >= this->len_) {
372 return this->data_[index];
382 required_size = std::max(required_size,
len);
384 if (this->len_ > target_size) {
385 this->
resize(target_size);
396 return {this->data_, this->len_};
401 std::swap(a.
data_,
b.data_);
402 std::swap(a.
ssbo_,
b.ssbo_);
403 std::swap(a.
len_,
b.len_);
404 std::swap(a.
name_,
b.name_);
454 template<
typename... ForwardT>
void append_as(ForwardT &&...value)
456 if (item_len_ >= this->len_) {
460 T *
ptr = &this->data_[item_len_++];
461 new (
ptr)
T(std::forward<ForwardT>(value)...);
467 for (
auto v : values) {
479 return this->
size() == 0;
488 std::swap(a.item_len_,
b.item_len_);
496 bool device_only =
false>
502 this->data_ =
static_cast<T *
>(
this);
507 *
static_cast<T *
>(
this) = other;
514 SWAP(
T,
static_cast<T>(a),
static_cast<T>(
b));
515 std::swap(a.
ssbo_,
b.ssbo_);
541 const float *
data =
nullptr,
542 bool cubemap =
false,
546 tx_ = create(extent, 0, 0, mip_len,
format, usage,
data,
false, cubemap);
554 const float *
data =
nullptr,
555 bool cubemap =
false,
559 tx_ = create(extent, layers, 0, mip_len,
format, usage,
data,
true, cubemap);
566 const float *
data =
nullptr,
578 const float *
data =
nullptr,
589 const float *
data =
nullptr,
628 if (
this != std::addressof(a)) {
632 this->name_ = a.
name_;
633 this->stencil_view_ = a.stencil_view_;
634 this->layer_range_view_ = a.layer_range_view_;
635 this->mip_views_ = std::move(a.mip_views_);
636 this->layer_views_ = std::move(a.layer_views_);
640 a.stencil_view_ =
nullptr;
641 a.layer_range_view_ =
nullptr;
642 a.mip_views_.clear();
643 a.layer_views_.clear();
655 const float *
data =
nullptr,
658 return ensure_impl(extent, 0, 0, mip_len,
format, usage,
data,
false,
false);
669 const float *
data =
nullptr,
673 return ensure_impl(extent, layers, 0, mip_len,
format, usage,
data,
true,
false);
683 const float *
data =
nullptr,
686 return ensure_impl(
UNPACK2(extent), 0, mip_len,
format, usage,
data,
false,
false);
697 const float *
data =
nullptr,
701 return ensure_impl(
UNPACK2(extent), layers, mip_len,
format, usage,
data,
true,
false);
711 const float *
data =
nullptr,
724 float *
data =
nullptr,
727 return ensure_impl(extent, extent, 0, mip_len,
format, usage,
data,
false,
true);
738 const float *
data =
nullptr,
741 return ensure_impl(extent, extent, layers, mip_len,
format, usage,
data,
true,
true);
768 "Incorrect mip level requested. "
769 "Might be missing call to ensure_mip_views().");
830 "Layer range needs to be valid");
833 if (layer_len != view_layer_len) {
837 name_,
tx_,
format, 0, 9999, layer_start, layer_len, cube_as_array,
false);
847 return tx_ !=
nullptr;
978 std::swap(a.
tx_,
b.tx_);
979 std::swap(a.
name_,
b.name_);
1002 bool ensure_impl(
int w,
1008 const float *
data =
nullptr,
1009 bool layered =
false,
1010 bool cubemap =
false)
1024 if (
tx_ ==
nullptr) {
1025 tx_ = create(
w, h, d, mip_len,
format, usage,
data, layered, cubemap);
1034 gpu::Texture *create(
int w,
1087 if (this->tx_ ==
nullptr) {
1091 this->tx_ =
nullptr;
1145 this->tx_ =
nullptr;
1178 return reinterpret_cast<Image *
>(tex);
1183 return reinterpret_cast<Image **
>(tex);
1226 if (fb_ ==
nullptr) {
1230 depth, color1, color2, color3, color4, color5, color6, color7, color8};
1239 if (fb_ ==
nullptr) {
1259 this->name_ = a.
name_;
1280 std::swap(a.fb_,
b.fb_);
1281 std::swap(a.name_,
b.name_);
1296 std::array<T, len> chain_;
1302 auto i_next = (
i + 1) %
len;
1303 if constexpr (std::is_trivial_v<T>) {
1304 std::swap(chain_[
i], chain_[i_next]);
1307 T::swap(chain_[
i], chain_[i_next]);
1325 return chain_[(0 +
len - 1) %
len];
1330 return chain_[(0 + 1) %
len];
1341 return chain_[(0 +
len - 1) %
len];
1346 return chain_[(0 + 1) %
len];
#define BLI_assert_msg(a, msg)
MINLINE uint min_uu(uint a, uint b)
MINLINE unsigned int power_of_2_max_u(unsigned int x)
blender::gpu::FrameBuffer * GPU_framebuffer_create(const char *name)
void GPU_framebuffer_default_size(blender::gpu::FrameBuffer *fb, int width, int height)
#define GPU_FRAMEBUFFER_FREE_SAFE(fb)
#define GPU_ATTACHMENT_NONE
void GPU_framebuffer_clear_depth(blender::gpu::FrameBuffer *fb, float clear_depth)
void GPU_framebuffer_config_array(blender::gpu::FrameBuffer *fb, const GPUAttachment *config, int config_len)
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
void GPU_storagebuf_free(blender::gpu::StorageBuf *ssbo)
blender::gpu::StorageBuf * GPU_storagebuf_create_ex(size_t size, const void *data, GPUUsageType usage, const char *name)
void GPU_storagebuf_clear_to_zero(blender::gpu::StorageBuf *ssbo)
void GPU_storagebuf_update(blender::gpu::StorageBuf *ssbo, const void *data)
void GPU_storagebuf_sync_to_host(blender::gpu::StorageBuf *ssbo)
void GPU_storagebuf_read(blender::gpu::StorageBuf *ssbo, void *data)
int GPU_texture_mip_count(const blender::gpu::Texture *texture)
void GPU_texture_clear(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
blender::gpu::Texture * GPU_texture_create_view(const char *name, blender::gpu::Texture *source_texture, blender::gpu::TextureFormat view_format, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array, bool use_stencil)
blender::gpu::Texture * GPU_texture_create_2d_array(const char *name, int width, int height, int layer_len, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_get_mipmap_size(blender::gpu::Texture *texture, int mip_level, int *r_size)
int GPU_texture_height(const blender::gpu::Texture *texture)
blender::gpu::Texture * GPU_texture_create_cube(const char *name, int width, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
bool GPU_texture_has_integer_format(const blender::gpu::Texture *texture)
bool GPU_texture_has_depth_format(const blender::gpu::Texture *texture)
blender::gpu::Texture * GPU_texture_create_1d_array(const char *name, int width, int layer_len, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
blender::gpu::TextureFormat GPU_texture_format(const blender::gpu::Texture *texture)
bool GPU_texture_has_stencil_format(const blender::gpu::Texture *texture)
int GPU_texture_width(const blender::gpu::Texture *texture)
bool GPU_texture_has_signed_format(const blender::gpu::Texture *texture)
blender::gpu::Texture * GPU_texture_create_cube_array(const char *name, int width, int layer_len, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
@ GPU_TEXTURE_USAGE_GENERAL
void * GPU_texture_read(blender::gpu::Texture *texture, eGPUDataFormat data_format, int mip_level)
bool GPU_texture_is_cube(const blender::gpu::Texture *texture)
bool GPU_texture_has_float_format(const blender::gpu::Texture *texture)
#define GPU_TEXTURE_FREE_SAFE(texture)
blender::gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
int GPU_texture_dimensions(const blender::gpu::Texture *texture)
void GPU_texture_filter_mode(blender::gpu::Texture *texture, bool use_filter)
int GPU_texture_layer_count(const blender::gpu::Texture *texture)
int GPU_texture_depth(const blender::gpu::Texture *texture)
bool GPU_texture_has_normalized_format(const blender::gpu::Texture *texture)
blender::gpu::Texture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const void *data)
blender::gpu::Texture * GPU_texture_create_1d(const char *name, int width, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
bool GPU_texture_is_array(const blender::gpu::Texture *texture)
Read Guarded memory(de)allocation.
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
static void swap(Framebuffer &a, Framebuffer &b)
Framebuffer(const char *name)
void ensure(int2 target_size)
gpu::FrameBuffer ** operator&()
Framebuffer & operator=(Framebuffer &&a)
void clear_depth(float depth)
void ensure(GPUAttachment depth=GPU_ATTACHMENT_NONE, GPUAttachment color1=GPU_ATTACHMENT_NONE, GPUAttachment color2=GPU_ATTACHMENT_NONE, GPUAttachment color3=GPU_ATTACHMENT_NONE, GPUAttachment color4=GPU_ATTACHMENT_NONE, GPUAttachment color5=GPU_ATTACHMENT_NONE, GPUAttachment color6=GPU_ATTACHMENT_NONE, GPUAttachment color7=GPU_ATTACHMENT_NONE, GPUAttachment color8=GPU_ATTACHMENT_NONE)
StorageArrayBuffer(const char *name=nullptr)
static void swap(StorageArrayBuffer &a, StorageArrayBuffer &b)
void resize(int64_t new_size)
T & get_or_resize(int64_t index)
MutableSpan< T > as_span() const
void trim_to_next_power_of_2(int64_t required_size)
static void swap(StorageBuffer< T > &a, StorageBuffer< T > &b)
StorageBuffer< T > & operator=(const T &other)
StorageBuffer(const char *name=nullptr)
void clear_to_zero()=delete
StorageVectorBuffer(const char *name=nullptr)
void append(const T &value)
static void swap(StorageVectorBuffer &a, StorageVectorBuffer &b)
void append_as(ForwardT &&...value)
void extend(const Span< T > values)
~StorageVectorBuffer()=default
const T & previous() const
const T & current() const
bool ensure_1d_array(int, int, int, blender::gpu::TextureFormat, eGPUTextureUsage, const float *)=delete
static void swap(TextureFromPool &a, Texture &b)
void acquire(int2 extent, blender::gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL)
gpu::Texture * layer_view(int)=delete
bool ensure_cube(int, int, blender::gpu::TextureFormat, eGPUTextureUsage, const float *)=delete
bool ensure_cube_array(int, int, int, blender::gpu::TextureFormat, eGPUTextureUsage, const float *)=delete
gpu::Texture * stencil_view()=delete
static void swap(TextureFromPool &a, TextureFromPool &b)
static void swap(Texture &a, TextureFromPool &b)
bool ensure_3d(int, int, int, int, blender::gpu::TextureFormat, eGPUTextureUsage, const float *)=delete
TextureFromPool(const char *name="gpu::Texture")
bool ensure_2d_array(int, int, int, int, blender::gpu::TextureFormat, eGPUTextureUsage, const float *)=delete
void filter_mode(bool)=delete
gpu::Texture * mip_view(int)=delete
bool ensure_1d(int, int, blender::gpu::TextureFormat, eGPUTextureUsage, const float *)=delete
bool ensure_2d(int, int, int, blender::gpu::TextureFormat, eGPUTextureUsage, float *)=delete
gpu::Texture * layer_view(int)=delete
bool ensure_1d(int, int, blender::gpu::TextureFormat, const float *)=delete
bool ensure_cube(int, int, blender::gpu::TextureFormat, const float *)=delete
gpu::Texture * mip_view(int)=delete
bool ensure_cube_array(int, int, int, blender::gpu::TextureFormat, const float *)=delete
void filter_mode(bool)=delete
gpu::Texture * stencil_view()=delete
bool ensure_2d_array(int, int, int, int, blender::gpu::TextureFormat, const float *)=delete
bool ensure_3d(int, int, int, int, blender::gpu::TextureFormat, const float *)=delete
bool ensure_1d_array(int, int, int, blender::gpu::TextureFormat, const float *)=delete
bool ensure_2d(int, int, int, blender::gpu::TextureFormat, const float *)=delete
void wrap(gpu::Texture *tex)
Texture(const char *name, blender::gpu::TextureFormat format, eGPUTextureUsage usage, int2 extent, const float *data=nullptr, int mip_len=1)
gpu::Texture * stencil_view_
bool ensure_1d(blender::gpu::TextureFormat format, int extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
bool ensure_2d_array(blender::gpu::TextureFormat format, int2 extent, int layers, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
bool ensure_mip_views(bool cube_as_array=false)
void free_texture_views()
static void swap(Texture &a, Texture &b)
gpu::Texture * gpu_texture()
Texture(const char *name, blender::gpu::TextureFormat format, eGPUTextureUsage usage, int2 extent, int layers, const float *data=nullptr, int mip_len=1)
Texture(const char *name="gpu::Texture")
void clear(float4 values)
T * read(eGPUDataFormat format, int miplvl=0)
gpu::Texture ** operator&()
bool ensure_1d_array(blender::gpu::TextureFormat format, int extent, int layers, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
Vector< gpu::Texture *, 0 > layer_views_
bool ensure_cube(blender::gpu::TextureFormat format, int extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, float *data=nullptr, int mip_len=1)
bool ensure_cube_array(blender::gpu::TextureFormat format, int extent, int layers, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
void filter_mode(bool do_filter)
Texture(const char *name, blender::gpu::TextureFormat format, eGPUTextureUsage usage, int3 extent, const float *data=nullptr, int mip_len=1)
bool ensure_2d(blender::gpu::TextureFormat format, int2 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
bool ensure_layer_views(bool cube_as_array=false)
gpu::Texture * layer_view(int layer)
Vector< gpu::Texture *, 0 > mip_views_
gpu::Texture * layer_range_view_
Texture(const char *name, blender::gpu::TextureFormat format, eGPUTextureUsage usage, int extent, int layers, const float *data=nullptr, bool cubemap=false, int mip_len=1)
gpu::Texture * layer_range_view(int layer_start, int layer_len, bool cube_as_array=false)
Texture & operator=(Texture &&a)
int3 size(int miplvl=0) const
bool ensure_3d(blender::gpu::TextureFormat format, int3 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
gpu::Texture * mip_view(int miplvl)
Texture(Texture &&other)=default
gpu::Texture * stencil_view(bool cube_as_array=false)
Texture(const char *name, blender::gpu::TextureFormat format, eGPUTextureUsage usage, int extent, const float *data=nullptr, bool cubemap=false, int mip_len=1)
BLI_STATIC_ASSERT(((sizeof(T) *len) % 16)==0, "Buffer size need to be aligned to size of float4.")
T & operator[](int64_t index)
const T & operator[](int64_t index) const
StorageCommon(const char *name=nullptr)
gpu::StorageBuf ** operator&()
void async_flush_to_host()
StorageVectorBuffer(const char *name=nullptr)
TextureFromPool(const char *name="gpu::Texture")
Texture(const char *name="gpu::Texture")
char name_[DEBUG_NAME_LEN]
blender::gpu::Texture * acquire_texture(int width, int height, blender::gpu::TextureFormat format, eGPUTextureUsage usage)
void give_texture_ownership(blender::gpu::Texture *tex)
void take_texture_ownership(blender::gpu::Texture *tex)
static TexturePool & get()
void release_texture(blender::gpu::Texture *tmp_tex)
char name_[DEBUG_NAME_LEN]
void * MEM_mallocN_aligned(size_t len, size_t alignment, const char *str)
void MEM_freeN(void *vmemh)
static gpu::Texture * as_texture(Image *img)
BLI_STATIC_ASSERT(MBC_BATCH_LEN< 64, "Number of batches exceeded the limit of bit fields")
static Image * as_image(gpu::Texture *tex)
VecBase< int32_t, 4 > int4
VecBase< uint32_t, 4 > uint4
bool assign_if_different(T &old_value, T new_value)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3