Blender V5.0
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
8
9#pragma once
10
11#include "BLI_assert.h"
12
13#include "GPU_vertex_buffer.hh"
14
16
17namespace blender::gpu {
18
20{
21 switch (format) {
22 case TextureFormat::SFLOAT_16_16_16_16:
23 case TextureFormat::SFLOAT_16_16_16:
24 case TextureFormat::SFLOAT_16_16:
25 case TextureFormat::SFLOAT_16:
26 return true;
27 default:
28 return false;
29 }
30}
31
33 /* The format has a depth component and can be used as depth attachment. */
34 GPU_FORMAT_DEPTH = (1 << 0),
35 /* The format has a stencil component and can be used as stencil attachment. */
37 /* The format represent non-normalized integers data, either signed or unsigned. */
39 /* The format is using normalized integers, either signed or unsigned. */
41 /* The format represent floating point data, either signed or unsigned. */
42 GPU_FORMAT_FLOAT = (1 << 4),
43 /* The format is using block compression. */
45 /* The format is using sRGB encoded storage. */
46 GPU_FORMAT_SRGB = (1 << 6),
47 /* The format can store negative values. */
49
51};
52
54
67
69
70/* Format types for samplers within the shader.
71 * This covers the sampler format type permutations within GLSL/MSL. */
76 /* Special case for depth, as these require differing dummy formats. */
79};
80
82
83#ifndef NDEBUG
84# define DEBUG_NAME_LEN 64
85#else
86# define DEBUG_NAME_LEN 8
87#endif
88
89/* Maximum number of image units. */
90#define GPU_MAX_IMAGE 8
91
92/* Maximum number of FBOs a texture can be attached to. */
93#define GPU_TEX_MAX_FBO_ATTACHED 32
94
99class Texture {
100 public:
104 int refcount = 1;
106 int src_w = 0, src_h = 0;
107#ifndef GPU_NO_USE_PY_REFERENCES
112 void **py_ref = nullptr;
113#endif
114
115 protected:
116 /* ---- Texture format (immutable after init). ---- */
118 int w_, h_, d_;
127
129 /* TODO(fclem): Should become immutable and the need for mipmaps should be specified upfront. */
130 int mipmaps_ = -1;
132 int mip_min_ = 0, mip_max_ = 0;
133
136
140
141 public:
142 Texture(const char *name);
143 virtual ~Texture();
144
145 /* Return true on success. */
146 bool init_1D(int w, int layers, int mip_len, TextureFormat format);
147 bool init_2D(int w, int h, int layers, int mip_len, TextureFormat format);
148 bool init_3D(int w, int h, int d, int mip_len, TextureFormat format);
149 bool init_cubemap(int w, int layers, int mip_len, TextureFormat format);
151 bool init_view(Texture *src,
153 GPUTextureType type,
154 int mip_start,
155 int mip_len,
156 int layer_start,
157 int layer_len,
158 bool cube_as_array,
159 bool use_stencil);
160
161 virtual void generate_mipmap() = 0;
162 virtual void copy_to(Texture *tex) = 0;
163 virtual void clear(eGPUDataFormat format, const void *data) = 0;
164 virtual void swizzle_set(const char swizzle_mask[4]) = 0;
165 virtual void mip_range_set(int min, int max) = 0;
166 virtual void *read(int mip, eGPUDataFormat format) = 0;
167
170 void update(eGPUDataFormat format, const void *data);
171
172 void usage_set(eGPUTextureUsage usage_flags);
173
174 virtual void update_sub(
175 int mip, int offset[3], int extent[3], eGPUDataFormat format, const void *data) = 0;
176 virtual void update_sub(int offset[3],
177 int extent[3],
179 GPUPixelBuffer *pixbuf) = 0;
180
181 int width_get() const
182 {
183 return w_;
184 }
185 int height_get() const
186 {
187 return h_;
188 }
189 int depth_get() const
190 {
191 return d_;
192 }
194 {
196 }
197
198 void mip_size_get(int mip, int r_size[3]) const
199 {
200 /* TODO: assert if lvl is below the limit of 1px in each dimension. */
201 int div = 1 << mip;
202 r_size[0] = max_ii(1, w_ / div);
203
205 r_size[1] = h_;
206 }
207 else if (h_ > 0) {
208 r_size[1] = max_ii(1, h_ / div);
209 }
210
212 r_size[2] = d_;
213 }
214 else if (d_ > 0) {
215 r_size[2] = max_ii(1, d_ / div);
216 }
217 }
218
219 int mip_width_get(int mip) const
220 {
221 return max_ii(1, w_ / (1 << mip));
222 }
223 int mip_height_get(int mip) const
224 {
225 return (type_ == GPU_TEXTURE_1D_ARRAY) ? h_ : max_ii(1, h_ / (1 << mip));
226 }
227 int mip_depth_get(int mip) const
228 {
229 return (type_ & (GPU_TEXTURE_ARRAY | GPU_TEXTURE_CUBE)) ? d_ : max_ii(1, d_ / (1 << mip));
230 }
231
232 /* Return number of dimension taking the array type into account. */
234 {
235 const int array = (type_ & GPU_TEXTURE_ARRAY) ? 1 : 0;
236 switch (type_ & ~GPU_TEXTURE_ARRAY) {
238 return 1;
239 case GPU_TEXTURE_1D:
240 return 1 + array;
241 case GPU_TEXTURE_2D:
242 return 2 + array;
243 case GPU_TEXTURE_CUBE:
244 case GPU_TEXTURE_3D:
245 default:
246 return 3;
247 }
248 }
249 /* Return number of array layer (or face layer) for texture array or 1 for the others. */
250 int layer_count() const
251 {
252 switch (type_) {
254 return h_;
257 return d_;
258 default:
259 return 1;
260 }
261 }
262
263 int mip_count() const
264 {
265 return mipmaps_;
266 }
267
269 {
270 return format_;
271 }
273 {
274 return format_flag_;
275 }
277 {
278 return type_;
279 }
281 {
282 switch (format_) {
283 case TextureFormat::SFLOAT_32_DEPTH:
284 case TextureFormat::UNORM_16_DEPTH:
285 BLI_assert(slot == 0);
287 case TextureFormat::SFLOAT_32_DEPTH_UINT_8:
288 BLI_assert(slot == 0);
290 default:
291 /* Valid color attachment formats. */
292 return GPU_FB_COLOR_ATTACHMENT0 + slot;
293
294 case TextureFormat::SFLOAT_16_16_16:
295 case TextureFormat::SNORM_16_16_16_16:
296 case TextureFormat::SNORM_8_8_8_8:
297 case TextureFormat::SFLOAT_32_32_32:
298 case TextureFormat::SINT_32_32_32:
299 case TextureFormat::UINT_32_32_32:
300 case TextureFormat::SNORM_16_16_16:
301 case TextureFormat::SINT_16_16_16:
302 case TextureFormat::UINT_16_16_16:
303 case TextureFormat::UNORM_16_16_16:
304 case TextureFormat::SNORM_8_8_8:
305 case TextureFormat::UNORM_8_8_8:
306 case TextureFormat::SINT_8_8_8:
307 case TextureFormat::UINT_8_8_8:
308 case TextureFormat::SNORM_16_16:
309 case TextureFormat::SNORM_8_8:
310 case TextureFormat::SNORM_16:
311 case TextureFormat::SNORM_8:
312 case TextureFormat::SRGB_DXT1:
313 case TextureFormat::SRGB_DXT3:
314 case TextureFormat::SRGB_DXT5:
315 case TextureFormat::SNORM_DXT1:
316 case TextureFormat::SNORM_DXT3:
317 case TextureFormat::SNORM_DXT5:
318 case TextureFormat::SRGBA_8_8_8:
319 case TextureFormat::UFLOAT_9_9_9_EXP_5:
320 BLI_assert_msg(0, "Texture cannot be attached to a framebuffer because of its type");
322 }
323 }
324
325 protected:
326 virtual bool init_internal() = 0;
327 virtual bool init_internal(VertBuf *vbo) = 0;
329 int mip_offset,
330 int layer_offset,
331 bool use_stencil) = 0;
332};
333
334/* GPU pixel Buffer. */
336 protected:
337 size_t size_ = 0;
338
339 public:
340 PixelBuffer(size_t size) : size_(size) {};
341 virtual ~PixelBuffer() = default;
342
343 virtual void *map() = 0;
344 virtual void unmap() = 0;
346 virtual size_t get_size() = 0;
347};
348
349/* Syntactic sugar. */
350static inline GPUPixelBuffer *wrap(PixelBuffer *pixbuf)
351{
352 return reinterpret_cast<GPUPixelBuffer *>(pixbuf);
353}
354static inline PixelBuffer *unwrap(GPUPixelBuffer *pixbuf)
355{
356 return reinterpret_cast<PixelBuffer *>(pixbuf);
357}
358static inline const PixelBuffer *unwrap(const GPUPixelBuffer *pixbuf)
359{
360 return reinterpret_cast<const PixelBuffer *>(pixbuf);
361}
362
363#undef DEBUG_NAME_LEN
364
366{
368}
369
370inline size_t to_block_size(TextureFormat data_type)
371{
372 switch (data_type) {
373 case TextureFormat::SRGB_DXT1:
374 case TextureFormat::SNORM_DXT1:
375 return 8;
376 case TextureFormat::SRGB_DXT3:
377 case TextureFormat::SRGB_DXT5:
378 case TextureFormat::SNORM_DXT3:
379 case TextureFormat::SNORM_DXT5:
380 return 16;
381 default:
382 BLI_assert_msg(0, "Texture format is not a compressed format");
383 return 0;
384 }
385}
386
388{
389 switch (format) {
390 /* Formats texture & render-buffer */
391 case TextureFormat::UINT_8_8_8_8:
392 return GPU_FORMAT_INTEGER;
393 case TextureFormat::SINT_8_8_8_8:
395 case TextureFormat::UNORM_8_8_8_8:
397 case TextureFormat::UINT_32_32_32_32:
398 return GPU_FORMAT_INTEGER;
399 case TextureFormat::SINT_32_32_32_32:
401 case TextureFormat::SFLOAT_32_32_32_32:
403 case TextureFormat::UINT_16_16_16_16:
404 return GPU_FORMAT_INTEGER;
405 case TextureFormat::SINT_16_16_16_16:
407 case TextureFormat::SFLOAT_16_16_16_16:
409 case TextureFormat::UNORM_16_16_16_16:
411 case TextureFormat::UINT_8_8:
412 return GPU_FORMAT_INTEGER;
413 case TextureFormat::SINT_8_8:
415 case TextureFormat::UNORM_8_8:
417 case TextureFormat::UINT_32_32:
418 return GPU_FORMAT_INTEGER;
419 case TextureFormat::SINT_32_32:
421 case TextureFormat::SFLOAT_32_32:
423 case TextureFormat::UINT_16_16:
424 return GPU_FORMAT_INTEGER;
425 case TextureFormat::SINT_16_16:
427 case TextureFormat::SFLOAT_16_16:
429 case TextureFormat::UNORM_16_16:
431 case TextureFormat::UINT_8:
432 return GPU_FORMAT_INTEGER;
433 case TextureFormat::SINT_8:
435 case TextureFormat::UNORM_8:
437 case TextureFormat::UINT_32:
438 return GPU_FORMAT_INTEGER;
439 case TextureFormat::SINT_32:
441 case TextureFormat::SFLOAT_32:
443 case TextureFormat::UINT_16:
444 return GPU_FORMAT_INTEGER;
445 case TextureFormat::SINT_16:
447 case TextureFormat::SFLOAT_16:
449 case TextureFormat::UNORM_16:
451
452 /* Special formats texture & render-buffer */
453 case TextureFormat::UNORM_10_10_10_2:
455 case TextureFormat::UINT_10_10_10_2:
456 return GPU_FORMAT_INTEGER;
457 case TextureFormat::UFLOAT_11_11_10:
458 return GPU_FORMAT_FLOAT;
459 case TextureFormat::SFLOAT_32_DEPTH_UINT_8:
461 case TextureFormat::SRGBA_8_8_8_8:
463
464 /* Texture only formats. */
465 case TextureFormat::SFLOAT_16_16_16:
467 case TextureFormat::SNORM_16_16_16:
469 case TextureFormat::SINT_16_16_16:
471 case TextureFormat::UINT_16_16_16:
472 return GPU_FORMAT_INTEGER;
473 case TextureFormat::UNORM_16_16_16:
475 case TextureFormat::SNORM_16_16_16_16:
476 case TextureFormat::SNORM_8_8_8_8:
478 case TextureFormat::SFLOAT_32_32_32:
480 case TextureFormat::SINT_32_32_32:
482 case TextureFormat::UINT_32_32_32:
483 return GPU_FORMAT_INTEGER;
484 case TextureFormat::SNORM_8_8_8:
486 case TextureFormat::UNORM_8_8_8:
488 case TextureFormat::SINT_8_8_8:
490 case TextureFormat::UINT_8_8_8:
491 return GPU_FORMAT_INTEGER;
492 case TextureFormat::SNORM_16_16:
493 case TextureFormat::SNORM_8_8:
494 case TextureFormat::SNORM_16:
495 case TextureFormat::SNORM_8:
497
498 /* Special formats, texture only. */
499 case TextureFormat::SRGB_DXT1:
500 case TextureFormat::SRGB_DXT3:
501 case TextureFormat::SRGB_DXT5:
503 case TextureFormat::SNORM_DXT1:
504 case TextureFormat::SNORM_DXT3:
505 case TextureFormat::SNORM_DXT5:
507 case TextureFormat::SRGBA_8_8_8:
509 case TextureFormat::UFLOAT_9_9_9_EXP_5:
510 return GPU_FORMAT_FLOAT;
511
512 /* Depth Formats. */
513 case TextureFormat::SFLOAT_32_DEPTH:
514 case TextureFormat::UNORM_16_DEPTH:
515 return GPU_FORMAT_DEPTH;
516
519 }
521 return GPU_FORMAT_FLOAT;
522}
523
528
529inline size_t to_bytesize(eGPUDataFormat data_format)
530{
531 switch (data_format) {
532 case GPU_DATA_UBYTE:
533 return 1;
535 return 2;
536 case GPU_DATA_FLOAT:
537 case GPU_DATA_INT:
538 case GPU_DATA_UINT:
539 return 4;
543 return 4;
544 }
546 return 0;
547}
548
549inline size_t to_bytesize(TextureFormat tex_format, eGPUDataFormat data_format)
550{
551 /* Special case for compacted types.
552 * Standard component len calculation does not apply, as the texture formats contain multiple
553 * channels, but associated data format contains several compacted components. */
554 if ((tex_format == TextureFormat::UFLOAT_11_11_10 && data_format == GPU_DATA_10_11_11_REV) ||
555 ((tex_format == TextureFormat::UNORM_10_10_10_2 ||
556 tex_format == TextureFormat::UINT_10_10_10_2) &&
557 data_format == GPU_DATA_2_10_10_10_REV))
558 {
559 return 4;
560 }
561
562 return to_component_len(tex_format) * to_bytesize(data_format);
563}
564
565/* Definitely not complete, edit according to the gl specification. */
566constexpr bool validate_data_format(TextureFormat tex_format, eGPUDataFormat data_format)
567{
568 switch (tex_format) {
569 /* Formats texture & render-buffer */
570 case TextureFormat::UINT_32_32_32_32:
571 case TextureFormat::UINT_32_32:
572 case TextureFormat::UINT_32:
573 return ELEM(data_format, GPU_DATA_UINT);
574 case TextureFormat::UINT_16_16_16_16:
575 case TextureFormat::UINT_16_16:
576 case TextureFormat::UINT_16:
577 return ELEM(data_format, GPU_DATA_UINT); /* Also GPU_DATA_USHORT if needed. */
578 case TextureFormat::UINT_8_8_8_8:
579 case TextureFormat::UINT_8_8:
580 case TextureFormat::UINT_8:
581 return ELEM(data_format, GPU_DATA_UINT, GPU_DATA_UBYTE);
582
583 case TextureFormat::SINT_32_32_32_32:
584 case TextureFormat::SINT_32_32:
585 case TextureFormat::SINT_32:
586 return ELEM(data_format, GPU_DATA_INT);
587 case TextureFormat::SINT_16_16_16_16:
588 case TextureFormat::SINT_16_16:
589 case TextureFormat::SINT_16:
590 return ELEM(data_format, GPU_DATA_INT); /* Also GPU_DATA_SHORT if needed. */
591 case TextureFormat::SINT_8_8_8_8:
592 case TextureFormat::SINT_8_8:
593 case TextureFormat::SINT_8:
594 return ELEM(data_format, GPU_DATA_INT); /* Also GPU_DATA_BYTE if needed. */
595
596 case TextureFormat::SFLOAT_32_32_32_32:
597 case TextureFormat::SFLOAT_32_32:
598 case TextureFormat::SFLOAT_32:
599 return ELEM(data_format, GPU_DATA_FLOAT);
600 case TextureFormat::SFLOAT_16_16_16_16:
601 case TextureFormat::SFLOAT_16_16:
602 case TextureFormat::SFLOAT_16:
603 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_HALF_FLOAT);
604 case TextureFormat::UNORM_16_16_16_16:
605 case TextureFormat::UNORM_16_16:
606 case TextureFormat::UNORM_16:
607 return ELEM(data_format, GPU_DATA_FLOAT); /* Also GPU_DATA_USHORT if needed. */
608 case TextureFormat::UNORM_8_8_8_8:
609 case TextureFormat::UNORM_8_8:
610 case TextureFormat::UNORM_8:
611 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_UBYTE);
612
613 /* Special formats texture & render-buffer */
614 case TextureFormat::UNORM_10_10_10_2:
615 case TextureFormat::UINT_10_10_10_2:
616 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_2_10_10_10_REV);
617 case TextureFormat::UFLOAT_11_11_10:
618 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_10_11_11_REV);
619 case TextureFormat::SFLOAT_32_DEPTH_UINT_8:
620 /* Should have its own type. For now, we rely on the backend to do the conversion. */
622 case TextureFormat::SRGBA_8_8_8_8:
623 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_UBYTE);
624
625 /* Texture only formats. */
626 case TextureFormat::UINT_32_32_32:
627 return ELEM(data_format, GPU_DATA_UINT);
628 case TextureFormat::UINT_16_16_16:
629 return ELEM(data_format, GPU_DATA_UINT); /* Also GPU_DATA_SHORT if needed. */
630 case TextureFormat::UINT_8_8_8:
631 return ELEM(data_format, GPU_DATA_UINT); /* Also GPU_DATA_BYTE if needed. */
632 case TextureFormat::SINT_32_32_32:
633 return ELEM(data_format, GPU_DATA_INT);
634 case TextureFormat::SINT_16_16_16:
635 return ELEM(data_format, GPU_DATA_INT); /* Also GPU_DATA_USHORT if needed. */
636 case TextureFormat::SINT_8_8_8:
637 return ELEM(data_format, GPU_DATA_INT, GPU_DATA_UBYTE);
638 case TextureFormat::UNORM_16_16_16:
639 return ELEM(data_format, GPU_DATA_FLOAT); /* Also GPU_DATA_USHORT if needed. */
640 case TextureFormat::UNORM_8_8_8:
641 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_UBYTE);
642 case TextureFormat::SNORM_16_16_16_16:
643 case TextureFormat::SNORM_16_16_16:
644 case TextureFormat::SNORM_16_16:
645 case TextureFormat::SNORM_16:
646 return ELEM(data_format, GPU_DATA_FLOAT); /* Also GPU_DATA_SHORT if needed. */
647 case TextureFormat::SNORM_8_8_8_8:
648 case TextureFormat::SNORM_8_8_8:
649 case TextureFormat::SNORM_8_8:
650 case TextureFormat::SNORM_8:
651 return ELEM(data_format, GPU_DATA_FLOAT); /* Also GPU_DATA_BYTE if needed. */
652 case TextureFormat::SFLOAT_32_32_32:
653 return ELEM(data_format, GPU_DATA_FLOAT);
654 case TextureFormat::SFLOAT_16_16_16:
655 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_HALF_FLOAT);
656
657 /* Special formats, texture only. */
658 case TextureFormat::SRGB_DXT1:
659 case TextureFormat::SRGB_DXT3:
660 case TextureFormat::SRGB_DXT5:
661 case TextureFormat::SNORM_DXT1:
662 case TextureFormat::SNORM_DXT3:
663 case TextureFormat::SNORM_DXT5:
664 /* TODO(fclem): GPU_DATA_COMPRESSED for each compression? Wouldn't it be overkill?
665 * For now, expect format to be set to float. */
666 return ELEM(data_format, GPU_DATA_FLOAT);
667 case TextureFormat::SRGBA_8_8_8:
668 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_UBYTE);
669 case TextureFormat::UFLOAT_9_9_9_EXP_5:
670 return ELEM(data_format, GPU_DATA_FLOAT);
671
672 /* Depth Formats. */
673 case TextureFormat::SFLOAT_32_DEPTH:
674 case TextureFormat::UNORM_16_DEPTH:
675 return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_UINT);
676
679 }
681 return data_format == GPU_DATA_FLOAT;
682}
683
684/* Return default data format for an internal texture format. */
686{
687 switch (tex_format) {
688 /* Formats texture & render-buffer */
689 case TextureFormat::UINT_32_32_32_32:
690 case TextureFormat::UINT_32_32:
691 case TextureFormat::UINT_32:
692 case TextureFormat::UINT_16_16_16_16:
693 case TextureFormat::UINT_16_16:
694 case TextureFormat::UINT_16:
695 case TextureFormat::UINT_8_8_8_8:
696 case TextureFormat::UINT_8_8:
697 case TextureFormat::UINT_8:
698 return GPU_DATA_UINT;
699
700 case TextureFormat::SINT_32_32_32_32:
701 case TextureFormat::SINT_32_32:
702 case TextureFormat::SINT_32:
703 case TextureFormat::SINT_16_16_16_16:
704 case TextureFormat::SINT_16_16:
705 case TextureFormat::SINT_16:
706 case TextureFormat::SINT_8_8_8_8:
707 case TextureFormat::SINT_8_8:
708 case TextureFormat::SINT_8:
709 return GPU_DATA_INT;
710
711 case TextureFormat::SFLOAT_32_32_32_32:
712 case TextureFormat::SFLOAT_32_32:
713 case TextureFormat::SFLOAT_32:
714 case TextureFormat::SFLOAT_16_16_16_16:
715 case TextureFormat::SFLOAT_16_16:
716 case TextureFormat::SFLOAT_16:
717 case TextureFormat::UNORM_16_16_16_16:
718 case TextureFormat::UNORM_16_16:
719 case TextureFormat::UNORM_16:
720 case TextureFormat::UNORM_8_8_8_8:
721 case TextureFormat::UNORM_8_8:
722 case TextureFormat::UNORM_8:
723 return GPU_DATA_FLOAT;
724
725 /* Special formats texture & render-buffer */
726 case TextureFormat::UNORM_10_10_10_2:
727 case TextureFormat::UINT_10_10_10_2:
729 case TextureFormat::UFLOAT_11_11_10:
731 case TextureFormat::SFLOAT_32_DEPTH_UINT_8:
732 /* Should have its own type. For now, we rely on the backend to do the conversion. */
734 case TextureFormat::SRGBA_8_8_8_8:
735 return GPU_DATA_FLOAT;
736
737 /* Texture only formats. */
738 case TextureFormat::UINT_32_32_32:
739 case TextureFormat::UINT_16_16_16:
740 case TextureFormat::UINT_8_8_8:
741 return GPU_DATA_UINT;
742 case TextureFormat::SINT_32_32_32:
743 case TextureFormat::SINT_16_16_16:
744 case TextureFormat::SINT_8_8_8:
745 return GPU_DATA_INT;
746 case TextureFormat::UNORM_16_16_16:
747 case TextureFormat::UNORM_8_8_8:
748 return GPU_DATA_FLOAT;
749 case TextureFormat::SNORM_16_16_16_16:
750 case TextureFormat::SNORM_16_16_16:
751 case TextureFormat::SNORM_16_16:
752 case TextureFormat::SNORM_16:
753 return GPU_DATA_FLOAT;
754 case TextureFormat::SNORM_8_8_8_8:
755 case TextureFormat::SNORM_8_8_8:
756 case TextureFormat::SNORM_8_8:
757 case TextureFormat::SNORM_8:
758 return GPU_DATA_FLOAT;
759 case TextureFormat::SFLOAT_32_32_32:
760 case TextureFormat::SFLOAT_16_16_16:
761 return GPU_DATA_FLOAT;
762
763 /* Special formats, texture only. */
764 case TextureFormat::SRGB_DXT1:
765 case TextureFormat::SRGB_DXT3:
766 case TextureFormat::SRGB_DXT5:
767 case TextureFormat::SNORM_DXT1:
768 case TextureFormat::SNORM_DXT3:
769 case TextureFormat::SNORM_DXT5:
770 /* TODO(fclem): GPU_DATA_COMPRESSED for each compression? Wouldn't it be overkill?
771 * For now, expect format to be set to float. */
772 return GPU_DATA_FLOAT;
773 case TextureFormat::SRGBA_8_8_8:
774 return GPU_DATA_FLOAT;
775 case TextureFormat::UFLOAT_9_9_9_EXP_5:
776 return GPU_DATA_FLOAT;
777
778 /* Depth Formats. */
779 case TextureFormat::SFLOAT_32_DEPTH:
780 case TextureFormat::UNORM_16_DEPTH:
781 return GPU_DATA_FLOAT;
784 }
786 return GPU_DATA_FLOAT;
787}
788
790{
791 switch (tex_format) {
792 /* Formats texture & render-buffer */
793 case TextureFormat::UINT_32_32_32_32:
794 case TextureFormat::UINT_32_32:
795 case TextureFormat::UINT_32:
796 case TextureFormat::UINT_16_16_16_16:
797 case TextureFormat::UINT_16_16:
798 case TextureFormat::UINT_16:
799 case TextureFormat::UINT_8_8_8_8:
800 case TextureFormat::UINT_8_8:
801 case TextureFormat::UINT_8:
802 case TextureFormat::SINT_32_32_32_32:
803 case TextureFormat::SINT_32_32:
804 case TextureFormat::SINT_32:
805 case TextureFormat::SINT_16_16_16_16:
806 case TextureFormat::SINT_16_16:
807 case TextureFormat::SINT_16:
808 case TextureFormat::SINT_8_8_8_8:
809 case TextureFormat::SINT_8_8:
810 case TextureFormat::SINT_8:
811 case TextureFormat::SFLOAT_32_32_32_32:
812 case TextureFormat::SFLOAT_32_32:
813 case TextureFormat::SFLOAT_32:
814 case TextureFormat::SFLOAT_16_16_16_16:
815 case TextureFormat::SFLOAT_16_16:
816 case TextureFormat::SFLOAT_16:
817 case TextureFormat::UNORM_16_16_16_16:
818 case TextureFormat::UNORM_16_16:
819 case TextureFormat::UNORM_16:
820 case TextureFormat::UNORM_8_8_8_8:
821 case TextureFormat::UNORM_8_8:
822 case TextureFormat::UNORM_8:
823 return GPU_COLOR_BIT;
824
825 /* Special formats texture & render-buffer */
826 case TextureFormat::UNORM_10_10_10_2:
827 case TextureFormat::UINT_10_10_10_2:
828 case TextureFormat::UFLOAT_11_11_10:
829 case TextureFormat::SRGBA_8_8_8_8:
830 return GPU_COLOR_BIT;
831 case TextureFormat::SFLOAT_32_DEPTH_UINT_8:
833
834 /* Depth Formats. */
835 case TextureFormat::SFLOAT_32_DEPTH:
836 case TextureFormat::UNORM_16_DEPTH:
837 return GPU_DEPTH_BIT;
838
839 /* Texture only formats. */
840 case TextureFormat::UINT_32_32_32:
841 case TextureFormat::UINT_16_16_16:
842 case TextureFormat::UINT_8_8_8:
843 case TextureFormat::SINT_32_32_32:
844 case TextureFormat::SINT_16_16_16:
845 case TextureFormat::SINT_8_8_8:
846 case TextureFormat::UNORM_16_16_16:
847 case TextureFormat::UNORM_8_8_8:
848 case TextureFormat::SNORM_16_16_16_16:
849 case TextureFormat::SNORM_16_16_16:
850 case TextureFormat::SNORM_16_16:
851 case TextureFormat::SNORM_16:
852 case TextureFormat::SNORM_8_8_8_8:
853 case TextureFormat::SNORM_8_8_8:
854 case TextureFormat::SNORM_8_8:
855 case TextureFormat::SNORM_8:
856 case TextureFormat::SFLOAT_32_32_32:
857 case TextureFormat::SFLOAT_16_16_16:
858 BLI_assert_msg(0, "This texture format is not compatible with framebuffer attachment.");
859 return GPU_COLOR_BIT;
860
861 /* Special formats, texture only. */
862 case TextureFormat::SRGB_DXT1:
863 case TextureFormat::SRGB_DXT3:
864 case TextureFormat::SRGB_DXT5:
865 case TextureFormat::SNORM_DXT1:
866 case TextureFormat::SNORM_DXT3:
867 case TextureFormat::SNORM_DXT5:
868 case TextureFormat::SRGBA_8_8_8:
869 case TextureFormat::UFLOAT_9_9_9_EXP_5:
870 BLI_assert_msg(0, "This texture format is not compatible with framebuffer attachment.");
871 return GPU_COLOR_BIT;
872
875 }
877 return GPU_COLOR_BIT;
878}
879
881{
882 if (format->attr_len == 0) {
883 BLI_assert_msg(0, "Incorrect vertex format for buffer texture");
884 return TextureFormat(0);
885 }
886 return TextureFormat(format->attrs[0].type.format);
887}
888
889} // namespace blender::gpu
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
MINLINE int max_ii(int a, int b)
#define ENUM_OPERATORS(_type, _max)
#define ELEM(...)
GPUFrameBufferBits
@ GPU_DEPTH_BIT
@ GPU_STENCIL_BIT
@ GPU_COLOR_BIT
eGPUDataFormat
@ GPU_DATA_HALF_FLOAT
@ GPU_DATA_INT
@ GPU_DATA_10_11_11_REV
@ GPU_DATA_UBYTE
@ GPU_DATA_UINT
@ GPU_DATA_UINT_24_8_DEPRECATED
@ GPU_DATA_2_10_10_10_REV
@ GPU_DATA_FLOAT
eGPUTextureUsage
BMesh const char void * data
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
virtual void unmap()=0
virtual void * map()=0
virtual ~PixelBuffer()=default
virtual GPUPixelBufferNativeHandle get_native_handle()=0
virtual size_t get_size()=0
virtual void mip_range_set(int min, int max)=0
void attach_to(FrameBuffer *fb, GPUAttachmentType type)
virtual bool init_internal(VertBuf *vbo)=0
int mip_width_get(int mip) const
int mip_depth_get(int mip) const
virtual void * read(int mip, eGPUDataFormat format)=0
bool init_1D(int w, int layers, int mip_len, TextureFormat format)
virtual void generate_mipmap()=0
GPUTextureType type_get() const
GPUTextureFormatFlag format_flag_get() const
void update(eGPUDataFormat format, const void *data)
eGPUTextureUsage gpu_image_usage_flags_
eGPUTextureUsage usage_get() const
bool init_cubemap(int w, int layers, int mip_len, TextureFormat format)
char name_[DEBUG_NAME_LEN]
bool init_view(Texture *src, TextureFormat format, GPUTextureType type, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array, bool use_stencil)
FrameBuffer * fb_[GPU_TEX_MAX_FBO_ATTACHED]
bool init_2D(int w, int h, int layers, int mip_len, TextureFormat format)
virtual bool init_internal(blender::gpu::Texture *src, int mip_offset, int layer_offset, bool use_stencil)=0
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
bool init_3D(int w, int h, int d, int mip_len, TextureFormat format)
GPUAttachmentType fb_attachment_[GPU_TEX_MAX_FBO_ATTACHED]
GPUAttachmentType attachment_type(int slot) const
int mip_height_get(int mip) const
bool init_buffer(VertBuf *vbo, TextureFormat format)
virtual void clear(eGPUDataFormat format, const void *data)=0
virtual bool init_internal()=0
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
TextureFormat format_get() const
virtual void copy_to(Texture *tex)=0
void usage_set(eGPUTextureUsage usage_flags)
Texture(const char *name)
void detach_from(FrameBuffer *fb)
GPUTextureFormatFlag format_flag_
@ 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
int format_component_len(const DataFormat format)
static Context * unwrap(GPUContext *ctx)
bool is_half_float(TextureFormat format)
eGPUDataFormat to_texture_data_format(TextureFormat tex_format)
static GPUContext * wrap(Context *ctx)
size_t to_block_size(TextureFormat data_type)
int to_bytesize(const DataFormat format)
int to_component_len(TextureFormat format)
constexpr bool validate_data_format(TextureFormat tex_format, eGPUDataFormat data_format)
GPUTextureFormatFlag to_format_flag(TextureFormat format)
constexpr TextureFormat to_texture_format(TextureTargetFormat format)
GPUFrameBufferBits to_framebuffer_bits(TextureFormat tex_format)
const char * name
#define min(a, b)
Definition sort.cc:36
static constexpr GPUSamplerState default_sampler()
max
Definition text_draw.cc:251