Blender V4.3
gpu_texture_private.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11#include "BLI_assert.h"
12
13#include "GPU_vertex_buffer.hh"
14
16
17namespace blender {
18namespace gpu {
19
21 /* The format has a depth component and can be used as depth attachment. */
22 GPU_FORMAT_DEPTH = (1 << 0),
23 /* The format has a stencil component and can be used as stencil attachment. */
25 /* The format represent non-normalized integers data, either signed or unsigned. */
27 /* The format is using normalized integers, either signed or unsigned. */
29 /* The format represent floating point data, either signed or unsigned. */
30 GPU_FORMAT_FLOAT = (1 << 4),
31 /* The format is using block compression. */
33 /* The format is using sRGB encoded storage. */
34 GPU_FORMAT_SRGB = (1 << 6),
35 /* The format can store negative values. */
37
39};
40
42
55
57
58/* Format types for samplers within the shader.
59 * This covers the sampler format type permutations within GLSL/MSL. */
64 /* Special case for depth, as these require differing dummy formats. */
67};
68
70
71#ifndef NDEBUG
72# define DEBUG_NAME_LEN 64
73#else
74# define DEBUG_NAME_LEN 8
75#endif
76
77/* Maximum number of FBOs a texture can be attached to. */
78#define GPU_TEX_MAX_FBO_ATTACHED 32
79
84class Texture {
85 public:
89 int refcount = 1;
91 int src_w = 0, src_h = 0;
92#ifndef GPU_NO_USE_PY_REFERENCES
97 void **py_ref = nullptr;
98#endif
99
100 protected:
101 /* ---- Texture format (immutable after init). ---- */
103 int w_, h_, d_;
112
114 /* TODO(fclem): Should become immutable and the need for mipmaps should be specified upfront. */
115 int mipmaps_ = -1;
117 int mip_min_ = 0, mip_max_ = 0;
118
121
125
126 public:
127 Texture(const char *name);
128 virtual ~Texture();
129
130 /* Return true on success. */
131 bool init_1D(int w, int layers, int mip_len, eGPUTextureFormat format);
132 bool init_2D(int w, int h, int layers, int mip_len, eGPUTextureFormat format);
133 bool init_3D(int w, int h, int d, int mip_len, eGPUTextureFormat format);
134 bool init_cubemap(int w, int layers, int mip_len, eGPUTextureFormat format);
136 bool init_view(GPUTexture *src,
138 eGPUTextureType type,
139 int mip_start,
140 int mip_len,
141 int layer_start,
142 int layer_len,
143 bool cube_as_array,
144 bool use_stencil);
145
146 virtual void generate_mipmap() = 0;
147 virtual void copy_to(Texture *tex) = 0;
148 virtual void clear(eGPUDataFormat format, const void *data) = 0;
149 virtual void swizzle_set(const char swizzle_mask[4]) = 0;
150 virtual void mip_range_set(int min, int max) = 0;
151 virtual void *read(int mip, eGPUDataFormat format) = 0;
152
155 void update(eGPUDataFormat format, const void *data);
156
157 void usage_set(eGPUTextureUsage usage_flags);
158
159 virtual void update_sub(
160 int mip, int offset[3], int extent[3], eGPUDataFormat format, const void *data) = 0;
161 virtual void update_sub(int offset[3],
162 int extent[3],
164 GPUPixelBuffer *pixbuf) = 0;
165
166 /* TODO(fclem): Legacy. Should be removed at some point. */
167 virtual uint gl_bindcode_get() const = 0;
168 int width_get() const
169 {
170 return w_;
171 }
172 int height_get() const
173 {
174 return h_;
175 }
176 int depth_get() const
177 {
178 return d_;
179 }
181 {
183 }
184
185 void mip_size_get(int mip, int r_size[3]) const
186 {
187 /* TODO: assert if lvl is below the limit of 1px in each dimension. */
188 int div = 1 << mip;
189 r_size[0] = max_ii(1, w_ / div);
190
192 r_size[1] = h_;
193 }
194 else if (h_ > 0) {
195 r_size[1] = max_ii(1, h_ / div);
196 }
197
199 r_size[2] = d_;
200 }
201 else if (d_ > 0) {
202 r_size[2] = max_ii(1, d_ / div);
203 }
204 }
205
206 int mip_width_get(int mip) const
207 {
208 return max_ii(1, w_ / (1 << mip));
209 }
210 int mip_height_get(int mip) const
211 {
212 return (type_ == GPU_TEXTURE_1D_ARRAY) ? h_ : max_ii(1, h_ / (1 << mip));
213 }
214 int mip_depth_get(int mip) const
215 {
216 return (type_ & (GPU_TEXTURE_ARRAY | GPU_TEXTURE_CUBE)) ? d_ : max_ii(1, d_ / (1 << mip));
217 }
218
219 /* Return number of dimension taking the array type into account. */
221 {
222 const int array = (type_ & GPU_TEXTURE_ARRAY) ? 1 : 0;
223 switch (type_ & ~GPU_TEXTURE_ARRAY) {
225 return 1;
226 case GPU_TEXTURE_1D:
227 return 1 + array;
228 case GPU_TEXTURE_2D:
229 return 2 + array;
230 case GPU_TEXTURE_CUBE:
231 case GPU_TEXTURE_3D:
232 default:
233 return 3;
234 }
235 }
236 /* Return number of array layer (or face layer) for texture array or 1 for the others. */
237 int layer_count() const
238 {
239 switch (type_) {
241 return h_;
244 return d_;
245 default:
246 return 1;
247 }
248 }
249
250 int mip_count() const
251 {
252 return mipmaps_;
253 }
254
256 {
257 return format_;
258 }
260 {
261 return format_flag_;
262 }
264 {
265 return type_;
266 }
268 {
269 switch (format_) {
273 BLI_assert(slot == 0);
277 BLI_assert(slot == 0);
279 default:
280 /* Valid color attachment formats. */
281 return GPU_FB_COLOR_ATTACHMENT0 + slot;
282
283 case GPU_RGB16F:
284 case GPU_RGBA16_SNORM:
285 case GPU_RGBA8_SNORM:
286 case GPU_RGB32F:
287 case GPU_RGB32I:
288 case GPU_RGB32UI:
289 case GPU_RGB16_SNORM:
290 case GPU_RGB16I:
291 case GPU_RGB16UI:
292 case GPU_RGB16:
293 case GPU_RGB8_SNORM:
294 case GPU_RGB8:
295 case GPU_RGB8I:
296 case GPU_RGB8UI:
297 case GPU_RG16_SNORM:
298 case GPU_RG8_SNORM:
299 case GPU_R16_SNORM:
300 case GPU_R8_SNORM:
304 case GPU_RGBA8_DXT1:
305 case GPU_RGBA8_DXT3:
306 case GPU_RGBA8_DXT5:
307 case GPU_SRGB8:
308 case GPU_RGB9_E5:
309 BLI_assert_msg(0, "Texture cannot be attached to a framebuffer because of its type");
311 }
312 }
313
314 protected:
315 virtual bool init_internal() = 0;
316 virtual bool init_internal(VertBuf *vbo) = 0;
317 virtual bool init_internal(GPUTexture *src,
318 int mip_offset,
319 int layer_offset,
320 bool use_stencil) = 0;
321};
322
323/* Syntactic sugar. */
324static inline GPUTexture *wrap(Texture *vert)
325{
326 return reinterpret_cast<GPUTexture *>(vert);
327}
328static inline Texture *unwrap(GPUTexture *vert)
329{
330 return reinterpret_cast<Texture *>(vert);
331}
332static inline const Texture *unwrap(const GPUTexture *vert)
333{
334 return reinterpret_cast<const Texture *>(vert);
335}
336
337/* GPU pixel Buffer. */
339 protected:
340 size_t size_ = 0;
341
342 public:
343 PixelBuffer(size_t size) : size_(size){};
344 virtual ~PixelBuffer(){};
345
346 virtual void *map() = 0;
347 virtual void unmap() = 0;
349 virtual size_t get_size() = 0;
350};
351
352/* Syntactic sugar. */
353static inline GPUPixelBuffer *wrap(PixelBuffer *pixbuf)
354{
355 return reinterpret_cast<GPUPixelBuffer *>(pixbuf);
356}
357static inline PixelBuffer *unwrap(GPUPixelBuffer *pixbuf)
358{
359 return reinterpret_cast<PixelBuffer *>(pixbuf);
360}
361static inline const PixelBuffer *unwrap(const GPUPixelBuffer *pixbuf)
362{
363 return reinterpret_cast<const PixelBuffer *>(pixbuf);
364}
365
366#undef DEBUG_NAME_LEN
367
369{
370 switch (format) {
371 /* Formats texture & render-buffer */
372 case GPU_RGBA8UI:
373 case GPU_RGBA8I:
374 case GPU_RGBA8:
375 return (4 * 8) / 8;
376 case GPU_RGBA32UI:
377 case GPU_RGBA32I:
378 case GPU_RGBA32F:
379 return (4 * 32) / 8;
380 case GPU_RGBA16UI:
381 case GPU_RGBA16I:
382 case GPU_RGBA16F:
383 case GPU_RGBA16:
384 return (4 * 16) / 8;
385 case GPU_RG8UI:
386 case GPU_RG8I:
387 case GPU_RG8:
388 return (2 * 8) / 8;
389 case GPU_RG32UI:
390 case GPU_RG32I:
391 case GPU_RG32F:
392 return (2 * 32) / 8;
393 case GPU_RG16UI:
394 case GPU_RG16I:
395 case GPU_RG16F:
396 case GPU_RG16:
397 return (2 * 16) / 8;
398 case GPU_R8UI:
399 case GPU_R8I:
400 case GPU_R8:
401 return 8 / 8;
402 case GPU_R32UI:
403 case GPU_R32I:
404 case GPU_R32F:
405 return 32 / 8;
406 case GPU_R16UI:
407 case GPU_R16I:
408 case GPU_R16F:
409 case GPU_R16:
410 return 16 / 8;
411
412 /* Special formats texture & render-buffer */
413 case GPU_RGB10_A2:
414 case GPU_RGB10_A2UI:
415 return (3 * 10 + 2) / 8;
417 return (11 + 11 + 10) / 8;
419 /* 32-bit depth, 8 bits stencil, and 24 unused bits. */
420 return (32 + 8 + 24) / 8;
422 return (24 + 8) / 8;
423 case GPU_SRGB8_A8:
424 return (3 * 8 + 8) / 8;
425
426 /* Texture only formats. */
427 case GPU_RGB16F:
428 case GPU_RGB16_SNORM:
429 case GPU_RGB16I:
430 case GPU_RGB16UI:
431 case GPU_RGB16:
432 return (3 * 16) / 8;
433 case GPU_RGBA16_SNORM:
434 return (4 * 16) / 8;
435 case GPU_RGBA8_SNORM:
436 return (4 * 8) / 8;
437 case GPU_RGB32F:
438 case GPU_RGB32I:
439 case GPU_RGB32UI:
440 return (3 * 32) / 8;
441 case GPU_RGB8_SNORM:
442 case GPU_RGB8:
443 case GPU_RGB8I:
444 case GPU_RGB8UI:
445 return (3 * 8) / 8;
446 case GPU_RG16_SNORM:
447 return (2 * 16) / 8;
448 case GPU_RG8_SNORM:
449 return (2 * 8) / 8;
450 case GPU_R16_SNORM:
451 return (1 * 16) / 8;
452 case GPU_R8_SNORM:
453 return (1 * 8) / 8;
454
455 /* Special formats, texture only. */
459 case GPU_RGBA8_DXT1:
460 case GPU_RGBA8_DXT3:
461 case GPU_RGBA8_DXT5:
462 /* Incorrect but actual size is fractional. */
463 return 1;
464 case GPU_SRGB8:
465 return (3 * 8) / 8;
466 case GPU_RGB9_E5:
467 return (3 * 9 + 5) / 8;
468
469 /* Depth Formats. */
471 return 32 / 8;
473 /* Depth component 24 uses 3 bytes to store the depth value, and reserved 1 byte for
474 * alignment. */
475 return (24 + 8) / 8;
477 return 16 / 8;
478 }
480 return 0;
481}
482
483inline size_t to_block_size(eGPUTextureFormat data_type)
484{
485 switch (data_type) {
487 case GPU_RGBA8_DXT1:
488 return 8;
491 case GPU_RGBA8_DXT3:
492 case GPU_RGBA8_DXT5:
493 return 16;
494 default:
495 BLI_assert_msg(0, "Texture format is not a compressed format");
496 return 0;
497 }
498}
499
501{
502 switch (format) {
503 /* Formats texture & render-buffer */
504 case GPU_RGBA8UI:
505 return GPU_FORMAT_INTEGER;
506 case GPU_RGBA8I:
508 case GPU_RGBA8:
510 case GPU_RGBA32UI:
511 return GPU_FORMAT_INTEGER;
512 case GPU_RGBA32I:
514 case GPU_RGBA32F:
516 case GPU_RGBA16UI:
517 return GPU_FORMAT_INTEGER;
518 case GPU_RGBA16I:
520 case GPU_RGBA16F:
522 case GPU_RGBA16:
524 case GPU_RG8UI:
525 return GPU_FORMAT_INTEGER;
526 case GPU_RG8I:
528 case GPU_RG8:
530 case GPU_RG32UI:
531 return GPU_FORMAT_INTEGER;
532 case GPU_RG32I:
534 case GPU_RG32F:
536 case GPU_RG16UI:
537 return GPU_FORMAT_INTEGER;
538 case GPU_RG16I:
540 case GPU_RG16F:
542 case GPU_RG16:
544 case GPU_R8UI:
545 return GPU_FORMAT_INTEGER;
546 case GPU_R8I:
548 case GPU_R8:
550 case GPU_R32UI:
551 return GPU_FORMAT_INTEGER;
552 case GPU_R32I:
554 case GPU_R32F:
556 case GPU_R16UI:
557 return GPU_FORMAT_INTEGER;
558 case GPU_R16I:
560 case GPU_R16F:
562 case GPU_R16:
564
565 /* Special formats texture & render-buffer */
566 case GPU_RGB10_A2:
568 case GPU_RGB10_A2UI:
569 return GPU_FORMAT_INTEGER;
571 return GPU_FORMAT_FLOAT;
575 case GPU_SRGB8_A8:
577
578 /* Texture only formats. */
579 case GPU_RGB16F:
581 case GPU_RGB16_SNORM:
583 case GPU_RGB16I:
585 case GPU_RGB16UI:
586 return GPU_FORMAT_INTEGER;
587 case GPU_RGB16:
589 case GPU_RGBA16_SNORM:
590 case GPU_RGBA8_SNORM:
592 case GPU_RGB32F:
594 case GPU_RGB32I:
596 case GPU_RGB32UI:
597 return GPU_FORMAT_INTEGER;
598 case GPU_RGB8_SNORM:
600 case GPU_RGB8:
602 case GPU_RGB8I:
604 case GPU_RGB8UI:
605 return GPU_FORMAT_INTEGER;
606 case GPU_RG16_SNORM:
607 case GPU_RG8_SNORM:
608 case GPU_R16_SNORM:
609 case GPU_R8_SNORM:
611
612 /* Special formats, texture only. */
617 case GPU_RGBA8_DXT1:
618 case GPU_RGBA8_DXT3:
619 case GPU_RGBA8_DXT5:
621 case GPU_SRGB8:
623 case GPU_RGB9_E5:
624 return GPU_FORMAT_FLOAT;
625
626 /* Depth Formats. */
630 return GPU_FORMAT_DEPTH;
631 }
633 return GPU_FORMAT_FLOAT;
634}
635
637{
638 switch (format) {
639 /* Formats texture & render-buffer */
640 case GPU_RGBA8UI:
641 case GPU_RGBA8I:
642 case GPU_RGBA8:
643 case GPU_RGBA32UI:
644 case GPU_RGBA32I:
645 case GPU_RGBA32F:
646 case GPU_RGBA16UI:
647 case GPU_RGBA16I:
648 case GPU_RGBA16F:
649 case GPU_RGBA16:
650 return 4;
651 case GPU_RG8UI:
652 case GPU_RG8I:
653 case GPU_RG8:
654 case GPU_RG32UI:
655 case GPU_RG32I:
656 case GPU_RG32F:
657 case GPU_RG16UI:
658 case GPU_RG16I:
659 case GPU_RG16F:
660 case GPU_RG16:
661 return 2;
662 case GPU_R8UI:
663 case GPU_R8I:
664 case GPU_R8:
665 case GPU_R32UI:
666 case GPU_R32I:
667 case GPU_R32F:
668 case GPU_R16UI:
669 case GPU_R16I:
670 case GPU_R16F:
671 case GPU_R16:
672 return 1;
673
674 /* Special formats texture & render-buffer */
675 case GPU_RGB10_A2:
676 case GPU_RGB10_A2UI:
677 return 4;
679 return 3;
682 /* Only count depth component. */
683 return 1;
684 case GPU_SRGB8_A8:
685 return 4;
686
687 /* Texture only formats. */
688 case GPU_RGB16F:
689 case GPU_RGB16_SNORM:
690 case GPU_RGB16I:
691 case GPU_RGB16UI:
692 case GPU_RGB16:
693 return 3;
694 case GPU_RGBA16_SNORM:
695 case GPU_RGBA8_SNORM:
696 return 4;
697 case GPU_RGB32F:
698 case GPU_RGB32I:
699 case GPU_RGB32UI:
700 case GPU_RGB8_SNORM:
701 case GPU_RGB8:
702 case GPU_RGB8I:
703 case GPU_RGB8UI:
704 return 3;
705 case GPU_RG16_SNORM:
706 case GPU_RG8_SNORM:
707 return 2;
708 case GPU_R16_SNORM:
709 case GPU_R8_SNORM:
710 return 1;
711
712 /* Special formats, texture only. */
716 case GPU_RGBA8_DXT1:
717 case GPU_RGBA8_DXT3:
718 case GPU_RGBA8_DXT5:
719 return 4;
720 case GPU_SRGB8:
721 case GPU_RGB9_E5:
722 return 3;
723
724 /* Depth Formats. */
728 return 1;
729 }
731 return 1;
732}
733
734inline size_t to_bytesize(eGPUDataFormat data_format)
735{
736 switch (data_format) {
737 case GPU_DATA_UBYTE:
738 return 1;
740 return 2;
741 case GPU_DATA_FLOAT:
742 case GPU_DATA_INT:
743 case GPU_DATA_UINT:
744 return 4;
748 return 4;
749 }
751 return 0;
752}
753
754inline size_t to_bytesize(eGPUTextureFormat tex_format, eGPUDataFormat data_format)
755{
756 /* Special case for compacted types.
757 * Standard component len calculation does not apply, as the texture formats contain multiple
758 * channels, but associated data format contains several compacted components. */
759 if ((tex_format == GPU_R11F_G11F_B10F && data_format == GPU_DATA_10_11_11_REV) ||
760 ((tex_format == GPU_RGB10_A2 || tex_format == GPU_RGB10_A2UI) &&
761 data_format == GPU_DATA_2_10_10_10_REV))
762 {
763 return 4;
764 }
765
766 return to_component_len(tex_format) * to_bytesize(data_format);
767}
768
769/* Definitely not complete, edit according to the gl specification. */
770constexpr inline bool validate_data_format(eGPUTextureFormat tex_format,
771 eGPUDataFormat data_format)
772{
773 switch (tex_format) {
774 /* Formats texture & render-buffer */
775 case GPU_RGBA32UI:
776 case GPU_RG32UI:
777 case GPU_R32UI:
778 return ELEM(data_format, GPU_DATA_UINT);
779 case GPU_RGBA16UI:
780 case GPU_RG16UI:
781 case GPU_R16UI:
782 return ELEM(data_format, GPU_DATA_UINT); /* Also GPU_DATA_USHORT if needed. */
783 case GPU_RGBA8UI:
784 case GPU_RG8UI:
785 case GPU_R8UI:
786 return ELEM(data_format, GPU_DATA_UINT, GPU_DATA_UBYTE);
787
788 case GPU_RGBA32I:
789 case GPU_RG32I:
790 case GPU_R32I:
791 return ELEM(data_format, GPU_DATA_INT);
792 case GPU_RGBA16I:
793 case GPU_RG16I:
794 case GPU_R16I:
795 return ELEM(data_format, GPU_DATA_INT); /* Also GPU_DATA_SHORT if needed. */
796 case GPU_RGBA8I:
797 case GPU_RG8I:
798 case GPU_R8I:
799 return ELEM(data_format, GPU_DATA_INT); /* Also GPU_DATA_BYTE if needed. */
800
801 case GPU_RGBA32F:
802 case GPU_RG32F:
803 case GPU_R32F:
804 return ELEM(data_format, GPU_DATA_FLOAT);
805 case GPU_RGBA16F:
806 case GPU_RG16F:
807 case GPU_R16F:
808 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_HALF_FLOAT);
809 case GPU_RGBA16:
810 case GPU_RG16:
811 case GPU_R16:
812 return ELEM(data_format, GPU_DATA_FLOAT); /* Also GPU_DATA_USHORT if needed. */
813 case GPU_RGBA8:
814 case GPU_RG8:
815 case GPU_R8:
816 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_UBYTE);
817
818 /* Special formats texture & render-buffer */
819 case GPU_RGB10_A2:
820 case GPU_RGB10_A2UI:
821 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_2_10_10_10_REV);
823 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_10_11_11_REV);
825 /* Should have its own type. For now, we rely on the backend to do the conversion. */
828 return ELEM(data_format, GPU_DATA_UINT_24_8, GPU_DATA_UINT);
829 case GPU_SRGB8_A8:
830 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_UBYTE);
831
832 /* Texture only formats. */
833 case GPU_RGB32UI:
834 return ELEM(data_format, GPU_DATA_UINT);
835 case GPU_RGB16UI:
836 return ELEM(data_format, GPU_DATA_UINT); /* Also GPU_DATA_SHORT if needed. */
837 case GPU_RGB8UI:
838 return ELEM(data_format, GPU_DATA_UINT); /* Also GPU_DATA_BYTE if needed. */
839 case GPU_RGB32I:
840 return ELEM(data_format, GPU_DATA_INT);
841 case GPU_RGB16I:
842 return ELEM(data_format, GPU_DATA_INT); /* Also GPU_DATA_USHORT if needed. */
843 case GPU_RGB8I:
844 return ELEM(data_format, GPU_DATA_INT, GPU_DATA_UBYTE);
845 case GPU_RGB16:
846 return ELEM(data_format, GPU_DATA_FLOAT); /* Also GPU_DATA_USHORT if needed. */
847 case GPU_RGB8:
848 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_UBYTE);
849 case GPU_RGBA16_SNORM:
850 case GPU_RGB16_SNORM:
851 case GPU_RG16_SNORM:
852 case GPU_R16_SNORM:
853 return ELEM(data_format, GPU_DATA_FLOAT); /* Also GPU_DATA_SHORT if needed. */
854 case GPU_RGBA8_SNORM:
855 case GPU_RGB8_SNORM:
856 case GPU_RG8_SNORM:
857 case GPU_R8_SNORM:
858 return ELEM(data_format, GPU_DATA_FLOAT); /* Also GPU_DATA_BYTE if needed. */
859 case GPU_RGB32F:
860 return ELEM(data_format, GPU_DATA_FLOAT);
861 case GPU_RGB16F:
862 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_HALF_FLOAT);
863
864 /* Special formats, texture only. */
868 case GPU_RGBA8_DXT1:
869 case GPU_RGBA8_DXT3:
870 case GPU_RGBA8_DXT5:
871 /* TODO(fclem): GPU_DATA_COMPRESSED for each compression? Wouldn't it be overkill?
872 * For now, expect format to be set to float. */
873 return ELEM(data_format, GPU_DATA_FLOAT);
874 case GPU_SRGB8:
875 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_UBYTE);
876 case GPU_RGB9_E5:
877 return ELEM(data_format, GPU_DATA_FLOAT);
878
879 /* Depth Formats. */
883 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_UINT);
884 }
886 return data_format == GPU_DATA_FLOAT;
887}
888
889/* Return default data format for an internal texture format. */
891{
892 switch (tex_format) {
893 /* Formats texture & render-buffer */
894 case GPU_RGBA32UI:
895 case GPU_RG32UI:
896 case GPU_R32UI:
897 case GPU_RGBA16UI:
898 case GPU_RG16UI:
899 case GPU_R16UI:
900 case GPU_RGBA8UI:
901 case GPU_RG8UI:
902 case GPU_R8UI:
903 return GPU_DATA_UINT;
904
905 case GPU_RGBA32I:
906 case GPU_RG32I:
907 case GPU_R32I:
908 case GPU_RGBA16I:
909 case GPU_RG16I:
910 case GPU_R16I:
911 case GPU_RGBA8I:
912 case GPU_RG8I:
913 case GPU_R8I:
914 return GPU_DATA_INT;
915
916 case GPU_RGBA32F:
917 case GPU_RG32F:
918 case GPU_R32F:
919 case GPU_RGBA16F:
920 case GPU_RG16F:
921 case GPU_R16F:
922 case GPU_RGBA16:
923 case GPU_RG16:
924 case GPU_R16:
925 case GPU_RGBA8:
926 case GPU_RG8:
927 case GPU_R8:
928 return GPU_DATA_FLOAT;
929
930 /* Special formats texture & render-buffer */
931 case GPU_RGB10_A2:
932 case GPU_RGB10_A2UI:
937 /* Should have its own type. For now, we rely on the backend to do the conversion. */
940 return GPU_DATA_UINT_24_8;
941 case GPU_SRGB8_A8:
942 return GPU_DATA_FLOAT;
943
944 /* Texture only formats. */
945 case GPU_RGB32UI:
946 case GPU_RGB16UI:
947 case GPU_RGB8UI:
948 return GPU_DATA_UINT;
949 case GPU_RGB32I:
950 case GPU_RGB16I:
951 case GPU_RGB8I:
952 return GPU_DATA_INT;
953 case GPU_RGB16:
954 case GPU_RGB8:
955 return GPU_DATA_FLOAT;
956 case GPU_RGBA16_SNORM:
957 case GPU_RGB16_SNORM:
958 case GPU_RG16_SNORM:
959 case GPU_R16_SNORM:
960 return GPU_DATA_FLOAT;
961 case GPU_RGBA8_SNORM:
962 case GPU_RGB8_SNORM:
963 case GPU_RG8_SNORM:
964 case GPU_R8_SNORM:
965 return GPU_DATA_FLOAT;
966 case GPU_RGB32F:
967 case GPU_RGB16F:
968 return GPU_DATA_FLOAT;
969
970 /* Special formats, texture only. */
974 case GPU_RGBA8_DXT1:
975 case GPU_RGBA8_DXT3:
976 case GPU_RGBA8_DXT5:
977 /* TODO(fclem): GPU_DATA_COMPRESSED for each compression? Wouldn't it be overkill?
978 * For now, expect format to be set to float. */
979 return GPU_DATA_FLOAT;
980 case GPU_SRGB8:
981 return GPU_DATA_FLOAT;
982 case GPU_RGB9_E5:
983 return GPU_DATA_FLOAT;
984
985 /* Depth Formats. */
989 return GPU_DATA_FLOAT;
990 }
992 return GPU_DATA_FLOAT;
993}
994
996{
997 switch (tex_format) {
998 /* Formats texture & render-buffer */
999 case GPU_RGBA32UI:
1000 case GPU_RG32UI:
1001 case GPU_R32UI:
1002 case GPU_RGBA16UI:
1003 case GPU_RG16UI:
1004 case GPU_R16UI:
1005 case GPU_RGBA8UI:
1006 case GPU_RG8UI:
1007 case GPU_R8UI:
1008 case GPU_RGBA32I:
1009 case GPU_RG32I:
1010 case GPU_R32I:
1011 case GPU_RGBA16I:
1012 case GPU_RG16I:
1013 case GPU_R16I:
1014 case GPU_RGBA8I:
1015 case GPU_RG8I:
1016 case GPU_R8I:
1017 case GPU_RGBA32F:
1018 case GPU_RG32F:
1019 case GPU_R32F:
1020 case GPU_RGBA16F:
1021 case GPU_RG16F:
1022 case GPU_R16F:
1023 case GPU_RGBA16:
1024 case GPU_RG16:
1025 case GPU_R16:
1026 case GPU_RGBA8:
1027 case GPU_RG8:
1028 case GPU_R8:
1029 return GPU_COLOR_BIT;
1030
1031 /* Special formats texture & render-buffer */
1032 case GPU_RGB10_A2:
1033 case GPU_RGB10_A2UI:
1034 case GPU_R11F_G11F_B10F:
1035 case GPU_SRGB8_A8:
1036 return GPU_COLOR_BIT;
1040
1041 /* Depth Formats. */
1045 return GPU_DEPTH_BIT;
1046
1047 /* Texture only formats. */
1048 case GPU_RGB32UI:
1049 case GPU_RGB16UI:
1050 case GPU_RGB8UI:
1051 case GPU_RGB32I:
1052 case GPU_RGB16I:
1053 case GPU_RGB8I:
1054 case GPU_RGB16:
1055 case GPU_RGB8:
1056 case GPU_RGBA16_SNORM:
1057 case GPU_RGB16_SNORM:
1058 case GPU_RG16_SNORM:
1059 case GPU_R16_SNORM:
1060 case GPU_RGBA8_SNORM:
1061 case GPU_RGB8_SNORM:
1062 case GPU_RG8_SNORM:
1063 case GPU_R8_SNORM:
1064 case GPU_RGB32F:
1065 case GPU_RGB16F:
1066 BLI_assert_msg(0, "This texture format is not compatible with framebuffer attachment.");
1067 return GPU_COLOR_BIT;
1068
1069 /* Special formats, texture only. */
1070 case GPU_SRGB8_A8_DXT1:
1071 case GPU_SRGB8_A8_DXT3:
1072 case GPU_SRGB8_A8_DXT5:
1073 case GPU_RGBA8_DXT1:
1074 case GPU_RGBA8_DXT3:
1075 case GPU_RGBA8_DXT5:
1076 case GPU_SRGB8:
1077 case GPU_RGB9_E5:
1078 BLI_assert_msg(0, "This texture format is not compatible with framebuffer attachment.");
1079 return GPU_COLOR_BIT;
1080 }
1082 return GPU_COLOR_BIT;
1083}
1084
1086{
1087 if (format->attr_len == 0) {
1088 BLI_assert_msg(0, "Incorrect vertex format for buffer texture");
1089 return GPU_DEPTH_COMPONENT24;
1090 }
1091 switch (format->attrs[0].comp_len) {
1092 case 1:
1093 switch (format->attrs[0].comp_type) {
1094 case GPU_COMP_I8:
1095 return GPU_R8I;
1096 case GPU_COMP_U8:
1097 return GPU_R8UI;
1098 case GPU_COMP_I16:
1099 return GPU_R16I;
1100 case GPU_COMP_U16:
1101 return GPU_R16UI;
1102 case GPU_COMP_I32:
1103 return GPU_R32I;
1104 case GPU_COMP_U32:
1105 return GPU_R32UI;
1106 case GPU_COMP_F32:
1107 return GPU_R32F;
1108 default:
1109 break;
1110 }
1111 break;
1112 case 2:
1113 switch (format->attrs[0].comp_type) {
1114 case GPU_COMP_I8:
1115 return GPU_RG8I;
1116 case GPU_COMP_U8:
1117 return GPU_RG8UI;
1118 case GPU_COMP_I16:
1119 return GPU_RG16I;
1120 case GPU_COMP_U16:
1121 return GPU_RG16UI;
1122 case GPU_COMP_I32:
1123 return GPU_RG32I;
1124 case GPU_COMP_U32:
1125 return GPU_RG32UI;
1126 case GPU_COMP_F32:
1127 return GPU_RG32F;
1128 default:
1129 break;
1130 }
1131 break;
1132 case 3:
1133 /* Not supported until GL 4.0 */
1134 break;
1135 case 4:
1136 switch (format->attrs[0].comp_type) {
1137 case GPU_COMP_I8:
1138 return GPU_RGBA8I;
1139 case GPU_COMP_U8:
1140 return GPU_RGBA8UI;
1141 case GPU_COMP_I16:
1142 return GPU_RGBA16I;
1143 case GPU_COMP_U16:
1144 /* NOTE: Checking the fetch mode to select the right GPU texture format. This can be
1145 * added to other formats as well. */
1146 switch (format->attrs[0].fetch_mode) {
1147 case GPU_FETCH_INT:
1148 return GPU_RGBA16UI;
1150 return GPU_RGBA16;
1152 return GPU_RGBA16F;
1153 case GPU_FETCH_FLOAT:
1154 return GPU_RGBA16F;
1155 }
1156 case GPU_COMP_I32:
1157 return GPU_RGBA32I;
1158 case GPU_COMP_U32:
1159 return GPU_RGBA32UI;
1160 case GPU_COMP_F32:
1161 return GPU_RGBA32F;
1162 default:
1163 break;
1164 }
1165 break;
1166 default:
1167 break;
1168 }
1169 BLI_assert_msg(0, "Unsupported vertex format for buffer texture");
1170 return GPU_DEPTH_COMPONENT24;
1171}
1172
1173} // namespace gpu
1174} // namespace blender
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
#define BLI_assert(a)
Definition BLI_assert.h:50
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:57
#define ATTR_FALLTHROUGH
MINLINE int max_ii(int a, int b)
unsigned int uint
#define ENUM_OPERATORS(_type, _max)
#define ELEM(...)
eGPUFrameBufferBits
@ GPU_DEPTH_BIT
@ GPU_STENCIL_BIT
@ GPU_COLOR_BIT
eGPUDataFormat
@ GPU_DATA_HALF_FLOAT
@ GPU_DATA_UINT_24_8
@ GPU_DATA_INT
@ GPU_DATA_10_11_11_REV
@ GPU_DATA_UBYTE
@ GPU_DATA_UINT
@ GPU_DATA_2_10_10_10_REV
@ GPU_DATA_FLOAT
eGPUTextureUsage
eGPUTextureFormat
@ GPU_RGB16
@ GPU_R16UI
@ GPU_RGB8
@ GPU_DEPTH32F_STENCIL8
@ GPU_SRGB8
@ GPU_R16I
@ GPU_SRGB8_A8
@ GPU_RG8_SNORM
@ GPU_DEPTH24_STENCIL8
@ GPU_RGB10_A2
@ GPU_RGB8I
@ GPU_R32I
@ GPU_RGBA8_SNORM
@ GPU_RGB10_A2UI
@ GPU_RG8UI
@ GPU_RGB16I
@ GPU_RGBA16_SNORM
@ GPU_RGB9_E5
@ GPU_SRGB8_A8_DXT5
@ GPU_RG8I
@ GPU_RG16I
@ GPU_RG32UI
@ GPU_RGB32I
@ GPU_RG8
@ GPU_RG32I
@ GPU_SRGB8_A8_DXT1
@ GPU_RGBA32UI
@ GPU_R8I
@ GPU_R16
@ GPU_RG16UI
@ GPU_RGBA8I
@ GPU_RGBA8_DXT1
@ GPU_RGBA8UI
@ GPU_RGB32F
@ GPU_RGBA16UI
@ GPU_RGBA16I
@ GPU_R8UI
@ GPU_RGBA16
@ GPU_SRGB8_A8_DXT3
@ GPU_RGB8_SNORM
@ GPU_RGBA8_DXT3
@ GPU_RGB32UI
@ GPU_R8_SNORM
@ GPU_RG32F
@ GPU_R8
@ GPU_RGB16_SNORM
@ GPU_DEPTH_COMPONENT24
@ GPU_RG16_SNORM
@ GPU_RGB8UI
@ GPU_RGB16F
@ GPU_RGB16UI
@ GPU_RGBA32I
@ GPU_RGBA8_DXT5
@ GPU_DEPTH_COMPONENT32F
@ GPU_R16_SNORM
@ GPU_DEPTH_COMPONENT16
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT_TO_FLOAT_UNIT
@ GPU_FETCH_INT
@ GPU_FETCH_INT_TO_FLOAT
@ GPU_COMP_U16
@ GPU_COMP_F32
@ GPU_COMP_I32
@ GPU_COMP_I8
@ GPU_COMP_U32
@ GPU_COMP_I16
@ GPU_COMP_U8
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Texture
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
virtual void unmap()=0
virtual void * map()=0
virtual int64_t get_native_handle()=0
virtual size_t get_size()=0
virtual void mip_range_set(int min, int max)=0
virtual uint gl_bindcode_get() const =0
void attach_to(FrameBuffer *fb, GPUAttachmentType type)
bool init_view(GPUTexture *src, eGPUTextureFormat format, eGPUTextureType type, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array, bool use_stencil)
virtual bool init_internal(GPUTexture *src, int mip_offset, int layer_offset, bool use_stencil)=0
virtual bool init_internal(VertBuf *vbo)=0
int mip_width_get(int mip) const
int mip_depth_get(int mip) const
eGPUTextureFormatFlag format_flag_get() const
virtual void * read(int mip, eGPUDataFormat format)=0
virtual void generate_mipmap()=0
eGPUTextureFormat format_get() const
eGPUTextureFormatFlag format_flag_
void update(eGPUDataFormat format, const void *data)
eGPUTextureUsage gpu_image_usage_flags_
eGPUTextureUsage usage_get() const
char name_[DEBUG_NAME_LEN]
FrameBuffer * fb_[GPU_TEX_MAX_FBO_ATTACHED]
virtual void swizzle_set(const char swizzle_mask[4])=0
virtual void update_sub(int offset[3], int extent[3], eGPUDataFormat format, GPUPixelBuffer *pixbuf)=0
GPUAttachmentType fb_attachment_[GPU_TEX_MAX_FBO_ATTACHED]
GPUAttachmentType attachment_type(int slot) const
bool init_1D(int w, int layers, int mip_len, eGPUTextureFormat format)
int mip_height_get(int mip) const
virtual void clear(eGPUDataFormat format, const void *data)=0
eGPUTextureType type_get() const
bool init_buffer(VertBuf *vbo, eGPUTextureFormat format)
virtual bool init_internal()=0
bool init_cubemap(int w, int layers, int mip_len, eGPUTextureFormat format)
virtual void update_sub(int mip, int offset[3], int extent[3], eGPUDataFormat format, const void *data)=0
void mip_size_get(int mip, int r_size[3]) const
virtual void copy_to(Texture *tex)=0
void usage_set(eGPUTextureUsage usage_flags)
bool init_3D(int w, int h, int d, int mip_len, eGPUTextureFormat format)
void detach_from(FrameBuffer *fb)
bool init_2D(int w, int h, int layers, int mip_len, eGPUTextureFormat format)
additional_info("compositor_sum_float_shared") .push_constant(Type additional_info("compositor_sum_float_shared") .push_constant(Type GPU_RGBA32F
DOF_TILES_FLATTEN_GROUP_SIZE coc_tx GPU_R11F_G11F_B10F
out_radiance out_gbuf_normal out_gbuf_closure2 GPU_RG16
SHADOW_TILEMAP_RES tiles_buf[] statistics_buf render_view_buf[SHADOW_VIEW_MAX] GPU_R32UI
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
@ GPU_FB_DEPTH_STENCIL_ATTACHMENT
@ GPU_FB_COLOR_ATTACHMENT0
@ GPU_FB_DEPTH_ATTACHMENT
#define DEBUG_NAME_LEN
#define GPU_TEX_MAX_FBO_ATTACHED
BLI_INLINE float fb(float length, float L)
format
static Context * unwrap(GPUContext *ctx)
size_t to_block_size(eGPUTextureFormat data_type)
static GPUContext * wrap(Context *ctx)
constexpr bool validate_data_format(eGPUTextureFormat tex_format, eGPUDataFormat data_format)
size_t to_bytesize(GPUIndexBufType type)
eGPUFrameBufferBits to_framebuffer_bits(eGPUTextureFormat tex_format)
eGPUDataFormat to_data_format(eGPUTextureFormat tex_format)
static eGPUTextureFormat to_texture_format(const GPUVertFormat *format)
eGPUTextureFormatFlag to_format_flag(eGPUTextureFormat format)
int to_component_len(eGPUTextureFormat format)
#define min(a, b)
Definition sort.c:32
__int64 int64_t
Definition stdint.h:89
static constexpr GPUSamplerState default_sampler()