Blender V5.0
gpu_texture.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_string.h"
10
11#include "GPU_framebuffer.hh"
12#include "GPU_texture.hh"
13
14#include "gpu_backend.hh"
17
19
20namespace blender::gpu {
21
22/* -------------------------------------------------------------------- */
25
27{
28 if (name) {
30 }
31 else {
32 name_[0] = '\0';
33 }
34
35 for (int i = 0; i < ARRAY_SIZE(fb_); i++) {
36 fb_[i] = nullptr;
37 }
38
40}
41
43{
44 for (int i = 0; i < ARRAY_SIZE(fb_); i++) {
45 if (fb_[i] != nullptr) {
46 fb_[i]->attachment_remove(fb_attachment_[i]);
47 }
48 }
49
50#ifndef GPU_NO_USE_PY_REFERENCES
51 if (this->py_ref) {
52 *this->py_ref = nullptr;
53 }
54#endif
55}
56
57bool Texture::init_1D(int w, int layers, int mip_len, TextureFormat format)
58{
59 w_ = w;
60 h_ = layers;
61 d_ = 0;
62 int mip_len_max = 1 + floorf(log2f(w));
63 mipmaps_ = min_ii(mip_len, mip_len_max);
66 type_ = (layers > 0) ? GPU_TEXTURE_1D_ARRAY : GPU_TEXTURE_1D;
69 }
70 return this->init_internal();
71}
72
73bool Texture::init_2D(int w, int h, int layers, int mip_len, TextureFormat format)
74{
75 w_ = w;
76 h_ = h;
77 d_ = layers;
78 int mip_len_max = 1 + floorf(log2f(max_ii(w, h)));
79 mipmaps_ = min_ii(mip_len, mip_len_max);
82 type_ = (layers > 0) ? GPU_TEXTURE_2D_ARRAY : GPU_TEXTURE_2D;
85 }
86 return this->init_internal();
87}
88
89bool Texture::init_3D(int w, int h, int d, int mip_len, TextureFormat format)
90{
91 w_ = w;
92 h_ = h;
93 d_ = d;
94 int mip_len_max = 1 + floorf(log2f(max_iii(w, h, d)));
95 mipmaps_ = min_ii(mip_len, mip_len_max);
101 }
102 return this->init_internal();
103}
104
105bool Texture::init_cubemap(int w, int layers, int mip_len, TextureFormat format)
106{
107 w_ = w;
108 h_ = w;
109 d_ = max_ii(1, layers) * 6;
110 int mip_len_max = 1 + floorf(log2f(w));
111 mipmaps_ = min_ii(mip_len, mip_len_max);
112 format_ = format;
117 }
118 return this->init_internal();
119}
120
122{
123 /* See to_texture_format(). */
125 h_ = 0;
126 d_ = 0;
127 format_ = format;
130 return this->init_internal(vbo);
131}
132
135 GPUTextureType type,
136 int mip_start,
137 int mip_len,
138 int layer_start,
139 int layer_len,
140 bool cube_as_array,
141 bool use_stencil)
142{
143 w_ = src->w_;
144 h_ = src->h_;
145 d_ = src->d_;
146 layer_start = min_ii(layer_start, src->layer_count() - 1);
147 layer_len = min_ii(layer_len, (src->layer_count() - layer_start));
148 switch (type) {
150 h_ = layer_len;
151 break;
153 BLI_assert(layer_len % 6 == 0);
156 d_ = layer_len;
157 break;
158 default:
159 BLI_assert(layer_len == 1 && layer_start == 0);
160 break;
161 }
162 mip_start = min_ii(mip_start, src->mipmaps_ - 1);
163 mip_len = min_ii(mip_len, (src->mipmaps_ - mip_start));
164 mipmaps_ = mip_len;
165 format_ = format;
167 type_ = type;
168 if (cube_as_array) {
171 }
173 return this->init_internal(src, mip_start, layer_start, use_stencil);
174}
175
177{
178 gpu_image_usage_flags_ = usage_flags;
179}
180
182
183/* -------------------------------------------------------------------- */
186
188{
189 for (int i = 0; i < ARRAY_SIZE(fb_); i++) {
190 if (fb_[i] == fb) {
191 /* Already stores a reference */
192 if (fb_attachment_[i] != type) {
193 /* Ensure it's not attached twice to the same FrameBuffer. */
194 fb_[i]->attachment_remove(fb_attachment_[i]);
195 fb_attachment_[i] = type;
196 }
197 return;
198 }
199 }
200 for (int i = 0; i < ARRAY_SIZE(fb_); i++) {
201 if (fb_[i] == nullptr) {
202 fb_attachment_[i] = type;
203 fb_[i] = fb;
204 return;
205 }
206 }
207 BLI_assert_msg(0, "GPU: Error: Texture: Not enough attachment");
208}
209
211{
212 for (int i = 0; i < ARRAY_SIZE(fb_); i++) {
213 if (fb_[i] == fb) {
214 fb_[i]->attachment_remove(fb_attachment_[i]);
215 fb_[i] = nullptr;
216 return;
217 }
218 }
219 BLI_assert_msg(0, "GPU: Error: Texture: Framebuffer is not attached");
220}
221
223{
224 int mip = 0;
225 int extent[3] = {1, 1, 1};
226 int offset[3] = {0, 0, 0};
227 this->mip_size_get(mip, extent);
228 this->update_sub(mip, offset, extent, format, data);
229}
230
232
233} // namespace blender::gpu
234
235/* -------------------------------------------------------------------- */
238
239using namespace blender;
240using namespace blender::gpu;
241
242/* ------ Memory Management ------ */
243
245{
246 /* TODO(fclem): Do that inside the new Texture class. */
247 return 0;
248}
249
250/* ------ Creation ------ */
251
252static inline gpu::Texture *gpu_texture_create(const char *name,
253 const int w,
254 const int h,
255 const int d,
256 const GPUTextureType type,
257 int mip_len,
258 TextureFormat tex_format,
259 eGPUTextureUsage usage,
260 const void *pixels,
261 eGPUDataFormat data_format = GPU_DATA_FLOAT)
262{
263 BLI_assert(mip_len > 0);
265 tex->usage_set(usage);
266
267 bool success = false;
268 switch (type) {
269 case GPU_TEXTURE_1D:
271 success = tex->init_1D(w, h, mip_len, tex_format);
272 break;
273 case GPU_TEXTURE_2D:
275 success = tex->init_2D(w, h, d, mip_len, tex_format);
276 break;
277 case GPU_TEXTURE_3D:
278 success = tex->init_3D(w, h, d, mip_len, tex_format);
279 break;
280 case GPU_TEXTURE_CUBE:
282 success = tex->init_cubemap(w, d, mip_len, tex_format);
283 break;
284 default:
285 break;
286 }
287
288 if (!success) {
289 delete tex;
290 return nullptr;
291 }
292 if (pixels) {
293 tex->update(data_format, pixels);
294 }
295 return reinterpret_cast<gpu::Texture *>(tex);
296}
297
299 int width,
300 int mip_len,
302 eGPUTextureUsage usage,
303 const float *data)
304{
305 return gpu_texture_create(name, width, 0, 0, GPU_TEXTURE_1D, mip_len, format, usage, data);
306}
307
309 int width,
310 int layer_len,
311 int mip_len,
313 eGPUTextureUsage usage,
314 const float *data)
315{
316 return gpu_texture_create(
317 name, width, layer_len, 0, GPU_TEXTURE_1D_ARRAY, mip_len, format, usage, data);
318}
319
321 int width,
322 int height,
323 int mip_len,
325 eGPUTextureUsage usage,
326 const float *data)
327{
328 return gpu_texture_create(name, width, height, 0, GPU_TEXTURE_2D, mip_len, format, usage, data);
329}
330
332 int width,
333 int height,
334 int layer_len,
335 int mip_len,
337 eGPUTextureUsage usage,
338 const float *data)
339{
340 return gpu_texture_create(
341 name, width, height, layer_len, GPU_TEXTURE_2D_ARRAY, mip_len, format, usage, data);
342}
343
345 int width,
346 int height,
347 int depth,
348 int mip_len,
349 TextureFormat texture_format,
350 eGPUTextureUsage usage,
351 const void *data)
352{
353 return gpu_texture_create(
354 name, width, height, depth, GPU_TEXTURE_3D, mip_len, texture_format, usage, data);
355}
356
358 int width,
359 int mip_len,
361 eGPUTextureUsage usage,
362 const float *data)
363{
364 return gpu_texture_create(name, width, width, 0, GPU_TEXTURE_CUBE, mip_len, format, usage, data);
365}
366
368 int width,
369 int layer_len,
370 int mip_len,
372 eGPUTextureUsage usage,
373 const float *data)
374{
375 return gpu_texture_create(
376 name, width, width, layer_len, GPU_TEXTURE_CUBE_ARRAY, mip_len, format, usage, data);
377}
378
380 int width,
381 int height,
382 int mip_len,
383 TextureFormat tex_format,
384 eGPUTextureUsage usage,
385 const void *data)
386{
388 tex->usage_set(usage);
389 bool success = tex->init_2D(width, height, 0, mip_len, tex_format);
390
391 if (!success) {
392 delete tex;
393 return nullptr;
394 }
395 if (data) {
396 size_t ofs = 0;
397 for (int mip = 0; mip < mip_len; mip++) {
398 int extent[3], offset[3] = {0, 0, 0};
399 tex->mip_size_get(mip, extent);
400
401 size_t size = ((extent[0] + 3) / 4) * ((extent[1] + 3) / 4) * to_block_size(tex_format);
402 tex->update_sub(
403 mip, offset, extent, to_texture_data_format(tex_format), (uchar *)data + ofs);
404
405 ofs += size;
406 }
407 }
408 return reinterpret_cast<gpu::Texture *>(tex);
409}
410
412{
413#ifndef NDEBUG
414 /* Vertex buffers used for texture buffers must be flagged with:
415 * GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY. */
417 "Vertex Buffers used for textures should have usage flag "
418 "GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY.");
419#endif
422
423 bool success = tex->init_buffer(vert, tex_format);
424 if (!success) {
425 delete tex;
426 return nullptr;
427 }
428 return reinterpret_cast<gpu::Texture *>(tex);
429}
430
431gpu::Texture *GPU_texture_create_error(int dimension, bool is_array)
432{
433 const float pixel[4] = {1.0f, 0.0f, 1.0f, 1.0f};
434 int w = 1;
435 int h = (dimension < 2 && !is_array) ? 0 : 1;
436 int d = (dimension < 3 && !is_array) ? 0 : 1;
437
439 type = (dimension == 2) ? (is_array ? GPU_TEXTURE_2D_ARRAY : GPU_TEXTURE_2D) : type;
440 type = (dimension == 1) ? (is_array ? GPU_TEXTURE_1D_ARRAY : GPU_TEXTURE_1D) : type;
441
442 return gpu_texture_create("invalid_tex",
443 w,
444 h,
445 d,
446 type,
447 1,
448 TextureFormat::UNORM_8_8_8_8,
450 pixel);
451}
452
454 gpu::Texture *source_texture,
455 TextureFormat view_format,
456 int mip_start,
457 int mip_len,
458 int layer_start,
459 int layer_len,
460 bool cube_as_array,
461 bool use_stencil)
462{
463 BLI_assert(mip_len > 0);
464 BLI_assert(layer_len > 0);
465 BLI_assert_msg(use_stencil == false ||
467 "Source texture of TextureView must have GPU_TEXTURE_USAGE_FORMAT_VIEW usage "
468 "flag if view texture uses stencil texturing.");
469 BLI_assert_msg((view_format == GPU_texture_format(source_texture)) ||
471 "Source texture of TextureView must have GPU_TEXTURE_USAGE_FORMAT_VIEW usage "
472 "flag if view texture format is different.");
474 view->init_view(source_texture,
475 view_format,
476 source_texture->type_get(),
477 mip_start,
478 mip_len,
479 layer_start,
480 layer_len,
481 cube_as_array,
482 use_stencil);
483 return view;
484}
485
486/* ------ Usage ------ */
488{
489 const Texture *tex = reinterpret_cast<const Texture *>(texture_);
490 return tex->usage_get();
491}
492
493/* ------ Update ------ */
494
496 int mip_level,
497 eGPUDataFormat data_format,
498 const void *pixels)
499{
500 int extent[3] = {1, 1, 1}, offset[3] = {0, 0, 0};
501 texture->mip_size_get(mip_level, extent);
502 texture->update_sub(mip_level, offset, extent, data_format, pixels);
503}
504
506 eGPUDataFormat data_format,
507 const void *pixels,
508 int offset_x,
509 int offset_y,
510 int offset_z,
511 int width,
512 int height,
513 int depth)
514{
515 int offset[3] = {offset_x, offset_y, offset_z};
516 int extent[3] = {width, height, depth};
517 tex->update_sub(0, offset, extent, data_format, pixels);
518}
519
521 eGPUDataFormat data_format,
522 GPUPixelBuffer *pixel_buf,
523 int offset_x,
524 int offset_y,
525 int offset_z,
526 int width,
527 int height,
528 int depth)
529{
530 int offset[3] = {offset_x, offset_y, offset_z};
531 int extent[3] = {width, height, depth};
532 texture->update_sub(offset, extent, data_format, pixel_buf);
533}
534
535void *GPU_texture_read(gpu::Texture *texture, eGPUDataFormat data_format, int mip_level)
536{
539 "The host-read usage flag must be specified up-front. Only textures which require data "
540 "reads should be flagged, allowing the backend to make certain optimizations.");
541 return texture->read(mip_level, data_format);
542}
543
544void GPU_texture_clear(gpu::Texture *tex, eGPUDataFormat data_format, const void *data)
545{
546 BLI_assert(data != nullptr); /* Do not accept nullptr as parameter. */
547 tex->clear(data_format, data);
548}
549
550void GPU_texture_update(gpu::Texture *tex, eGPUDataFormat data_format, const void *data)
551{
552 tex->update(data_format, data);
553}
554
559
560/* ------ Binding ------ */
561
568
570{
571 Texture *tex = texture;
573}
574
580
585
587{
589}
590
595
600
605
607{
608 Texture *src = src_;
609 Texture *dst = dst_;
610 src->copy_to(dst);
611}
612
614{
615 Texture *tex = texture;
616 /* Only depth formats does support compare mode. */
617 BLI_assert(!(use_compare) || (tex->format_flag_get() & GPU_FORMAT_DEPTH));
618
622}
623
625{
626 Texture *tex = texture;
627 /* Stencil and integer format does not support filtering. */
628 BLI_assert(!(use_filter) ||
631}
632
633void GPU_texture_mipmap_mode(gpu::Texture *texture, bool use_mipmap, bool use_filter)
634{
635 Texture *tex = texture;
636 /* Stencil and integer format does not support filtering. */
637 BLI_assert(!(use_filter || use_mipmap) ||
641}
642
644{
645 Texture *tex = texture;
646 /* Stencil and integer format does not support filtering. */
647 BLI_assert(!(use_aniso) ||
650}
651
653{
654 texture->sampler_state.extend_x = extend_mode;
655}
656
658{
659 texture->sampler_state.extend_yz = extend_mode;
660}
661
663{
664 texture->sampler_state.extend_x = extend_mode;
665 texture->sampler_state.extend_yz = extend_mode;
666}
667
668void GPU_texture_swizzle_set(gpu::Texture *texture, const char swizzle[4])
669{
670 texture->swizzle_set(swizzle);
671}
672
674{
675 Texture *tex = texture;
676 tex->refcount--;
677
678 if (tex->refcount < 0) {
679 fprintf(stderr, "gpu::Texture: negative refcount\n");
680 }
681
682 if (tex->refcount == 0) {
683 delete tex;
684 }
685}
686
688{
689 texture->refcount++;
690}
691
693{
694 GPUTextureType type = texture->type_get();
695 if (type & GPU_TEXTURE_1D) {
696 return 1;
697 }
698 if (type & GPU_TEXTURE_2D) {
699 return 2;
700 }
701 if (type & GPU_TEXTURE_3D) {
702 return 3;
703 }
704 if (type & GPU_TEXTURE_CUBE) {
705 return 2;
706 }
707 /* GPU_TEXTURE_BUFFER */
708 return 1;
709}
710
712{
713 return texture->width_get();
714}
715
717{
718 return texture->height_get();
719}
720
722{
723 return texture->depth_get();
724}
725
727{
728 return texture->layer_count();
729}
730
732{
733 return texture->mip_count();
734}
735
737{
738 return texture->src_w;
739}
740
742{
743 return texture->src_h;
744}
745
747{
748 texture->src_w = w;
749 texture->src_h = h;
750}
751
753{
754 return texture->format_get();
755}
756
757const char *GPU_texture_format_name(TextureFormat texture_format)
758{
759 switch (texture_format) {
760 /* Formats texture & render-buffer */
761 case TextureFormat::UINT_8_8_8_8:
762 return "RGBA8UI";
763 case TextureFormat::SINT_8_8_8_8:
764 return "RGBA8I";
765 case TextureFormat::UNORM_8_8_8_8:
766 return "RGBA8";
767 case TextureFormat::UINT_32_32_32_32:
768 return "RGBA32UI";
769 case TextureFormat::SINT_32_32_32_32:
770 return "RGBA32I";
771 case TextureFormat::SFLOAT_32_32_32_32:
772 return "RGBA32F";
773 case TextureFormat::UINT_16_16_16_16:
774 return "RGBA16UI";
775 case TextureFormat::SINT_16_16_16_16:
776 return "RGBA16I";
777 case TextureFormat::SFLOAT_16_16_16_16:
778 return "RGBA16F";
779 case TextureFormat::UNORM_16_16_16_16:
780 return "RGBA16";
781 case TextureFormat::UINT_8_8:
782 return "RG8UI";
783 case TextureFormat::SINT_8_8:
784 return "RG8I";
785 case TextureFormat::UNORM_8_8:
786 return "RG8";
787 case TextureFormat::UINT_32_32:
788 return "RG32UI";
789 case TextureFormat::SINT_32_32:
790 return "RG32I";
791 case TextureFormat::SFLOAT_32_32:
792 return "RG32F";
793 case TextureFormat::UINT_16_16:
794 return "RG16UI";
795 case TextureFormat::SINT_16_16:
796 return "RG16I";
797 case TextureFormat::SFLOAT_16_16:
798 return "RG16F";
799 case TextureFormat::UNORM_16_16:
800 return "RG16";
801 case TextureFormat::UINT_8:
802 return "R8UI";
803 case TextureFormat::SINT_8:
804 return "R8I";
805 case TextureFormat::UNORM_8:
806 return "R8";
807 case TextureFormat::UINT_32:
808 return "R32UI";
809 case TextureFormat::SINT_32:
810 return "R32I";
811 case TextureFormat::SFLOAT_32:
812 return "R32F";
813 case TextureFormat::UINT_16:
814 return "R16UI";
815 case TextureFormat::SINT_16:
816 return "R16I";
817 case TextureFormat::SFLOAT_16:
818 return "R16F";
819 case TextureFormat::UNORM_16:
820 return "R16";
821 /* Special formats texture & render-buffer */
822 case TextureFormat::UNORM_10_10_10_2:
823 return "RGB10_A2";
824 case TextureFormat::UINT_10_10_10_2:
825 return "RGB10_A2UI";
826 case TextureFormat::UFLOAT_11_11_10:
827 return "R11F_G11F_B10F";
828 case TextureFormat::SFLOAT_32_DEPTH_UINT_8:
829 return "DEPTH32F_STENCIL8";
830 case TextureFormat::SRGBA_8_8_8_8:
831 return "SRGB8_A8";
832 /* Texture only formats. */
833 case TextureFormat::SFLOAT_16_16_16:
834 return "RGB16F";
835 case TextureFormat::SNORM_16_16_16:
836 return "RGB16_SNORM";
837 case TextureFormat::SINT_16_16_16:
838 return "RGB16I";
839 case TextureFormat::UINT_16_16_16:
840 return "RGB16UI";
841 case TextureFormat::UNORM_16_16_16:
842 return "RGB16";
843 case TextureFormat::SNORM_16_16_16_16:
844 return "RGBA16_SNORM";
845 case TextureFormat::SNORM_8_8_8_8:
846 return "RGBA8_SNORM";
847 case TextureFormat::SFLOAT_32_32_32:
848 return "RGB32F";
849 case TextureFormat::SINT_32_32_32:
850 return "RGB32I";
851 case TextureFormat::UINT_32_32_32:
852 return "RGB32UI";
853 case TextureFormat::SNORM_8_8_8:
854 return "RGB8_SNORM";
855 case TextureFormat::UNORM_8_8_8:
856 return "RGB8";
857 case TextureFormat::SINT_8_8_8:
858 return "RGB8I";
859 case TextureFormat::UINT_8_8_8:
860 return "RGB8UI";
861 case TextureFormat::SNORM_16_16:
862 return "RG16_SNORM";
863 case TextureFormat::SNORM_8_8:
864 return "RG8_SNORM";
865 case TextureFormat::SNORM_16:
866 return "R16_SNORM";
867 case TextureFormat::SNORM_8:
868 return "R8_SNORM";
869 /* Special formats, texture only. */
870 case TextureFormat::SRGB_DXT1:
871 return "SRGB8_A8_DXT1";
872 case TextureFormat::SRGB_DXT3:
873 return "SRGB8_A8_DXT3";
874 case TextureFormat::SRGB_DXT5:
875 return "SRGB8_A8_DXT5";
876 case TextureFormat::SNORM_DXT1:
877 return "RGBA8_DXT1";
878 case TextureFormat::SNORM_DXT3:
879 return "RGBA8_DXT3";
880 case TextureFormat::SNORM_DXT5:
881 return "RGBA8_DXT5";
882 case TextureFormat::SRGBA_8_8_8:
883 return "SRGB8";
884 case TextureFormat::UFLOAT_9_9_9_EXP_5:
885 return "RGB9_E5";
886 /* Depth Formats. */
887 case TextureFormat::SFLOAT_32_DEPTH:
888 return "DEPTH_COMPONENT32F";
889 case TextureFormat::UNORM_16_DEPTH:
890 return "DEPTH_COMPONENT16";
891
894 return "Invalid";
895 }
897 return "";
898}
899
901{
902 return (texture->format_flag_get() & GPU_FORMAT_DEPTH) != 0;
903}
904
906{
907 return (texture->format_flag_get() & GPU_FORMAT_STENCIL) != 0;
908}
909
911{
912 return (texture->format_flag_get() & GPU_FORMAT_INTEGER) != 0;
913}
914
916{
917 return (texture->format_flag_get() & GPU_FORMAT_FLOAT) != 0;
918}
919
921{
922 return (texture->format_flag_get() & GPU_FORMAT_NORMALIZED_INTEGER) != 0;
923}
924
926{
927 return (texture->format_flag_get() & GPU_FORMAT_SIGNED) != 0;
928}
929
931{
932 return (texture->type_get() & GPU_TEXTURE_CUBE) != 0;
933}
934
936{
937 return (texture->type_get() & GPU_TEXTURE_ARRAY) != 0;
938}
939
940#ifndef GPU_NO_USE_PY_REFERENCES
942{
943 return texture->py_ref;
944}
945
947{
948 BLI_assert(py_ref == nullptr || texture->py_ref == nullptr);
949 texture->py_ref = py_ref;
950}
951#endif
952
953void GPU_texture_get_mipmap_size(gpu::Texture *texture, int mip_level, int *r_size)
954{
955 texture->mip_size_get(mip_level, r_size);
956}
957
959
960/* -------------------------------------------------------------------- */
965
966GPUPixelBuffer *GPU_pixel_buffer_create(size_t size)
967{
968 /* Ensure buffer satisfies the alignment of 256 bytes for copying
969 * data between buffers and textures. As specified in:
970 * https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
971 *
972 * Ensuring minimal size across all platforms handles cases for small-sized
973 * textures and avoids issues with zero-sized buffers. */
976 return wrap(pixbuf);
977}
978
979void GPU_pixel_buffer_free(GPUPixelBuffer *pixel_buf)
980{
981 PixelBuffer *handle = unwrap(pixel_buf);
982 delete handle;
983}
984
985void *GPU_pixel_buffer_map(GPUPixelBuffer *pixel_buf)
986{
987 return unwrap(pixel_buf)->map();
988}
989
990void GPU_pixel_buffer_unmap(GPUPixelBuffer *pixel_buf)
991{
992 unwrap(pixel_buf)->unmap();
993}
994
995size_t GPU_pixel_buffer_size(GPUPixelBuffer *pixel_buf)
996{
997 return unwrap(pixel_buf)->get_size();
998}
999
1001{
1002 return unwrap(pixel_buf)->get_native_handle();
1003}
1004
1006
1007/* -------------------------------------------------------------------- */
1013
1015{
1016 /* Backend may not exist when we are updating preferences from background mode. */
1017 GPUBackend *backend = GPUBackend::get();
1018 if (backend) {
1019 backend->samplers_update();
1020 }
1021}
1022
1024
1025/* -------------------------------------------------------------------- */
1028
1030{
1031 return to_component_len(tex_format);
1032}
1033
1035{
1036 return to_bytesize(data_format);
1037}
1038
#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
#define ATTR_FALLTHROUGH
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
MINLINE int max_iii(int a, int b, int c)
MINLINE uint64_t ceil_to_multiple_ul(uint64_t a, uint64_t b)
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:693
unsigned char uchar
unsigned int uint
#define ARRAY_SIZE(arr)
static AppView * view
@ GPU_SAMPLER_CUSTOM_COMPARE
void GPU_texture_extend_mode_y(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
int GPU_texture_mip_count(const blender::gpu::Texture *texture)
void GPU_texture_swizzle_set(blender::gpu::Texture *texture, const char swizzle[4])
void GPU_texture_clear(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
void GPU_texture_update_sub(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
int GPU_texture_original_height(const blender::gpu::Texture *texture)
void GPU_pixel_buffer_unmap(GPUPixelBuffer *pixel_buf)
void GPU_texture_extend_mode_x(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
void GPU_texture_copy(blender::gpu::Texture *dst, blender::gpu::Texture *src)
blender::gpu::Texture * GPU_texture_create_view(const char *name, blender::gpu::Texture *source_texture, blender::gpu::TextureFormat view_format, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array, bool use_stencil)
blender::gpu::Texture * GPU_texture_create_2d_array(const char *name, int width, int height, int layer_len, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_get_mipmap_size(blender::gpu::Texture *texture, int mip_level, int *r_size)
void GPU_texture_update_sub_from_pixel_buffer(blender::gpu::Texture *texture, eGPUDataFormat data_format, GPUPixelBuffer *pixel_buf, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
size_t GPU_texture_component_len(blender::gpu::TextureFormat format)
size_t GPU_texture_dataformat_size(eGPUDataFormat data_format)
void ** GPU_texture_py_reference_get(blender::gpu::Texture *texture)
void GPU_texture_image_unbind_all()
GPUPixelBufferNativeHandle GPU_pixel_buffer_get_native_handle(GPUPixelBuffer *pixel_buf)
int GPU_texture_height(const blender::gpu::Texture *texture)
void GPU_texture_anisotropic_filter(blender::gpu::Texture *texture, bool use_aniso)
blender::gpu::Texture * GPU_texture_create_cube(const char *name, int width, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
size_t GPU_pixel_buffer_size(GPUPixelBuffer *pixel_buf)
void GPU_texture_update_mipmap(blender::gpu::Texture *texture, int mip_level, eGPUDataFormat data_format, const void *pixels)
blender::gpu::Texture * GPU_texture_create_compressed_2d(const char *name, int width, int height, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const void *data)
bool GPU_texture_has_integer_format(const blender::gpu::Texture *texture)
bool GPU_texture_has_depth_format(const blender::gpu::Texture *texture)
@ GPU_SAMPLER_STATE_TYPE_CUSTOM
@ GPU_SAMPLER_STATE_TYPE_PARAMETERS
@ GPU_SAMPLER_STATE_TYPE_INTERNAL
blender::gpu::Texture * GPU_texture_create_1d_array(const char *name, int width, int layer_len, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void * GPU_pixel_buffer_map(GPUPixelBuffer *pixel_buf)
void GPU_texture_update_mipmap_chain(blender::gpu::Texture *texture)
blender::gpu::TextureFormat GPU_texture_format(const blender::gpu::Texture *texture)
int GPU_texture_original_width(const blender::gpu::Texture *texture)
void GPU_texture_unbind(blender::gpu::Texture *texture)
void GPU_pixel_buffer_free(GPUPixelBuffer *pixel_buf)
bool GPU_texture_has_stencil_format(const blender::gpu::Texture *texture)
int GPU_texture_width(const blender::gpu::Texture *texture)
eGPUDataFormat
@ GPU_DATA_FLOAT
void GPU_texture_bind_ex(blender::gpu::Texture *texture, GPUSamplerState state, int unit)
bool GPU_texture_has_signed_format(const blender::gpu::Texture *texture)
void GPU_texture_original_size_set(blender::gpu::Texture *texture, int width, int height)
void GPU_texture_extend_mode(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
blender::gpu::Texture * GPU_texture_create_cube_array(const char *name, int width, int layer_len, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_mipmap_mode(blender::gpu::Texture *texture, bool use_mipmap, bool use_filter)
void GPU_texture_ref(blender::gpu::Texture *texture)
eGPUTextureUsage
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_GENERAL
@ GPU_TEXTURE_USAGE_FORMAT_VIEW
GPUSamplerExtendMode
void * GPU_texture_read(blender::gpu::Texture *texture, eGPUDataFormat data_format, int mip_level)
void GPU_texture_image_bind(blender::gpu::Texture *texture, int unit)
bool GPU_texture_is_cube(const blender::gpu::Texture *texture)
eGPUTextureUsage GPU_texture_usage(const blender::gpu::Texture *texture)
void GPU_texture_py_reference_set(blender::gpu::Texture *texture, void **py_ref)
bool GPU_texture_has_float_format(const blender::gpu::Texture *texture)
void GPU_texture_image_unbind(blender::gpu::Texture *texture)
blender::gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
int GPU_texture_dimensions(const blender::gpu::Texture *texture)
void GPU_texture_unbind_all()
void GPU_texture_compare_mode(blender::gpu::Texture *texture, bool use_compare)
blender::gpu::Texture * GPU_texture_create_from_vertbuf(const char *name, blender::gpu::VertBuf *vertex_buf)
void GPU_texture_filter_mode(blender::gpu::Texture *texture, bool use_filter)
GPUPixelBuffer * GPU_pixel_buffer_create(size_t byte_size)
void GPU_unpack_row_length_set(uint len)
@ GPU_SAMPLER_FILTERING_MIPMAP
@ GPU_SAMPLER_FILTERING_ANISOTROPIC
@ GPU_SAMPLER_FILTERING_LINEAR
const char * GPU_texture_format_name(blender::gpu::TextureFormat format)
int GPU_texture_layer_count(const blender::gpu::Texture *texture)
void GPU_samplers_update()
void GPU_texture_bind(blender::gpu::Texture *texture, int unit)
blender::gpu::Texture * GPU_texture_create_error(int dimension, bool array)
int GPU_texture_depth(const blender::gpu::Texture *texture)
bool GPU_texture_has_normalized_format(const blender::gpu::Texture *texture)
void GPU_texture_free(blender::gpu::Texture *texture)
blender::gpu::Texture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const void *data)
blender::gpu::Texture * GPU_texture_create_1d(const char *name, int width, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_update(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
unsigned int GPU_texture_memory_usage_get()
bool GPU_texture_is_array(const blender::gpu::Texture *texture)
const GPUVertFormat * GPU_vertbuf_get_format(const blender::gpu::VertBuf *verts)
uint GPU_vertbuf_get_vertex_len(const blender::gpu::VertBuf *verts)
@ GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY
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
static Context * get()
static GPUBackend * get()
virtual void samplers_update()=0
virtual PixelBuffer * pixelbuf_alloc(size_t size)=0
virtual Texture * texture_alloc(const char *name)=0
virtual void texture_unbind_all()=0
virtual void texture_unbind(Texture *tex)=0
virtual void image_unbind_all()=0
virtual void image_unbind(Texture *tex)=0
virtual void image_bind(Texture *tex, int unit)=0
virtual void texture_bind(Texture *tex, GPUSamplerState sampler, int unit)=0
virtual void texture_unpack_row_length_set(uint len)=0
void attach_to(FrameBuffer *fb, GPUAttachmentType type)
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)
bool init_3D(int w, int h, int d, int mip_len, TextureFormat format)
GPUAttachmentType fb_attachment_[GPU_TEX_MAX_FBO_ATTACHED]
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
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_
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
static gpu::Texture * gpu_texture_create(const char *name, const int w, const int h, const int d, const GPUTextureType type, int mip_len, TextureFormat tex_format, eGPUTextureUsage usage, const void *pixels, eGPUDataFormat data_format=GPU_DATA_FLOAT)
BLI_INLINE float fb(float length, float L)
format
static ulong state[N]
static Context * unwrap(GPUContext *ctx)
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)
GPUTextureFormatFlag to_format_flag(TextureFormat format)
constexpr TextureFormat to_texture_format(TextureTargetFormat format)
const char * name
#define floorf
GPUSamplerCustomType custom_type
GPUSamplerStateType type
void set_filtering_flag_from_test(GPUSamplerFiltering filtering_flags, bool test)
i
Definition text_draw.cc:230
uint len