Blender  V3.3
DRW_gpu_wrapper.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2022 Blender Foundation. */
3 
4 #pragma once
5 
56 #include "DRW_render.h"
57 
58 #include "MEM_guardedalloc.h"
59 
60 #include "draw_texture_pool.h"
61 
62 #include "BLI_math_vec_types.hh"
63 #include "BLI_span.hh"
64 #include "BLI_utildefines.h"
65 #include "BLI_utility_mixins.hh"
66 #include "BLI_vector.hh"
67 
68 #include "GPU_framebuffer.h"
69 #include "GPU_storage_buffer.h"
70 #include "GPU_texture.h"
71 #include "GPU_uniform_buffer.h"
72 
73 namespace blender::draw {
74 
75 /* -------------------------------------------------------------------- */
79 namespace detail {
80 
81 template<
83  typename T,
85  int64_t len,
87  bool device_only>
88 class DataBuffer {
89  protected:
90  T *data_ = nullptr;
92 
93  BLI_STATIC_ASSERT(((sizeof(T) * len) % 16) == 0,
94  "Buffer size need to be aligned to size of float4.");
95 
96  public:
101  const T &operator[](int64_t index) const
102  {
103  BLI_STATIC_ASSERT(!device_only, "");
104  BLI_assert(index >= 0);
105  BLI_assert(index < len_);
106  return data_[index];
107  }
108 
110  {
111  BLI_STATIC_ASSERT(!device_only, "");
112  BLI_assert(index >= 0);
113  BLI_assert(index < len_);
114  return data_[index];
115  }
116 
120  const T *data() const
121  {
122  BLI_STATIC_ASSERT(!device_only, "");
123  return data_;
124  }
125  T *data()
126  {
127  BLI_STATIC_ASSERT(!device_only, "");
128  return data_;
129  }
130 
134  const T *begin() const
135  {
136  BLI_STATIC_ASSERT(!device_only, "");
137  return data_;
138  }
139  const T *end() const
140  {
141  BLI_STATIC_ASSERT(!device_only, "");
142  return data_ + len_;
143  }
144 
145  T *begin()
146  {
147  BLI_STATIC_ASSERT(!device_only, "");
148  return data_;
149  }
150  T *end()
151  {
152  BLI_STATIC_ASSERT(!device_only, "");
153  return data_ + len_;
154  }
155 
156  operator Span<T>() const
157  {
158  BLI_STATIC_ASSERT(!device_only, "");
159  return Span<T>(data_, len_);
160  }
161 };
162 
163 template<typename T, int64_t len, bool device_only>
164 class UniformCommon : public DataBuffer<T, len, false>, NonMovable, NonCopyable {
165  protected:
167 
168 #ifdef DEBUG
169  const char *name_ = typeid(T).name();
170 #else
171  const char *name_ = "UniformBuffer";
172 #endif
173 
174  public:
176  {
177  ubo_ = GPU_uniformbuf_create_ex(sizeof(T) * len, nullptr, name_);
178  }
179 
181  {
183  }
184 
185  void push_update(void)
186  {
187  GPU_uniformbuf_update(ubo_, this->data_);
188  }
189 
190  /* To be able to use it with DRW_shgroup_*_ref(). */
191  operator GPUUniformBuf *() const
192  {
193  return ubo_;
194  }
195 
196  /* To be able to use it with DRW_shgroup_*_ref(). */
198  {
199  return &ubo_;
200  }
201 };
202 
203 template<typename T, int64_t len, bool device_only>
204 class StorageCommon : public DataBuffer<T, len, false>, NonMovable, NonCopyable {
205  protected:
207 
208 #ifdef DEBUG
209  const char *name_ = typeid(T).name();
210 #else
211  const char *name_ = "StorageBuffer";
212 #endif
213 
214  public:
215  StorageCommon(const char *name = nullptr)
216  {
217  if (name) {
218  name_ = name;
219  }
220  this->len_ = len;
221  constexpr GPUUsageType usage = device_only ? GPU_USAGE_DEVICE_ONLY : GPU_USAGE_DYNAMIC;
222  ssbo_ = GPU_storagebuf_create_ex(sizeof(T) * this->len_, nullptr, usage, this->name_);
223  }
224 
226  {
228  }
229 
230  void push_update(void)
231  {
232  BLI_assert(device_only == false);
233  GPU_storagebuf_update(ssbo_, this->data_);
234  }
235 
236  operator GPUStorageBuf *() const
237  {
238  return ssbo_;
239  }
240  /* To be able to use it with DRW_shgroup_*_ref(). */
242  {
243  return &ssbo_;
244  }
245 };
246 
247 } // namespace detail
248 
251 /* -------------------------------------------------------------------- */
255 template<
257  typename T,
259  int64_t len
261  /* TODO(@fclem): Currently unsupported. */
262  /* bool device_only = false */>
263 class UniformArrayBuffer : public detail::UniformCommon<T, len, false> {
264  public:
266  {
267  /* TODO(@fclem): We should map memory instead. */
268  this->data_ = (T *)MEM_mallocN_aligned(len * sizeof(T), 16, this->name_);
269  }
271  {
272  MEM_freeN(this->data_);
273  }
274 };
275 
276 template<
278  typename T
280  /* TODO(@fclem): Currently unsupported. */
281  /* bool device_only = false */>
282 class UniformBuffer : public T, public detail::UniformCommon<T, 1, false> {
283  public:
285  {
286  /* TODO(@fclem): How could we map this? */
287  this->data_ = static_cast<T *>(this);
288  }
289 
290  UniformBuffer<T> &operator=(const T &other)
291  {
292  *static_cast<T *>(this) = other;
293  return *this;
294  }
295 };
296 
299 /* -------------------------------------------------------------------- */
303 template<
305  typename T,
307  int64_t len,
309  bool device_only = false>
310 class StorageArrayBuffer : public detail::StorageCommon<T, len, device_only> {
311  public:
312  StorageArrayBuffer(const char *name = nullptr) : detail::StorageCommon<T, len, device_only>(name)
313  {
314  /* TODO(@fclem): We should map memory instead. */
315  this->data_ = (T *)MEM_mallocN_aligned(len * sizeof(T), 16, this->name_);
316  }
318  {
319  MEM_freeN(this->data_);
320  }
321 
322  void resize(int64_t new_size)
323  {
324  BLI_assert(new_size > 0);
325  if (new_size != this->len_) {
326  /* Manual realloc since MEM_reallocN_aligned does not exists. */
327  T *new_data_ = (T *)MEM_mallocN_aligned(new_size * sizeof(T), 16, this->name_);
328  memcpy(new_data_, this->data_, min_uu(this->len_, new_size) * sizeof(T));
329  MEM_freeN(this->data_);
330  this->data_ = new_data_;
331  GPU_storagebuf_free(this->ssbo_);
332 
333  this->len_ = new_size;
334  constexpr GPUUsageType usage = device_only ? GPU_USAGE_DEVICE_ONLY : GPU_USAGE_DYNAMIC;
335  this->ssbo_ = GPU_storagebuf_create_ex(sizeof(T) * this->len_, nullptr, usage, this->name_);
336  }
337  }
338 
339  /* Resize on access. */
341  {
342  BLI_assert(index >= 0);
343  if (index >= this->len_) {
344  size_t size = power_of_2_max_u(index + 1);
345  this->resize(size);
346  }
347  return this->data_[index];
348  }
349 };
350 
351 template<
353  typename T,
355  bool device_only = false>
356 class StorageBuffer : public T, public detail::StorageCommon<T, 1, device_only> {
357  public:
358  StorageBuffer(const char *name = nullptr) : detail::StorageCommon<T, 1, device_only>(name)
359  {
360  /* TODO(@fclem): How could we map this? */
361  this->data_ = static_cast<T *>(this);
362  }
363 
364  StorageBuffer<T> &operator=(const T &other)
365  {
366  *static_cast<T *>(this) = other;
367  return *this;
368  }
369 };
370 
373 /* -------------------------------------------------------------------- */
378  protected:
379  GPUTexture *tx_ = nullptr;
383  const char *name_;
384 
385  public:
386  Texture(const char *name = "gpu::Texture") : name_(name)
387  {
388  }
389 
390  Texture(const char *name,
392  int extent,
393  float *data = nullptr,
394  bool cubemap = false,
395  int mip_len = 1)
396  : name_(name)
397  {
398  tx_ = create(extent, 0, 0, mip_len, format, data, false, cubemap);
399  }
400 
401  Texture(const char *name,
403  int extent,
404  int layers,
405  float *data = nullptr,
406  bool cubemap = false,
407  int mip_len = 1)
408  : name_(name)
409  {
410  tx_ = create(extent, layers, 0, mip_len, format, data, true, cubemap);
411  }
412 
413  Texture(const char *name,
415  int2 extent,
416  float *data = nullptr,
417  int mip_len = 1)
418  : name_(name)
419  {
420  tx_ = create(UNPACK2(extent), 0, mip_len, format, data, false, false);
421  }
422 
423  Texture(const char *name,
425  int2 extent,
426  int layers,
427  float *data = nullptr,
428  int mip_len = 1)
429  : name_(name)
430  {
431  tx_ = create(UNPACK2(extent), layers, mip_len, format, data, true, false);
432  }
433 
434  Texture(const char *name,
436  int3 extent,
437  float *data = nullptr,
438  int mip_len = 1)
439  : name_(name)
440  {
441  tx_ = create(UNPACK3(extent), mip_len, format, data, false, false);
442  }
443 
445  {
446  free();
447  }
448 
449  /* To be able to use it with DRW_shgroup_uniform_texture(). */
450  operator GPUTexture *() const
451  {
452  BLI_assert(tx_ != nullptr);
453  return tx_;
454  }
455 
456  /* To be able to use it with DRW_shgroup_uniform_texture_ref(). */
458  {
459  return &tx_;
460  }
461 
463  {
464  if (*this != a) {
465  this->tx_ = a.tx_;
466  this->name_ = a.name_;
467  a.tx_ = nullptr;
468  }
469  return *this;
470  }
471 
476  bool ensure_1d(eGPUTextureFormat format, int extent, float *data = nullptr, int mip_len = 1)
477  {
478  return ensure_impl(extent, 0, 0, mip_len, format, data, false, false);
479  }
480 
486  eGPUTextureFormat format, int extent, int layers, float *data = nullptr, int mip_len = 1)
487  {
488  return ensure_impl(extent, layers, 0, mip_len, format, data, true, false);
489  }
490 
495  bool ensure_2d(eGPUTextureFormat format, int2 extent, float *data = nullptr, int mip_len = 1)
496  {
497  return ensure_impl(UNPACK2(extent), 0, mip_len, format, data, false, false);
498  }
499 
505  eGPUTextureFormat format, int2 extent, int layers, float *data = nullptr, int mip_len = 1)
506  {
507  return ensure_impl(UNPACK2(extent), layers, mip_len, format, data, true, false);
508  }
509 
514  bool ensure_3d(eGPUTextureFormat format, int3 extent, float *data = nullptr, int mip_len = 1)
515  {
516  return ensure_impl(UNPACK3(extent), mip_len, format, data, false, false);
517  }
518 
523  bool ensure_cube(eGPUTextureFormat format, int extent, float *data = nullptr, int mip_len = 1)
524  {
525  return ensure_impl(extent, extent, 0, mip_len, format, data, false, true);
526  }
527 
533  eGPUTextureFormat format, int extent, int layers, float *data = nullptr, int mip_len = 1)
534  {
535  return ensure_impl(extent, extent, layers, mip_len, format, data, false, true);
536  }
537 
542  bool ensure_mip_views(bool cube_as_array = false)
543  {
544  int mip_len = GPU_texture_mip_count(tx_);
545  if (mip_views_.size() != mip_len) {
546  for (GPUTexture *&view : mip_views_) {
548  }
550  for (auto i : IndexRange(mip_len)) {
552  GPU_texture_create_view(name_, tx_, format, i, 1, 0, 9999, cube_as_array));
553  }
554  return true;
555  }
556  return false;
557  }
558 
559  GPUTexture *mip_view(int miplvl)
560  {
561  return mip_views_[miplvl];
562  }
563 
569  bool ensure_layer_views(bool cube_as_array = false)
570  {
571  int layer_len = GPU_texture_layer_count(tx_);
572  if (layer_views_.size() != layer_len) {
573  for (GPUTexture *&view : layer_views_) {
575  }
577  for (auto i : IndexRange(layer_len)) {
579  GPU_texture_create_view(name_, tx_, format, 0, 9999, i, 1, cube_as_array));
580  }
581  return true;
582  }
583  return false;
584  }
585 
586  GPUTexture *layer_view(int layer)
587  {
588  return layer_views_[layer];
589  }
590 
591  GPUTexture *stencil_view(bool cube_as_array = false)
592  {
593  if (stencil_view_ == nullptr) {
595  stencil_view_ = GPU_texture_create_view(name_, tx_, format, 0, 9999, 0, 9999, cube_as_array);
597  }
598  return stencil_view_;
599  }
600 
604  bool is_valid(void) const
605  {
606  return tx_ != nullptr;
607  }
608 
609  int width(void) const
610  {
611  return GPU_texture_width(tx_);
612  }
613 
614  int height(void) const
615  {
616  return GPU_texture_height(tx_);
617  }
618 
619  bool depth(void) const
620  {
621  return GPU_texture_depth(tx_);
622  }
623 
624  bool is_stencil(void) const
625  {
626  return GPU_texture_stencil(tx_);
627  }
628 
629  bool is_integer(void) const
630  {
631  return GPU_texture_integer(tx_);
632  }
633 
634  bool is_cube(void) const
635  {
636  return GPU_texture_cube(tx_);
637  }
638 
639  bool is_array(void) const
640  {
641  return GPU_texture_array(tx_);
642  }
643 
644  int3 size(int miplvl = 0) const
645  {
646  int3 size(0);
648  return size;
649  }
650 
654  void clear(float4 values)
655  {
656  GPU_texture_clear(tx_, GPU_DATA_FLOAT, &values[0]);
657  }
658 
662  void clear(uint4 values)
663  {
664  GPU_texture_clear(tx_, GPU_DATA_UINT, &values[0]);
665  }
666 
670  void clear(int4 values)
671  {
672  GPU_texture_clear(tx_, GPU_DATA_INT, &values[0]);
673  }
674 
679  template<typename T> T *read(eGPUDataFormat format, int miplvl = 0)
680  {
681  return reinterpret_cast<T *>(GPU_texture_read(tx_, format, miplvl));
682  }
683 
684  void filter_mode(bool do_filter)
685  {
686  GPU_texture_filter_mode(tx_, do_filter);
687  }
688 
692  void free()
693  {
695  for (GPUTexture *&view : mip_views_) {
697  }
698  for (GPUTexture *&view : layer_views_) {
700  }
702  mip_views_.clear();
703  }
704 
708  static void swap(Texture &a, Texture &b)
709  {
710  SWAP(GPUTexture *, a.tx_, b.tx_);
711  SWAP(const char *, a.name_, b.name_);
712  }
713 
714  private:
715  bool ensure_impl(int w,
716  int h = 0,
717  int d = 0,
718  int mip_len = 1,
720  float *data = nullptr,
721  bool layered = false,
722  bool cubemap = false)
723 
724  {
725  /* TODO(@fclem): In the future, we need to check if mip_count did not change.
726  * For now it's ok as we always define all MIP level. */
727  if (tx_) {
728  int3 size = this->size();
729  if (size != int3(w, h, d) || GPU_texture_format(tx_) != format ||
730  GPU_texture_cube(tx_) != cubemap || GPU_texture_array(tx_) != layered) {
732  }
733  }
734  if (tx_ == nullptr) {
735  tx_ = create(w, h, d, mip_len, format, data, layered, cubemap);
736  return true;
737  }
738  return false;
739  }
740 
741  GPUTexture *create(int w,
742  int h,
743  int d,
744  int mip_len,
746  float *data,
747  bool layered,
748  bool cubemap)
749  {
750  if (h == 0) {
751  return GPU_texture_create_1d(name_, w, mip_len, format, data);
752  }
753  else if (cubemap) {
754  if (layered) {
755  return GPU_texture_create_cube_array(name_, w, d, mip_len, format, data);
756  }
757  else {
758  return GPU_texture_create_cube(name_, w, mip_len, format, data);
759  }
760  }
761  else if (d == 0) {
762  if (layered) {
763  return GPU_texture_create_1d_array(name_, w, h, mip_len, format, data);
764  }
765  else {
766  return GPU_texture_create_2d(name_, w, h, mip_len, format, data);
767  }
768  }
769  else {
770  if (layered) {
771  return GPU_texture_create_2d_array(name_, w, h, d, mip_len, format, data);
772  }
773  else {
774  return GPU_texture_create_3d(name_, w, h, d, mip_len, format, GPU_DATA_FLOAT, data);
775  }
776  }
777  }
778 };
779 
781  private:
782  GPUTexture *tx_tmp_saved_ = nullptr;
783 
784  public:
785  TextureFromPool(const char *name = "gpu::Texture") : Texture(name){};
786 
787  /* Always use `release()` after rendering and `sync()` in sync phase. */
788  void acquire(int2 extent, eGPUTextureFormat format, void *owner_)
789  {
790  BLI_assert(this->tx_ == nullptr);
791  if (this->tx_ != nullptr) {
792  return;
793  }
794  if (tx_tmp_saved_ != nullptr) {
795  if (GPU_texture_width(tx_tmp_saved_) != extent.x ||
796  GPU_texture_height(tx_tmp_saved_) != extent.y ||
797  GPU_texture_format(tx_tmp_saved_) != format) {
798  this->tx_tmp_saved_ = nullptr;
799  }
800  else {
801  this->tx_ = tx_tmp_saved_;
802  return;
803  }
804  }
805  DrawEngineType *owner = (DrawEngineType *)owner_;
806  this->tx_ = DRW_texture_pool_query_2d(UNPACK2(extent), format, owner);
807  }
808 
809  void release(void)
810  {
811  /* Allows multiple release. */
812  if (this->tx_ != nullptr) {
813  tx_tmp_saved_ = this->tx_;
814  this->tx_ = nullptr;
815  }
816  }
817 
822  void sync(void)
823  {
824  tx_tmp_saved_ = nullptr;
825  }
826 
828  bool ensure_1d(int, int, eGPUTextureFormat, float *) = delete;
829  bool ensure_1d_array(int, int, int, eGPUTextureFormat, float *) = delete;
830  bool ensure_2d(int, int, int, eGPUTextureFormat, float *) = delete;
831  bool ensure_2d_array(int, int, int, int, eGPUTextureFormat, float *) = delete;
832  bool ensure_3d(int, int, int, int, eGPUTextureFormat, float *) = delete;
833  bool ensure_cube(int, int, eGPUTextureFormat, float *) = delete;
834  bool ensure_cube_array(int, int, int, eGPUTextureFormat, float *) = delete;
835  void filter_mode(bool) = delete;
836  void free() = delete;
837  GPUTexture *mip_view(int) = delete;
838  GPUTexture *layer_view(int) = delete;
840 };
841 
844 /* -------------------------------------------------------------------- */
849  private:
850  GPUFrameBuffer *fb_ = nullptr;
851  const char *name_;
852 
853  public:
854  Framebuffer() : name_(""){};
855  Framebuffer(const char *name) : name_(name){};
856 
858  {
859  GPU_FRAMEBUFFER_FREE_SAFE(fb_);
860  }
861 
862  void ensure(GPUAttachment depth = GPU_ATTACHMENT_NONE,
863  GPUAttachment color1 = GPU_ATTACHMENT_NONE,
864  GPUAttachment color2 = GPU_ATTACHMENT_NONE,
865  GPUAttachment color3 = GPU_ATTACHMENT_NONE,
866  GPUAttachment color4 = GPU_ATTACHMENT_NONE,
867  GPUAttachment color5 = GPU_ATTACHMENT_NONE,
868  GPUAttachment color6 = GPU_ATTACHMENT_NONE,
869  GPUAttachment color7 = GPU_ATTACHMENT_NONE,
870  GPUAttachment color8 = GPU_ATTACHMENT_NONE)
871  {
872  GPU_framebuffer_ensure_config(
873  &fb_, {depth, color1, color2, color3, color4, color5, color6, color7, color8});
874  }
875 
877  {
878  if (*this != a) {
879  this->fb_ = a.fb_;
880  this->name_ = a.name_;
881  a.fb_ = nullptr;
882  }
883  return *this;
884  }
885 
886  operator GPUFrameBuffer *() const
887  {
888  return fb_;
889  }
890 
894  static void swap(Framebuffer &a, Framebuffer &b)
895  {
896  SWAP(GPUFrameBuffer *, a.fb_, b.fb_);
897  SWAP(const char *, a.name_, b.name_);
898  }
899 };
900 
903 /* -------------------------------------------------------------------- */
909 template<typename T, int64_t len> class SwapChain {
910  private:
911  std::array<T, len> chain_;
912  int64_t index_ = 0;
913 
914  public:
915  void swap()
916  {
917  index_ = (index_ + 1) % len;
918  }
919 
921  {
922  return chain_[index_];
923  }
924 
926  {
927  /* Avoid modulo operation with negative numbers. */
928  return chain_[(index_ + len - 1) % len];
929  }
930 
931  T &next()
932  {
933  return chain_[(index_ + 1) % len];
934  }
935 
936  const T &current() const
937  {
938  return chain_[index_];
939  }
940 
941  const T &previous() const
942  {
943  /* Avoid modulo operation with negative numbers. */
944  return chain_[(index_ + len - 1) % len];
945  }
946 
947  const T &next() const
948  {
949  return chain_[(index_ + 1) % len];
950  }
951 };
952 
955 } // namespace blender::draw
#define BLI_assert(a)
Definition: BLI_assert.h:46
MINLINE uint min_uu(uint a, uint b)
MINLINE unsigned int power_of_2_max_u(unsigned int x)
#define UNPACK2(a)
#define SWAP(type, a, b)
#define UNPACK3(a)
static AppView * view
struct GPUFrameBuffer GPUFrameBuffer
void GPU_storagebuf_free(GPUStorageBuf *ssbo)
void GPU_storagebuf_update(GPUStorageBuf *ssbo, const void *data)
GPUStorageBuf * GPU_storagebuf_create_ex(size_t size, const void *data, GPUUsageType usage, const char *name)
struct GPUStorageBuf GPUStorageBuf
GPUTexture * GPU_texture_create_2d_array(const char *name, int w, int h, int d, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:297
bool GPU_texture_cube(const GPUTexture *tex)
Definition: gpu_texture.cc:659
GPUTexture * GPU_texture_create_1d_array(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:284
int GPU_texture_height(const GPUTexture *tex)
Definition: gpu_texture.cc:607
GPUTexture * GPU_texture_create_1d(const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:278
void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat data_format, const void *data)
Definition: gpu_texture.cc:438
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
int GPU_texture_width(const GPUTexture *tex)
Definition: gpu_texture.cc:602
void * GPU_texture_read(GPUTexture *tex, eGPUDataFormat data_format, int miplvl)
Definition: gpu_texture.cc:432
eGPUDataFormat
Definition: GPU_texture.h:170
@ GPU_DATA_INT
Definition: GPU_texture.h:172
@ GPU_DATA_UINT
Definition: GPU_texture.h:173
@ GPU_DATA_FLOAT
Definition: GPU_texture.h:171
int GPU_texture_mip_count(const GPUTexture *tex)
Definition: gpu_texture.cc:617
bool GPU_texture_integer(const GPUTexture *tex)
Definition: gpu_texture.cc:654
bool GPU_texture_array(const GPUTexture *tex)
Definition: gpu_texture.cc:664
void GPU_texture_get_mipmap_size(GPUTexture *tex, int lvl, int *size)
Definition: gpu_texture.cc:688
GPUTexture * GPU_texture_create_view(const char *name, const GPUTexture *src, eGPUTextureFormat format, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array)
Definition: gpu_texture.cc:388
void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter)
Definition: gpu_texture.cc:518
int GPU_texture_layer_count(const GPUTexture *tex)
Definition: gpu_texture.cc:612
void GPU_texture_stencil_texture_mode_set(GPUTexture *tex, bool use_stencil)
Definition: gpu_texture.cc:558
GPUTexture * GPU_texture_create_2d(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:291
#define GPU_TEXTURE_FREE_SAFE(texture)
Definition: GPU_texture.h:40
eGPUTextureFormat
Definition: GPU_texture.h:83
@ GPU_RGBA8
Definition: GPU_texture.h:87
bool GPU_texture_stencil(const GPUTexture *tex)
Definition: gpu_texture.cc:649
GPUTexture * GPU_texture_create_3d(const char *name, int w, int h, int d, int mip_len, eGPUTextureFormat texture_format, eGPUDataFormat data_format, const void *data)
Definition: gpu_texture.cc:309
eGPUTextureFormat GPU_texture_format(const GPUTexture *tex)
Definition: gpu_texture.cc:639
bool GPU_texture_depth(const GPUTexture *tex)
Definition: gpu_texture.cc:644
GPUTexture * GPU_texture_create_cube(const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:322
GPUTexture * GPU_texture_create_cube_array(const char *name, int w, int d, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:329
struct GPUUniformBuf GPUUniformBuf
GPUUniformBuf * GPU_uniformbuf_create_ex(size_t size, const void *data, const char *name)
void GPU_uniformbuf_update(GPUUniformBuf *ubo, const void *data)
void GPU_uniformbuf_free(GPUUniformBuf *ubo)
GPUUsageType
@ GPU_USAGE_DYNAMIC
@ GPU_USAGE_DEVICE_ONLY
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
int64_t size() const
Definition: BLI_vector.hh:694
void append(const T &value)
Definition: BLI_vector.hh:433
static void swap(Framebuffer &a, Framebuffer &b)
Framebuffer(const char *name)
Framebuffer & operator=(Framebuffer &&a)
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)
StorageBuffer< T > & operator=(const T &other)
StorageBuffer(const char *name=nullptr)
const T & previous() const
const T & current() const
GPUTexture * layer_view(int)=delete
GPUTexture * mip_view(int)=delete
bool ensure_1d_array(int, int, int, eGPUTextureFormat, float *)=delete
bool ensure_cube(int, int, eGPUTextureFormat, float *)=delete
void acquire(int2 extent, eGPUTextureFormat format, void *owner_)
TextureFromPool(const char *name="gpu::Texture")
void filter_mode(bool)=delete
bool ensure_2d(int, int, int, eGPUTextureFormat, float *)=delete
bool ensure_2d_array(int, int, int, int, eGPUTextureFormat, float *)=delete
bool ensure_3d(int, int, int, int, eGPUTextureFormat, float *)=delete
bool ensure_1d(int, int, eGPUTextureFormat, float *)=delete
bool ensure_cube_array(int, int, int, eGPUTextureFormat, float *)=delete
GPUTexture * stencil_view()=delete
bool is_valid(void) const
bool ensure_cube_array(eGPUTextureFormat format, int extent, int layers, float *data=nullptr, int mip_len=1)
bool ensure_mip_views(bool cube_as_array=false)
bool ensure_1d(eGPUTextureFormat format, int extent, float *data=nullptr, int mip_len=1)
Texture(const char *name, eGPUTextureFormat format, int extent, float *data=nullptr, bool cubemap=false, int mip_len=1)
Vector< GPUTexture *, 0 > mip_views_
Texture(const char *name, eGPUTextureFormat format, int3 extent, float *data=nullptr, int mip_len=1)
bool is_integer(void) const
static void swap(Texture &a, Texture &b)
GPUTexture * layer_view(int layer)
bool ensure_2d_array(eGPUTextureFormat format, int2 extent, int layers, float *data=nullptr, int mip_len=1)
Texture(const char *name, eGPUTextureFormat format, int extent, int layers, float *data=nullptr, bool cubemap=false, int mip_len=1)
Texture(const char *name="gpu::Texture")
Texture(const char *name, eGPUTextureFormat format, int2 extent, int layers, float *data=nullptr, int mip_len=1)
void clear(float4 values)
Vector< GPUTexture *, 0 > layer_views_
GPUTexture * stencil_view(bool cube_as_array=false)
void clear(uint4 values)
GPUTexture * mip_view(int miplvl)
void clear(int4 values)
void filter_mode(bool do_filter)
bool is_cube(void) const
bool is_stencil(void) const
Texture & operator=(Texture &&a)
T * read(eGPUDataFormat format, int miplvl=0)
bool ensure_layer_views(bool cube_as_array=false)
bool is_array(void) const
bool ensure_3d(eGPUTextureFormat format, int3 extent, float *data=nullptr, int mip_len=1)
Texture(const char *name, eGPUTextureFormat format, int2 extent, float *data=nullptr, int mip_len=1)
int3 size(int miplvl=0) const
bool ensure_1d_array(eGPUTextureFormat format, int extent, int layers, float *data=nullptr, int mip_len=1)
bool depth(void) const
GPUTexture ** operator&()
bool ensure_cube(eGPUTextureFormat format, int extent, float *data=nullptr, int mip_len=1)
bool ensure_2d(eGPUTextureFormat format, int2 extent, float *data=nullptr, int mip_len=1)
UniformBuffer< T > & operator=(const T &other)
const T & operator[](int64_t index) const
BLI_STATIC_ASSERT(((sizeof(T) *len) % 16)==0, "Buffer size need to be aligned to size of float4.")
StorageCommon(const char *name=nullptr)
int len
Definition: draw_manager.c:108
GPUTexture * DRW_texture_pool_query_2d(int w, int h, eGPUTextureFormat format, DrawEngineType *engine_type)
format
Definition: logImageCore.h:38
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN_aligned)(size_t len, size_t alignment, const char *str)
Definition: mallocn.c:35
#define T
static unsigned a[3]
Definition: RandGen.cpp:78
vec_base< int32_t, 3 > int3
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
__int64 int64_t
Definition: stdint.h:89