Blender V4.3
GPU_texture.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
13#pragma once
14
15#include <string>
16
17#include "BLI_assert.h"
18#include "BLI_utildefines.h"
19
20#include "GPU_state.hh"
21
22namespace blender::gpu {
23class VertBuf;
24}
25
26/* -------------------------------------------------------------------- */
65
67
68
72 1;
73
94
95#define GPU_SAMPLER_EXTEND_MODES_COUNT (GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER + 1)
96
131
132#define GPU_SAMPLER_CUSTOM_TYPES_COUNT (GPU_SAMPLER_CUSTOM_ICON + 1)
133
159
192
209
226
242
260
265 {
266 this->filtering = this->filtering | filtering_flags;
267 }
268
273 {
274 this->filtering = this->filtering & ~filtering_flags;
275 }
276
281 void set_filtering_flag_from_test(GPUSamplerFiltering filtering_flags, bool test)
282 {
283 if (test) {
284 this->enable_filtering_flag(filtering_flags);
285 }
286 else {
287 this->disable_filtering_flag(filtering_flags);
288 }
289 }
290
291 std::string to_string() const
292 {
293 if (this->type == GPU_SAMPLER_STATE_TYPE_INTERNAL) {
294 return "internal";
295 }
296
297 if (this->type == GPU_SAMPLER_STATE_TYPE_CUSTOM) {
298 switch (this->custom_type) {
300 return "compare";
301 break;
303 return "icon";
304 break;
305 default:
307 return "";
308 }
309 }
310
311 /* The sampler state is of type PARAMETERS, so serialize the parameters. */
313 std::string serialized_parameters;
314
316 serialized_parameters += "linear-filter_";
317 }
318
320 serialized_parameters += "mipmap_";
321 }
322
324 serialized_parameters += "anisotropic_";
325 }
326
327 switch (this->extend_x) {
329 serialized_parameters += "extend-x_";
330 break;
332 serialized_parameters += "repeat-x_";
333 break;
335 serialized_parameters += "mirrored-repeat-x_";
336 break;
338 serialized_parameters += "clamp-to-border-x_";
339 break;
340 default:
342 }
343
344 switch (this->extend_yz) {
346 serialized_parameters += "extend-y_";
347 break;
349 serialized_parameters += "repeat-y_";
350 break;
352 serialized_parameters += "mirrored-repeat-y_";
353 break;
355 serialized_parameters += "clamp-to-border-y_";
356 break;
357 default:
359 }
360
361 switch (this->extend_yz) {
363 serialized_parameters += "extend-z";
364 break;
366 serialized_parameters += "repeat-z";
367 break;
369 serialized_parameters += "mirrored-repeat-z";
370 break;
372 serialized_parameters += "clamp-to-border-z";
373 break;
374 default:
376 }
377
378 return serialized_parameters;
379 }
380
381 bool operator==(GPUSamplerState const &rhs) const
382 {
383 return this->filtering == rhs.filtering && this->extend_x == rhs.extend_x &&
384 this->extend_yz == rhs.extend_yz && this->custom_type == rhs.custom_type &&
385 this->type == rhs.type;
386 }
387};
388
391/* -------------------------------------------------------------------- */
400 /* Formats texture & render-buffer. */
401
412
423
434
435 /* Special formats texture & render-buffer. */
436
443
444 /* Texture only formats. */
445
448
461
464
467
468 /* Special formats, texture only. */
472 GPU_RGBA8_DXT1, /* BC1 */
473 GPU_RGBA8_DXT3, /* BC2 */
474 GPU_RGBA8_DXT5, /* BC3 */
477#if 0 /* TODO: Add support for them. */
478 GPU_COMPRESSED_RG_RGTC2,
479 GPU_COMPRESSED_SIGNED_RG_RGTC2,
480 GPU_COMPRESSED_RED_RGTC1,
481 GPU_COMPRESSED_SIGNED_RED_RGTC1,
482#endif
483
484 /* Depth Formats. */
488};
489
508
521 /* Whether texture is sampled or read during a shader. */
523 /* Whether the texture is written to by a shader using imageStore. */
525 /* Whether a texture is used as an attachment in a frame-buffer. */
527 /* Whether a texture is used to create a texture view utilizing a different texture format to the
528 * source textures format. This includes the use of stencil views. */
530 /* Whether the texture needs to be read from by the CPU. */
532 /* When used, the texture will not have any backing storage and can solely exist as a virtual
533 * frame-buffer attachment. */
535 /* Whether a texture can support atomic operations. */
537 /* Create a texture whose usage cannot be defined prematurely.
538 * This is unoptimized and should not be used. */
541};
542
544
547/* -------------------------------------------------------------------- */
552struct GPUTexture;
553
564GPUTexture *GPU_texture_create_1d(const char *name,
565 int width,
566 int mip_len,
568 eGPUTextureUsage usage,
569 const float *data);
570GPUTexture *GPU_texture_create_1d_array(const char *name,
571 int width,
572 int layer_len,
573 int mip_len,
575 eGPUTextureUsage usage,
576 const float *data);
577GPUTexture *GPU_texture_create_2d(const char *name,
578 int width,
579 int height,
580 int mip_len,
582 eGPUTextureUsage usage,
583 const float *data);
584GPUTexture *GPU_texture_create_2d_array(const char *name,
585 int width,
586 int height,
587 int layer_len,
588 int mip_len,
590 eGPUTextureUsage usage,
591 const float *data);
592GPUTexture *GPU_texture_create_3d(const char *name,
593 int width,
594 int height,
595 int depth,
596 int mip_len,
598 eGPUTextureUsage usage,
599 const void *data);
600GPUTexture *GPU_texture_create_cube(const char *name,
601 int width,
602 int mip_len,
604 eGPUTextureUsage usage,
605 const float *data);
606GPUTexture *GPU_texture_create_cube_array(const char *name,
607 int width,
608 int layer_len,
609 int mip_len,
611 eGPUTextureUsage usage,
612 const float *data);
618GPUTexture *GPU_texture_create_compressed_2d(const char *name,
619 int width,
620 int height,
621 int mip_len,
623 eGPUTextureUsage usage,
624 const void *data);
625
630GPUTexture *GPU_texture_create_from_vertbuf(const char *name, blender::gpu::VertBuf *vertex_buf);
631
637GPUTexture *GPU_texture_create_error(int dimension, bool array);
638
641/* -------------------------------------------------------------------- */
651void GPU_texture_ref(GPUTexture *texture);
652
657void GPU_texture_free(GPUTexture *texture);
658
659#define GPU_TEXTURE_FREE_SAFE(texture) \
660 do { \
661 if (texture != nullptr) { \
662 GPU_texture_free(texture); \
663 texture = nullptr; \
664 } \
665 } while (0)
666
669/* -------------------------------------------------------------------- */
697GPUTexture *GPU_texture_create_view(const char *name,
698 GPUTexture *source_texture,
699 eGPUTextureFormat view_format,
700 int mip_start,
701 int mip_len,
702 int layer_start,
703 int layer_len,
704 bool cube_as_array,
705 bool use_stencil);
706
709/* -------------------------------------------------------------------- */
721
730void GPU_texture_update(GPUTexture *texture, eGPUDataFormat data_format, const void *data);
731
743void GPU_texture_update_sub(GPUTexture *texture,
744 eGPUDataFormat data_format,
745 const void *pixels,
746 int offset_x,
747 int offset_y,
748 int offset_z,
749 int width,
750 int height,
751 int depth);
752
759void GPU_texture_update_mipmap(GPUTexture *texture,
760 int mip_level,
761 eGPUDataFormat data_format,
762 const void *pixels);
763
772void GPU_texture_clear(GPUTexture *texture, eGPUDataFormat data_format, const void *data);
773
778void GPU_texture_copy(GPUTexture *dst, GPUTexture *src);
779
784void GPU_texture_update_mipmap_chain(GPUTexture *texture);
785
792void *GPU_texture_read(GPUTexture *texture, eGPUDataFormat data_format, int mip_level);
793
796/* -------------------------------------------------------------------- */
803void GPU_texture_bind(GPUTexture *texture, int unit);
807void GPU_texture_bind_ex(GPUTexture *texture, GPUSamplerState state, int unit);
812void GPU_texture_unbind(GPUTexture *texture);
817
823void GPU_texture_image_bind(GPUTexture *texture, int unit);
828void GPU_texture_image_unbind(GPUTexture *texture);
833
836/* -------------------------------------------------------------------- */
843void GPU_texture_compare_mode(GPUTexture *texture, bool use_compare);
844
851void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter);
852
860void GPU_texture_mipmap_mode(GPUTexture *texture, bool use_mipmap, bool use_filter);
861
866void GPU_texture_anisotropic_filter(GPUTexture *texture, bool use_aniso);
867
872void GPU_texture_extend_mode_x(GPUTexture *texture, GPUSamplerExtendMode extend_mode);
873
878void GPU_texture_extend_mode_y(GPUTexture *texture, GPUSamplerExtendMode extend_mode);
879
884void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode);
885
902void GPU_texture_swizzle_set(GPUTexture *texture, const char swizzle[4]);
903
906/* -------------------------------------------------------------------- */
914int GPU_texture_dimensions(const GPUTexture *texture);
915
919int GPU_texture_width(const GPUTexture *texture);
920
924int GPU_texture_height(const GPUTexture *texture);
925
930int GPU_texture_depth(const GPUTexture *texture);
931
935int GPU_texture_layer_count(const GPUTexture *texture);
936
940int GPU_texture_mip_count(const GPUTexture *texture);
941
945eGPUTextureFormat GPU_texture_format(const GPUTexture *texture);
946
950eGPUTextureUsage GPU_texture_usage(const GPUTexture *texture);
951
955bool GPU_texture_is_array(const GPUTexture *texture);
956
960bool GPU_texture_is_cube(const GPUTexture *texture);
961
965bool GPU_texture_has_depth_format(const GPUTexture *texture);
966
970bool GPU_texture_has_stencil_format(const GPUTexture *texture);
971
975bool GPU_texture_has_integer_format(const GPUTexture *texture);
976
980bool GPU_texture_has_float_format(const GPUTexture *tex);
981
985bool GPU_texture_has_normalized_format(const GPUTexture *tex);
986
990bool GPU_texture_has_signed_format(const GPUTexture *tex);
991
997void GPU_texture_get_mipmap_size(GPUTexture *texture, int mip_level, int *r_size);
998
1001/* -------------------------------------------------------------------- */
1013int GPU_texture_original_width(const GPUTexture *texture);
1014int GPU_texture_original_height(const GPUTexture *texture);
1015void GPU_texture_original_size_set(GPUTexture *texture, int width, int height);
1016
1021#ifndef GPU_NO_USE_PY_REFERENCES
1022void **GPU_texture_py_reference_get(GPUTexture *texture);
1023void GPU_texture_py_reference_set(GPUTexture *texture, void **py_ref);
1024#endif
1025
1031int GPU_texture_opengl_bindcode(const GPUTexture *texture);
1032
1035/* -------------------------------------------------------------------- */
1043
1048
1054
1060unsigned int GPU_texture_memory_usage_get();
1061
1065void GPU_samplers_update();
1066
1069/* -------------------------------------------------------------------- */
1077struct GPUPixelBuffer;
1078
1082GPUPixelBuffer *GPU_pixel_buffer_create(size_t byte_size);
1083
1088void GPU_pixel_buffer_free(GPUPixelBuffer *pixel_buf);
1089
1096void *GPU_pixel_buffer_map(GPUPixelBuffer *pixel_buf);
1097
1102void GPU_pixel_buffer_unmap(GPUPixelBuffer *pixel_buf);
1103
1107size_t GPU_pixel_buffer_size(GPUPixelBuffer *pixel_buf);
1108
1112int64_t GPU_pixel_buffer_get_native_handle(GPUPixelBuffer *pixel_buf);
1113
1119void GPU_texture_update_sub_from_pixel_buffer(GPUTexture *texture,
1120 eGPUDataFormat data_format,
1121 GPUPixelBuffer *pixel_buf,
1122 int offset_x,
1123 int offset_y,
1124 int offset_z,
1125 int width,
1126 int height,
1127 int depth);
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
#define BLI_assert(a)
Definition BLI_assert.h:50
unsigned int uint
#define ENUM_OPERATORS(_type, _max)
GPUSamplerCustomType
@ GPU_SAMPLER_CUSTOM_ICON
@ GPU_SAMPLER_CUSTOM_COMPARE
int GPU_texture_height(const GPUTexture *texture)
GPUTexture * GPU_texture_create_compressed_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const void *data)
void GPU_texture_bind(GPUTexture *texture, int unit)
int GPU_texture_original_height(const GPUTexture *texture)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_extend_mode_y(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
GPUTexture * GPU_texture_create_1d(const char *name, int width, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
const char * GPU_texture_format_name(eGPUTextureFormat format)
void GPU_texture_free(GPUTexture *texture)
void GPU_pixel_buffer_unmap(GPUPixelBuffer *pixel_buf)
int GPU_texture_width(const GPUTexture *texture)
void GPU_texture_clear(GPUTexture *texture, eGPUDataFormat data_format, const void *data)
void GPU_texture_ref(GPUTexture *texture)
void ** GPU_texture_py_reference_get(GPUTexture *texture)
void GPU_texture_bind_ex(GPUTexture *texture, GPUSamplerState state, int unit)
int GPU_texture_dimensions(const GPUTexture *texture)
void GPU_texture_copy(GPUTexture *dst, GPUTexture *src)
bool GPU_texture_has_float_format(const GPUTexture *tex)
size_t GPU_texture_dataformat_size(eGPUDataFormat data_format)
void * GPU_texture_read(GPUTexture *texture, eGPUDataFormat data_format, int mip_level)
bool GPU_texture_is_cube(const GPUTexture *texture)
void GPU_texture_image_unbind_all()
int GPU_texture_depth(const GPUTexture *texture)
void GPU_texture_unbind(GPUTexture *texture)
size_t GPU_pixel_buffer_size(GPUPixelBuffer *pixel_buf)
int GPU_texture_mip_count(const GPUTexture *texture)
int GPU_texture_original_width(const GPUTexture *texture)
GPUSamplerStateType
@ GPU_SAMPLER_STATE_TYPE_CUSTOM
@ GPU_SAMPLER_STATE_TYPE_PARAMETERS
@ GPU_SAMPLER_STATE_TYPE_INTERNAL
void GPU_texture_py_reference_set(GPUTexture *texture, void **py_ref)
void * GPU_pixel_buffer_map(GPUPixelBuffer *pixel_buf)
void GPU_pixel_buffer_free(GPUPixelBuffer *pixel_buf)
void GPU_texture_update_sub_from_pixel_buffer(GPUTexture *texture, eGPUDataFormat data_format, GPUPixelBuffer *pixel_buf, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
void GPU_texture_anisotropic_filter(GPUTexture *texture, bool use_aniso)
GPUTexture * GPU_texture_create_error(int dimension, bool array)
int64_t GPU_pixel_buffer_get_native_handle(GPUPixelBuffer *pixel_buf)
static const int GPU_SAMPLER_FILTERING_TYPES_COUNT
GPUTexture * GPU_texture_create_cube_array(const char *name, int width, int layer_len, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
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
void GPU_texture_compare_mode(GPUTexture *texture, bool use_compare)
void GPU_texture_extend_mode_x(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
bool GPU_texture_has_integer_format(const GPUTexture *texture)
GPUTexture * GPU_texture_create_from_vertbuf(const char *name, blender::gpu::VertBuf *vertex_buf)
GPUTexture * GPU_texture_create_view(const char *name, GPUTexture *source_texture, eGPUTextureFormat view_format, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array, bool use_stencil)
bool GPU_texture_is_array(const GPUTexture *texture)
int GPU_texture_opengl_bindcode(const GPUTexture *texture)
eGPUTextureUsage
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_WRITE
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_MEMORYLESS
@ GPU_TEXTURE_USAGE_ATTACHMENT
@ GPU_TEXTURE_USAGE_GENERAL
@ GPU_TEXTURE_USAGE_ATOMIC
@ GPU_TEXTURE_USAGE_FORMAT_VIEW
bool GPU_texture_has_stencil_format(const GPUTexture *texture)
GPUSamplerExtendMode
@ GPU_SAMPLER_EXTEND_MODE_MIRRORED_REPEAT
@ GPU_SAMPLER_EXTEND_MODE_REPEAT
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
@ GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER
void GPU_texture_update_sub(GPUTexture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
void GPU_texture_update_mipmap(GPUTexture *texture, int mip_level, eGPUDataFormat data_format, const void *pixels)
GPUTexture * GPU_texture_create_2d_array(const char *name, int width, int height, int layer_len, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
bool GPU_texture_has_signed_format(const GPUTexture *tex)
void GPU_texture_mipmap_mode(GPUTexture *texture, bool use_mipmap, bool use_filter)
void GPU_texture_image_unbind(GPUTexture *texture)
GPUTexture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const void *data)
void GPU_texture_image_bind(GPUTexture *texture, int unit)
bool GPU_texture_has_normalized_format(const GPUTexture *tex)
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
eGPUTextureFormat
@ GPU_RGB16
@ GPU_R16UI
@ GPU_RGB8
@ GPU_RG16F
@ GPU_DEPTH32F_STENCIL8
@ GPU_R32F
@ 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_R16F
@ GPU_RGB16I
@ GPU_RGBA16_SNORM
@ GPU_RGB9_E5
@ GPU_SRGB8_A8_DXT5
@ GPU_RG8I
@ GPU_RG16I
@ GPU_RG32UI
@ GPU_RGB32I
@ GPU_RGBA32F
@ GPU_RGBA16F
@ GPU_RG8
@ GPU_RG32I
@ GPU_SRGB8_A8_DXT1
@ GPU_RG16
@ 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_R32UI
@ GPU_RGBA32I
@ GPU_RGBA8_DXT5
@ GPU_DEPTH_COMPONENT32F
@ GPU_R16_SNORM
@ GPU_DEPTH_COMPONENT16
@ GPU_R11F_G11F_B10F
@ GPU_RGBA8
void GPU_texture_unbind_all()
GPUTexture * GPU_texture_create_cube(const char *name, int width, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_update_mipmap_chain(GPUTexture *texture)
eGPUTextureUsage GPU_texture_usage(const GPUTexture *texture)
GPUPixelBuffer * GPU_pixel_buffer_create(size_t byte_size)
GPUTexture * GPU_texture_create_1d_array(const char *name, int width, int layer_len, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_unpack_row_length_set(uint len)
GPUSamplerFiltering
@ GPU_SAMPLER_FILTERING_MIPMAP
@ GPU_SAMPLER_FILTERING_ANISOTROPIC
@ GPU_SAMPLER_FILTERING_LINEAR
@ GPU_SAMPLER_FILTERING_DEFAULT
void GPU_texture_original_size_set(GPUTexture *texture, int width, int height)
int GPU_texture_layer_count(const GPUTexture *texture)
bool GPU_texture_has_depth_format(const GPUTexture *texture)
void GPU_samplers_update()
size_t GPU_texture_component_len(eGPUTextureFormat format)
void GPU_texture_update(GPUTexture *texture, eGPUDataFormat data_format, const void *data)
void GPU_texture_get_mipmap_size(GPUTexture *texture, int mip_level, int *r_size)
unsigned int GPU_texture_memory_usage_get()
eGPUTextureFormat GPU_texture_format(const GPUTexture *texture)
void GPU_texture_swizzle_set(GPUTexture *texture, const char swizzle[4])
local_group_size(16, 16) .push_constant(Type rhs
int len
format
static ulong state[N]
__int64 int64_t
Definition stdint.h:89
GPUSamplerCustomType custom_type
GPUSamplerExtendMode extend_yz
static constexpr GPUSamplerState internal_sampler()
static constexpr GPUSamplerState icon_sampler()
static constexpr GPUSamplerState default_sampler()
GPUSamplerFiltering filtering
void enable_filtering_flag(GPUSamplerFiltering filtering_flags)
std::string to_string() const
void disable_filtering_flag(GPUSamplerFiltering filtering_flags)
GPUSamplerExtendMode extend_x
static constexpr GPUSamplerState compare_sampler()
bool operator==(GPUSamplerState const &rhs) const
GPUSamplerStateType type
void set_filtering_flag_from_test(GPUSamplerFiltering filtering_flags, bool test)