101 "Buffer size need to be aligned to size of float4.");
170template<
typename T,
int64_t len,
bool device_only>
178 const char *
name_ =
"UniformBuffer";
201 operator GPUUniformBuf *()
const
213template<
typename T,
int64_t len,
bool device_only>
221 const char *
name_ =
"StorageBuffer";
261 operator GPUStorageBuf *()
const
312 this->data_ =
static_cast<T *
>(
this);
317 *
static_cast<T *
>(
this) = other;
332 int64_t len = (512u + (
sizeof(
T) - 1)) /
sizeof(T),
334 bool device_only =
false>
351 if (new_size != this->len_) {
354 memcpy(new_data_, this->data_,
min_uu(this->len_, new_size) *
sizeof(T));
356 this->data_ = new_data_;
359 this->len_ = new_size;
369 if (index >= this->len_) {
373 return this->data_[index];
383 required_size = std::max(required_size,
len);
385 if (this->len_ > target_size) {
386 this->
resize(target_size);
397 return {this->
data_, this->len_};
402 std::swap(a.data_,
b.data_);
403 std::swap(a.ssbo_,
b.ssbo_);
404 std::swap(a.len_,
b.len_);
405 std::swap(a.name_,
b.name_);
413 int64_t len = (512u + (
sizeof(
T) - 1)) /
sizeof(T)>
455 template<
typename... ForwardT>
void append_as(ForwardT &&...value)
457 if (item_len_ >= this->len_) {
461 T *
ptr = &this->data_[item_len_++];
462 new (
ptr)
T(std::forward<ForwardT>(value)...);
468 for (
auto v : values) {
480 return this->
size() == 0;
489 std::swap(a.item_len_,
b.item_len_);
497 bool device_only =
false>
503 this->data_ =
static_cast<T *
>(
this);
508 *
static_cast<T *
>(
this) = other;
515 SWAP(T,
static_cast<T
>(a),
static_cast<T
>(
b));
516 std::swap(a.ssbo_,
b.ssbo_);
528 GPUTexture *
tx_ =
nullptr;
542 const float *data =
nullptr,
543 bool cubemap =
false,
547 tx_ = create(extent, 0, 0, mip_len,
format, usage, data,
false, cubemap);
555 const float *data =
nullptr,
556 bool cubemap =
false,
560 tx_ = create(extent, layers, 0, mip_len,
format, usage, data,
true, cubemap);
567 const float *data =
nullptr,
571 tx_ = create(
UNPACK2(extent), 0, mip_len,
format, usage, data,
false,
false);
579 const float *data =
nullptr,
583 tx_ = create(
UNPACK2(extent), layers, mip_len,
format, usage, data,
true,
false);
590 const float *data =
nullptr,
609 operator GPUTexture *()
const
629 if (
this != std::addressof(a)) {
633 this->name_ = a.name_;
634 this->stencil_view_ = a.stencil_view_;
635 this->layer_range_view_ = a.layer_range_view_;
636 this->mip_views_ = std::move(a.mip_views_);
637 this->layer_views_ = std::move(a.layer_views_);
641 a.stencil_view_ =
nullptr;
642 a.layer_range_view_ =
nullptr;
643 a.mip_views_.clear();
644 a.layer_views_.clear();
656 const float *data =
nullptr,
659 return ensure_impl(extent, 0, 0, mip_len,
format, usage, data,
false,
false);
670 const float *data =
nullptr,
674 return ensure_impl(extent, layers, 0, mip_len,
format, usage, data,
true,
false);
684 const float *data =
nullptr,
687 return ensure_impl(
UNPACK2(extent), 0, mip_len,
format, usage, data,
false,
false);
698 const float *data =
nullptr,
702 return ensure_impl(
UNPACK2(extent), layers, mip_len,
format, usage, data,
true,
false);
712 const float *data =
nullptr,
715 return ensure_impl(
UNPACK3(extent), mip_len,
format, usage, data,
false,
false);
725 float *data =
nullptr,
728 return ensure_impl(extent, extent, 0, mip_len,
format, usage, data,
false,
true);
739 const float *data =
nullptr,
742 return ensure_impl(extent, extent, layers, mip_len,
format, usage, data,
true,
true);
769 "Incorrect mip level requested. "
770 "Might be missing call to ensure_mip_views().");
831 "Layer range needs to be valid");
834 if (layer_len != view_layer_len) {
838 name_,
tx_,
format, 0, 9999, layer_start, layer_len, cube_as_array,
false);
848 return tx_ !=
nullptr;
983 std::swap(a.tx_,
b.tx_);
984 std::swap(a.name_,
b.name_);
985 std::swap(a.stencil_view_,
b.stencil_view_);
986 std::swap(a.layer_range_view_,
b.layer_range_view_);
987 std::swap(a.mip_views_,
b.mip_views_);
988 std::swap(a.layer_views_,
b.layer_views_);
992 bool ensure_impl(
int w,
998 const float *data =
nullptr,
999 bool layered =
false,
1000 bool cubemap =
false)
1014 if (
tx_ ==
nullptr) {
1015 tx_ = create(
w, h, d, mip_len,
format, usage, data, layered, cubemap);
1024 GPUTexture *create(
int w,
1086 if (this->tx_ ==
nullptr) {
1090 this->tx_ =
nullptr;
1141 this->tx_ =
nullptr;
1172 return reinterpret_cast<Image *
>(
tex);
1177 return reinterpret_cast<Image **
>(
tex);
1182 return reinterpret_cast<GPUTexture *
>(img);
1187 return reinterpret_cast<GPUTexture **
>(img);
1198 GPUFrameBuffer *fb_ =
nullptr;
1220 if (fb_ ==
nullptr) {
1224 depth, color1, color2, color3, color4, color5, color6, color7, color8};
1233 if (fb_ ==
nullptr) {
1253 this->name_ = a.name_;
1259 operator GPUFrameBuffer *()
const
1274 std::swap(a.fb_,
b.fb_);
1275 std::swap(a.name_,
b.name_);
1290 std::array<T, len> chain_;
1296 auto i_next = (i + 1) %
len;
1297 if constexpr (std::is_trivial_v<T>) {
1298 std::swap(chain_[i], chain_[i_next]);
1301 T::swap(chain_[i], chain_[i_next]);
1319 return chain_[(0 +
len - 1) %
len];
1324 return chain_[(0 + 1) %
len];
1335 return chain_[(0 +
len - 1) %
len];
1340 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)
GPUFrameBuffer * GPU_framebuffer_create(const char *name)
#define GPU_FRAMEBUFFER_FREE_SAFE(fb)
void GPU_framebuffer_default_size(GPUFrameBuffer *framebuffer, int width, int height)
void GPU_framebuffer_config_array(GPUFrameBuffer *framebuffer, const GPUAttachment *config, int config_len)
#define GPU_ATTACHMENT_NONE
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_clear_depth(GPUFrameBuffer *fb, float clear_depth)
void GPU_storagebuf_sync_to_host(GPUStorageBuf *ssbo)
GPUStorageBuf * GPU_storagebuf_create_ex(size_t size, const void *data, GPUUsageType usage, const char *name)
void GPU_storagebuf_clear_to_zero(GPUStorageBuf *ssbo)
void GPU_storagebuf_free(GPUStorageBuf *ssbo)
void GPU_storagebuf_update(GPUStorageBuf *ssbo, const void *data)
void GPU_storagebuf_read(GPUStorageBuf *ssbo, void *data)
int GPU_texture_height(const GPUTexture *texture)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
GPUTexture * GPU_texture_create_1d(const char *name, int width, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
int GPU_texture_width(const GPUTexture *texture)
void GPU_texture_clear(GPUTexture *texture, eGPUDataFormat data_format, const void *data)
bool GPU_texture_has_float_format(const GPUTexture *tex)
void * GPU_texture_read(GPUTexture *texture, eGPUDataFormat data_format, int mip_level)
bool GPU_texture_is_cube(const GPUTexture *texture)
int GPU_texture_depth(const GPUTexture *texture)
int GPU_texture_mip_count(const GPUTexture *texture)
GPUTexture * GPU_texture_create_cube_array(const char *name, int width, int layer_len, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
bool GPU_texture_has_integer_format(const GPUTexture *texture)
GPUTexture * GPU_texture_create_view(const char *name, GPUTexture *source_texture, eGPUTextureFormat view_format, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array, bool use_stencil)
bool GPU_texture_is_array(const GPUTexture *texture)
@ GPU_TEXTURE_USAGE_GENERAL
bool GPU_texture_has_stencil_format(const GPUTexture *texture)
GPUTexture * GPU_texture_create_2d_array(const char *name, int width, int height, int layer_len, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
bool GPU_texture_has_signed_format(const GPUTexture *tex)
GPUTexture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const void *data)
bool GPU_texture_has_normalized_format(const GPUTexture *tex)
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
#define GPU_TEXTURE_FREE_SAFE(texture)
GPUTexture * GPU_texture_create_cube(const char *name, int width, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
GPUTexture * GPU_texture_create_1d_array(const char *name, int width, int layer_len, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
int GPU_texture_layer_count(const GPUTexture *texture)
bool GPU_texture_has_depth_format(const GPUTexture *texture)
void GPU_texture_get_mipmap_size(GPUTexture *texture, int mip_level, int *r_size)
eGPUTextureFormat GPU_texture_format(const GPUTexture *texture)
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
void append(const T &value)
static void swap(Framebuffer &a, Framebuffer &b)
Framebuffer(const char *name)
void ensure(int2 target_size)
GPUFrameBuffer ** 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)
const T & previous() const
const T & current() const
static void swap(TextureFromPool &a, Texture &b)
bool ensure_1d_array(int, int, int, eGPUTextureFormat, eGPUTextureUsage, const float *)=delete
GPUTexture * stencil_view()=delete
GPUTexture * mip_view(int)=delete
bool ensure_cube(int, int, eGPUTextureFormat, eGPUTextureUsage, const float *)=delete
bool ensure_cube_array(int, int, int, eGPUTextureFormat, eGPUTextureUsage, const float *)=delete
void acquire(int2 extent, eGPUTextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL)
static void swap(TextureFromPool &a, TextureFromPool &b)
bool ensure_2d_array(int, int, int, int, eGPUTextureFormat, eGPUTextureUsage, const float *)=delete
static void swap(Texture &a, TextureFromPool &b)
TextureFromPool(const char *name="gpu::Texture")
GPUTexture * layer_view(int)=delete
void filter_mode(bool)=delete
bool ensure_3d(int, int, int, int, eGPUTextureFormat, eGPUTextureUsage, const float *)=delete
bool ensure_2d(int, int, int, eGPUTextureFormat, eGPUTextureUsage, float *)=delete
bool ensure_1d(int, int, eGPUTextureFormat, eGPUTextureUsage, const float *)=delete
GPUTexture * mip_view(int)=delete
GPUTexture * stencil_view()=delete
bool ensure_1d_array(int, int, int, eGPUTextureFormat, const float *)=delete
bool ensure_cube_array(int, int, int, eGPUTextureFormat, const float *)=delete
GPUTexture * layer_view(int)=delete
void filter_mode(bool)=delete
void wrap(GPUTexture *tex)
bool ensure_cube(int, int, eGPUTextureFormat, const float *)=delete
bool ensure_2d_array(int, int, int, int, eGPUTextureFormat, const float *)=delete
bool ensure_3d(int, int, int, int, eGPUTextureFormat, const float *)=delete
bool ensure_1d(int, int, eGPUTextureFormat, const float *)=delete
bool ensure_2d(int, int, int, eGPUTextureFormat, const float *)=delete
bool ensure_1d_array(eGPUTextureFormat format, int extent, int layers, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
Texture(const char *name, eGPUTextureFormat format, eGPUTextureUsage usage, int extent, const float *data=nullptr, bool cubemap=false, int mip_len=1)
Texture(const char *name, eGPUTextureFormat format, eGPUTextureUsage usage, int extent, int layers, const float *data=nullptr, bool cubemap=false, int mip_len=1)
bool ensure_mip_views(bool cube_as_array=false)
Vector< GPUTexture *, 0 > mip_views_
bool ensure_1d(eGPUTextureFormat format, int extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
static void swap(Texture &a, Texture &b)
GPUTexture * layer_range_view_
Texture(const char *name="gpu::Texture")
GPUTexture * stencil_view_
void clear(float4 values)
Vector< GPUTexture *, 0 > layer_views_
T * read(eGPUDataFormat format, int miplvl=0)
bool ensure_cube(eGPUTextureFormat format, int extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, float *data=nullptr, int mip_len=1)
Texture(const char *name, eGPUTextureFormat format, eGPUTextureUsage usage, int2 extent, const float *data=nullptr, int mip_len=1)
void filter_mode(bool do_filter)
GPUTexture ** operator&()
bool ensure_cube_array(eGPUTextureFormat format, int extent, int layers, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
bool ensure_2d_array(eGPUTextureFormat 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)
bool ensure_2d(eGPUTextureFormat format, int2 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
bool ensure_3d(eGPUTextureFormat format, int3 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
GPUTexture * layer_view(int layer)
Texture(const char *name, eGPUTextureFormat format, eGPUTextureUsage usage, int3 extent, const float *data=nullptr, int mip_len=1)
GPUTexture * stencil_view(bool cube_as_array=false)
GPUTexture * gpu_texture()
Texture & operator=(Texture &&a)
GPUTexture * mip_view(int miplvl)
int3 size(int miplvl=0) const
GPUTexture * layer_range_view(int layer_start, int layer_len, bool cube_as_array=false)
Texture(Texture &&other)=default
Texture(const char *name, eGPUTextureFormat format, eGPUTextureUsage usage, int2 extent, int layers, const float *data=nullptr, 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)
GPUStorageBuf ** operator&()
void async_flush_to_host()
local_group_size(16, 16) .push_constant(Type b
GPUTexture * DRW_texture_pool_texture_acquire(DRWTexturePool *pool, int width, int height, eGPUTextureFormat format, eGPUTextureUsage usage)
void DRW_texture_pool_texture_release(DRWTexturePool *pool, GPUTexture *tmp_tex)
void DRW_texture_pool_take_texture_ownership(DRWTexturePool *pool, GPUTexture *tex)
void DRW_texture_pool_give_texture_ownership(DRWTexturePool *pool, GPUTexture *tex)
RAYTRACE_GROUP_SIZE additional_info("eevee_shared", "eevee_gbuffer_data", "eevee_global_ubo", "eevee_sampling_data", "eevee_utility_texture", "eevee_hiz_data", "draw_view") .specialization_constant(Type RAYTRACE_GROUP_SIZE in_sh_0_tx in_sh_2_tx screen_normal_tx GPU_RGBA8
void * MEM_mallocN_aligned(size_t len, size_t alignment, const char *str)
void MEM_freeN(void *vmemh)
static GPUTexture * as_texture(Image *img)
static Image * as_image(GPUTexture *tex)
BLI_STATIC_ASSERT(MBC_BATCH_LEN< 32, "Number of batches exceeded the limit of bit fields")
VecBase< int32_t, 4 > int4
VecBase< uint32_t, 4 > uint4
VecBase< float, 4 > float4
VecBase< int32_t, 3 > int3
DRWTexturePool * texture_pool