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";
290 this->data_ =
static_cast<T *
>(
295 MEM_delete(this->data_);
310 this->data_ =
static_cast<T *
>(
this);
315 *
static_cast<T *
>(
this) = other;
332 bool device_only =
false>
338 this->data_ =
static_cast<T *
>(
343 MEM_delete(this->data_);
350 if (new_size != this->len_) {
352 T *new_data_ =
static_cast<T *
>(
354 memcpy(
reinterpret_cast<void *
>(new_data_),
356 min_uu(this->len_, new_size) *
sizeof(
T));
357 MEM_delete(this->data_);
358 this->data_ = new_data_;
361 this->len_ = new_size;
371 if (
index >= this->len_) {
375 return this->data_[
index];
385 required_size = std::max(required_size,
len);
387 if (this->len_ > target_size) {
388 this->
resize(target_size);
399 return {this->data_, this->len_};
404 std::swap(a.
data_,
b.data_);
405 std::swap(a.
ssbo_,
b.ssbo_);
406 std::swap(a.
len_,
b.len_);
407 std::swap(a.
name_,
b.name_);
457 template<
typename... ForwardT>
void append_as(ForwardT &&...value)
459 if (item_len_ >= this->len_) {
463 T *ptr = &this->data_[item_len_++];
464 new (ptr)
T(std::forward<ForwardT>(value)...);
470 for (
auto v : values) {
482 return this->
size() == 0;
491 std::swap(a.item_len_,
b.item_len_);
499 bool device_only =
false>
505 this->data_ =
static_cast<T *
>(
this);
510 *
static_cast<T *
>(
this) = other;
517 SWAP(
T,
static_cast<T>(a),
static_cast<T>(
b));
518 std::swap(a.
ssbo_,
b.ssbo_);
544 const float *
data =
nullptr,
545 bool cubemap =
false,
549 tx_ = create(extent, 0, 0, mip_len, format, usage,
data,
false, cubemap);
557 const float *
data =
nullptr,
558 bool cubemap =
false,
562 tx_ = create(extent, layers, 0, mip_len, format, usage,
data,
true, cubemap);
569 const float *
data =
nullptr,
573 tx_ = create(
UNPACK2(extent), 0, mip_len, format, usage,
data,
false,
false);
581 const float *
data =
nullptr,
585 tx_ = create(
UNPACK2(extent), layers, mip_len, format, usage,
data,
true,
false);
592 const float *
data =
nullptr,
596 tx_ = create(
UNPACK3(extent), mip_len, format, usage,
data,
false,
false);
631 if (
this != std::addressof(a)) {
635 this->name_ = a.
name_;
636 this->stencil_view_ = a.stencil_view_;
637 this->layer_range_view_ = a.layer_range_view_;
638 this->mip_views_ = std::move(a.mip_views_);
639 this->layer_views_ = std::move(a.layer_views_);
643 a.stencil_view_ =
nullptr;
644 a.layer_range_view_ =
nullptr;
645 a.mip_views_.clear();
646 a.layer_views_.clear();
658 const float *
data =
nullptr,
661 return ensure_impl(extent, 0, 0, mip_len, format, usage,
data,
false,
false);
672 const float *
data =
nullptr,
676 return ensure_impl(extent, layers, 0, mip_len, format, usage,
data,
true,
false);
686 const float *
data =
nullptr,
689 return ensure_impl(
UNPACK2(extent), 0, mip_len, format, usage,
data,
false,
false);
700 const float *
data =
nullptr,
704 return ensure_impl(
UNPACK2(extent), layers, mip_len, format, usage,
data,
true,
false);
714 const float *
data =
nullptr,
717 return ensure_impl(
UNPACK3(extent), mip_len, format, usage,
data,
false,
false);
727 float *
data =
nullptr,
730 return ensure_impl(extent, extent, 0, mip_len, format, usage,
data,
false,
true);
741 const float *
data =
nullptr,
744 return ensure_impl(extent, extent, layers, mip_len, format, usage,
data,
true,
true);
771 "Incorrect mip level requested. "
772 "Might be missing call to ensure_mip_views().");
813 name_,
tx_, format, 0, 9999, 0, 9999, cube_as_array,
true);
833 "Layer range needs to be valid");
836 if (layer_len != view_layer_len) {
840 name_,
tx_, format, 0, 9999, layer_start, layer_len, cube_as_array,
false);
850 return tx_ !=
nullptr;
981 std::swap(a.
tx_,
b.tx_);
982 std::swap(a.
name_,
b.name_);
1005 bool ensure_impl(
int w,
1011 const float *
data =
nullptr,
1012 bool layered =
false,
1013 bool cubemap =
false)
1027 if (
tx_ ==
nullptr) {
1028 tx_ = create(
w, h, d, mip_len, format, usage,
data, layered, cubemap);
1037 gpu::Texture *create(
int w,
1091 return acquire_impl(extent, 0, 0, mip_len, format, usage,
false,
false);
1104 return acquire_impl(extent, layers, 0, mip_len, format, usage,
true,
false);
1116 return acquire_impl(extent.x, extent.y, 0, mip_len, format, usage,
false,
false);
1129 return acquire_impl(extent.x, extent.y, layers, mip_len, format, usage,
true,
false);
1141 return acquire_impl(extent.x, extent.y, extent.z, mip_len, format, usage,
false,
false);
1153 return acquire_impl(extent, 0, 0, mip_len, format, usage,
false,
true);
1166 return acquire_impl(extent, layers, 0, mip_len, format, usage,
true,
true);
1172 if (
tx_ ==
nullptr) {
1176 pool_->release_texture(
tx_);
1184 pool_->offset_users_count(
tx_, -1);
1191 std::swap(a.pool_,
b.pool_);
1214 bool acquire_impl(
int w,
1223 if (
tx_ !=
nullptr) {
1231 pool_->offset_users_count(
tx_, 1);
1239 tx_ = pool_->acquire_texture_1d(
w, mip_len, format, usage,
name_);
1243 tx_ = pool_->acquire_texture_cube_array(
w, h, mip_len, format, usage,
name_);
1246 tx_ = pool_->acquire_texture_cube(
w, mip_len, format, usage,
name_);
1251 tx_ = pool_->acquire_texture_1d_array(
w, h, mip_len, format, usage,
name_);
1254 tx_ = pool_->acquire_texture_2d({
w, h}, mip_len, format, usage,
name_);
1258 tx_ = pool_->acquire_texture_2d_array({
w, h}, d, mip_len, format, usage,
name_);
1261 tx_ = pool_->acquire_texture_3d({
w, h, d}, mip_len, format, usage,
name_);
1278 this->tx_ =
nullptr;
1311 return reinterpret_cast<Image *
>(tex);
1316 return reinterpret_cast<Image **
>(tex);
1359 if (fb_ ==
nullptr) {
1363 depth, color1, color2, color3, color4, color5, color6, color7, color8};
1372 if (fb_ ==
nullptr) {
1397 this->name_ = a.
name_;
1418 std::swap(a.fb_,
b.fb_);
1419 std::swap(a.name_,
b.name_);
1433 BLI_STATIC_ASSERT(
len > 1,
"A swap-chain needs more than 1 unit in length.");
1434 std::array<T, len> chain_;
1440 auto i_next = (i + 1) %
len;
1441 if constexpr (std::is_trivial_v<T>) {
1442 std::swap(chain_[i], chain_[i_next]);
1445 T::swap(chain_[i], chain_[i_next]);
1463 return chain_[(0 +
len - 1) %
len];
1468 return chain_[(0 + 1) %
len];
1479 return chain_[(0 +
len - 1) %
len];
1484 return chain_[(0 + 1) %
len];
#define GPU_FRAMEBUFFER_FREE_SAFE(fb)
#define GPU_ATTACHMENT_NONE
#define GPU_TEXTURE_FREE_SAFE(texture)
Read Blender memory allocation and freeing.
#define BLI_assert_msg(a, msg)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
constexpr IndexRange()=default
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
static void swap(Framebuffer &a, Framebuffer &b)
void clear_color(float4 color)
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_2d_array(int, int, int, int, gpu::TextureFormat, eGPUTextureUsage, const float *)=delete
bool acquire_3d(int3 extent, gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, int mip_len=1)
bool acquire_cube(int extent, gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, int mip_len=1)
bool ensure_2d(int, int, int, gpu::TextureFormat, eGPUTextureUsage, float *)=delete
static void swap(TextureFromPool &a, TextureFromPool &b)
bool ensure_cube(int, int, gpu::TextureFormat, eGPUTextureUsage, const float *)=delete
void filter_mode(bool)=delete
TextureFromPool(const char *name="draw::TextureFromPool")
bool ensure_1d_array(int, int, int, gpu::TextureFormat, eGPUTextureUsage, const float *)=delete
bool acquire_1d_array(int extent, int layers, gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, int mip_len=1)
bool acquire_2d(int2 extent, gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, int mip_len=1)
bool acquire_1d(int extent, gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, int mip_len=1)
bool acquire_2d_array(int2 extent, int layers, gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, int mip_len=1)
bool ensure_1d(int, int, blender::gpu::TextureFormat, eGPUTextureUsage, const float *)=delete
bool acquire_cube_array(int extent, int layers, gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, int mip_len=1)
bool ensure_3d(int, int, int, int, gpu::TextureFormat, eGPUTextureUsage, const float *)=delete
gpu::Texture * layer_view(int)=delete
bool ensure_cube(int, int, gpu::TextureFormat, const float *)=delete
gpu::Texture * mip_view(int)=delete
bool ensure_cube_array(int, int, int, gpu::TextureFormat, const float *)=delete
void filter_mode(bool)=delete
gpu::Texture * stencil_view()=delete
bool ensure_1d(int, int, gpu::TextureFormat, const float *)=delete
bool ensure_3d(int, int, int, int, gpu::TextureFormat, const float *)=delete
bool ensure_1d_array(int, int, int, gpu::TextureFormat, const float *)=delete
bool ensure_2d(int, int, int, gpu::TextureFormat, const float *)=delete
void wrap(gpu::Texture *tex)
bool ensure_2d_array(int, int, int, int, gpu::TextureFormat, const float *)=delete
gpu::Texture * stencil_view_
bool ensure_mip_views(bool cube_as_array=false)
bool ensure_2d(gpu::TextureFormat format, int2 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
void free_texture_views()
static void swap(Texture &a, Texture &b)
bool ensure_3d(gpu::TextureFormat format, int3 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
gpu::Texture * gpu_texture()
Texture(const char *name="gpu::Texture")
Texture(const char *name, gpu::TextureFormat format, eGPUTextureUsage usage, int extent, const float *data=nullptr, bool cubemap=false, int mip_len=1)
void clear(float4 values)
T * read(eGPUDataFormat format, int miplvl=0)
gpu::Texture ** operator&()
Texture(const char *name, gpu::TextureFormat format, eGPUTextureUsage usage, int3 extent, const float *data=nullptr, int mip_len=1)
Vector< gpu::Texture *, 0 > layer_views_
bool ensure_cube_array(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)
bool ensure_1d_array(gpu::TextureFormat format, int extent, int layers, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
bool ensure_2d_array(gpu::TextureFormat format, int2 extent, int layers, 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, gpu::TextureFormat format, eGPUTextureUsage usage, int2 extent, const float *data=nullptr, int mip_len=1)
gpu::Texture * layer_range_view(int layer_start, int layer_len, bool cube_as_array=false)
Texture & operator=(Texture &&a)
bool ensure_1d(gpu::TextureFormat format, int extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
int3 size(int miplvl=0) const
gpu::Texture * mip_view(int miplvl)
bool ensure_cube(gpu::TextureFormat format, int extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, float *data=nullptr, int mip_len=1)
Texture(Texture &&other)=default
Texture(const char *name, gpu::TextureFormat format, eGPUTextureUsage usage, int2 extent, int layers, const float *data=nullptr, int mip_len=1)
gpu::Texture * stencil_view(bool cube_as_array=false)
Texture(const char *name, gpu::TextureFormat format, eGPUTextureUsage usage, int extent, int layers, 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="draw::TextureFromPool")
Texture(const char *name="gpu::Texture")
char name_[DEBUG_NAME_LEN]
static TexturePool & get()
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
void free(Subdiv *subdiv)
static gpu::Texture * as_texture(Image *img)
static Image * as_image(gpu::Texture *tex)
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void GPU_storagebuf_update(gpu::StorageBuf *ssbo, const void *data)
gpu::Texture * GPU_texture_create_cube_array(const char *name, int width, int layer_len, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
bool GPU_texture_has_depth_format(const gpu::Texture *texture)
gpu::Texture * GPU_texture_create_1d(const char *name, int width, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
int GPU_texture_depth(const gpu::Texture *texture)
bool GPU_texture_has_integer_format(const gpu::Texture *texture)
void GPU_storagebuf_clear_to_zero(gpu::StorageBuf *ssbo)
gpu::TextureFormat GPU_texture_format(const gpu::Texture *texture)
VecBase< int32_t, 4 > int4
eGPUTextureUsage GPU_texture_usage(const gpu::Texture *texture)
void GPU_uniformbuf_free(gpu::UniformBuf *ubo)
bool assign_if_different(T &old_value, T &&new_value)
gpu::StorageBuf * GPU_storagebuf_create_ex(size_t size, const void *data, GPUUsageType usage, const char *name)
VecBase< uint32_t, 4 > uint4
bool GPU_texture_has_signed_format(const gpu::Texture *texture)
void GPU_framebuffer_clear_color(gpu::FrameBuffer *fb, const double4 clear_col)
gpu::Texture * GPU_texture_create_2d_array(const char *name, int width, int height, int layer_len, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
ATTR_WARN_UNUSED_RESULT const BMVert * v
MINLINE unsigned int power_of_2_max_u(unsigned int x)
bool GPU_texture_has_normalized_format(const gpu::Texture *texture)
int GPU_texture_dimensions(const gpu::Texture *texture)
VecBase< float, 4 > float4
void * MEM_new_uninitialized_aligned(size_t len, size_t alignment, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(3)
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
@ GPU_TEXTURE_USAGE_GENERAL
int GPU_texture_mip_count(const gpu::Texture *texture)
BMesh const char void * data
void GPU_texture_filter_mode(gpu::Texture *texture, bool use_filter)
bool GPU_texture_has_float_format(const gpu::Texture *texture)
gpu::Texture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const void *data)
int GPU_texture_width(const gpu::Texture *texture)
bool GPU_texture_is_cube(const gpu::Texture *texture)
void GPU_framebuffer_config_array(gpu::FrameBuffer *fb, const GPUAttachment *config, int config_len)
void GPU_storagebuf_sync_to_host(gpu::StorageBuf *ssbo)
bool GPU_texture_is_array(const gpu::Texture *texture)
gpu::UniformBuf * GPU_uniformbuf_create_ex(size_t size, const void *data, const char *name)
gpu::FrameBuffer * GPU_framebuffer_create(const char *name)
void GPU_framebuffer_clear_depth(gpu::FrameBuffer *fb, float clear_depth)
void GPU_uniformbuf_update(gpu::UniformBuf *ubo, const void *data)
gpu::Texture * GPU_texture_create_cube(const char *name, int width, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_framebuffer_default_size(gpu::FrameBuffer *fb, int width, int height)
void GPU_texture_clear(gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
int GPU_texture_height(const gpu::Texture *texture)
void * GPU_texture_read(gpu::Texture *texture, eGPUDataFormat data_format, int mip_level)
int GPU_texture_layer_count(const gpu::Texture *texture)
void GPU_storagebuf_free(gpu::StorageBuf *ssbo)
gpu::Texture * GPU_texture_create_view(const char *name, gpu::Texture *source_texture, gpu::TextureFormat view_format, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array, bool use_stencil)
bool GPU_texture_has_stencil_format(const gpu::Texture *texture)
VecBase< double, 4 > double4
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_get_mipmap_size(gpu::Texture *texture, int mip_level, int *r_size)
gpu::Texture * GPU_texture_create_1d_array(const char *name, int width, int layer_len, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
MINLINE uint min_uu(uint a, uint b)
void GPU_storagebuf_read(gpu::StorageBuf *ssbo, void *data)