45 if (
fb_[i] !=
nullptr) {
50#ifndef GPU_NO_USE_PY_REFERENCES
62 int mip_len_max = 1 +
floorf(log2f(
w));
110 int mip_len_max = 1 +
floorf(log2f(
w));
163 BLI_assert(layer_len == 1 && layer_start == 0);
177 return this->
init_internal(src_, mip_start, layer_start, use_stencil);
205 if (
fb_[i] ==
nullptr) {
223 BLI_assert_msg(0,
"GPU: Error: Texture: Framebuffer is not attached");
229 int extent[3] = {1, 1, 1};
230 int offset[3] = {0, 0, 0};
269 tex->usage_set(usage);
271 bool success =
false;
275 success =
tex->init_1D(
w, h, mip_len, tex_format);
279 success =
tex->init_2D(
w, h, d, mip_len, tex_format);
282 success =
tex->init_3D(
w, h, d, mip_len, tex_format);
286 success =
tex->init_cubemap(
w, d, mip_len, tex_format);
297 tex->update(data_format, pixels);
299 return reinterpret_cast<GPUTexture *
>(
tex);
395 tex->usage_set(usage);
396 bool success =
tex->init_2D(
w, h, 0, miplen, tex_format);
404 for (
int mip = 0; mip < miplen; mip++) {
405 int extent[3], offset[3] = {0, 0, 0};
406 tex->mip_size_get(mip, extent);
408 size_t size = ((extent[0] + 3) / 4) * ((extent[1] + 3) / 4) *
to_block_size(tex_format);
414 return reinterpret_cast<GPUTexture *
>(
tex);
423 "Vertex Buffers used for textures should have usage flag "
424 "GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY.");
429 bool success =
tex->init_buffer(vert, tex_format);
434 return reinterpret_cast<GPUTexture *
>(
tex);
439 const float pixel[4] = {1.0f, 0.0f, 1.0f, 1.0f};
441 int h = (dimension < 2 && !is_array) ? 0 : 1;
442 int d = (dimension < 3 && !is_array) ? 0 : 1;
473 "Source texture of TextureView must have GPU_TEXTURE_USAGE_FORMAT_VIEW usage "
474 "flag if view texture uses stencil texturing.");
477 "Source texture of TextureView must have GPU_TEXTURE_USAGE_FORMAT_VIEW usage "
478 "flag if view texture format is different.");
496 return tex->usage_get();
507 int extent[3] = {1, 1, 1}, offset[3] = {0, 0, 0};
508 tex->mip_size_get(miplvl, extent);
509 reinterpret_cast<Texture *
>(
tex)->update_sub(miplvl, offset, extent, data_format, pixels);
522 int offset[3] = {offset_x, offset_y, offset_z};
523 int extent[3] = {width, height, depth};
524 reinterpret_cast<Texture *
>(
tex)->update_sub(0, offset, extent, data_format, pixels);
529 GPUPixelBuffer *pix_buf,
537 int offset[3] = {offset_x, offset_y, offset_z};
538 int extent[3] = {width, height, depth};
539 reinterpret_cast<Texture *
>(
tex)->update_sub(offset, extent, data_format, pix_buf);
547 "The host-read usage flag must be specified up-front. Only textures which require data "
548 "reads should be flagged, allowing the backend to make certain optimisations.");
549 return tex->read(miplvl, data_format);
611 reinterpret_cast<Texture *
>(
tex)->generate_mipmap();
663 tex->sampler_state.extend_x = extend_mode;
669 tex->sampler_state.extend_yz = extend_mode;
675 tex->sampler_state.extend_x = extend_mode;
676 tex->sampler_state.extend_yz = extend_mode;
681 reinterpret_cast<Texture *
>(
tex)->swizzle_set(swizzle);
689 if (
tex->refcount < 0) {
690 fprintf(stderr,
"GPUTexture: negative refcount\n");
693 if (
tex->refcount == 0) {
724 return reinterpret_cast<const Texture *
>(
tex)->width_get();
729 return reinterpret_cast<const Texture *
>(
tex)->height_get();
734 return reinterpret_cast<const Texture *
>(
tex)->depth_get();
739 return reinterpret_cast<const Texture *
>(
tex)->layer_count();
744 return reinterpret_cast<const Texture *
>(
tex)->mip_count();
749 return reinterpret_cast<const Texture *
>(
tex)->src_w;
754 return reinterpret_cast<const Texture *
>(
tex)->src_h;
766 return reinterpret_cast<const Texture *
>(
tex)->format_get();
771 switch (texture_format) {
839 return "R11F_G11F_B10F";
841 return "DEPTH32F_STENCIL8";
843 return "DEPTH24_STENCIL8";
850 return "RGB16_SNORM";
858 return "RGBA16_SNORM";
860 return "RGBA8_SNORM";
885 return "SRGB8_A8_DXT1";
887 return "SRGB8_A8_DXT3";
889 return "SRGB8_A8_DXT5";
902 return "DEPTH_COMPONENT32F";
904 return "DEPTH_COMPONENT24";
906 return "DEPTH_COMPONENT16";
934 return (
reinterpret_cast<const Texture *
>(
tex)->format_flag_get() &
953#ifndef GPU_NO_USE_PY_REFERENCES
969 return reinterpret_cast<const Texture *
>(
tex)->gl_bindcode_get();
974 return reinterpret_cast<Texture *
>(
tex)->mip_size_get(lvl, r_size);
1006 return reinterpret_cast<PixelBuffer *
>(pix_buf)->map();
1011 reinterpret_cast<PixelBuffer *
>(pix_buf)->unmap();
1016 return reinterpret_cast<PixelBuffer *
>(pix_buf)->get_size();
1021 return reinterpret_cast<PixelBuffer *
>(pix_buf)->get_native_handle();
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
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)
#define STRNCPY(dst, src)
@ 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)
@ 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)
GPUTexture * GPU_texture_create_cube_array(const char *name, int width, int layer_len, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
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)
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_GENERAL
@ GPU_TEXTURE_USAGE_FORMAT_VIEW
bool GPU_texture_has_stencil_format(const GPUTexture *texture)
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)
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)
@ GPU_SAMPLER_FILTERING_MIPMAP
@ GPU_SAMPLER_FILTERING_ANISOTROPIC
@ GPU_SAMPLER_FILTERING_LINEAR
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])
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
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
StateManager * state_manager
void attachment_remove(GPUAttachmentType type)
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
GPUSamplerState sampler_state
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)
eGPUTextureFormat format_
eGPUTextureFormatFlag format_flag_
void update(eGPUDataFormat format, const void *data)
eGPUTextureUsage gpu_image_usage_flags_
char name_[DEBUG_NAME_LEN]
FrameBuffer * fb_[GPU_TEX_MAX_FBO_ATTACHED]
GPUAttachmentType fb_attachment_[GPU_TEX_MAX_FBO_ATTACHED]
bool init_1D(int w, int layers, int mip_len, eGPUTextureFormat format)
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)
Texture(const char *name)
void detach_from(FrameBuffer *fb)
bool init_2D(int w, int h, int layers, int mip_len, eGPUTextureFormat format)
GPUUsageType extended_usage_
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
static GPUTexture * gpu_texture_create(const char *name, const int w, const int h, const int d, const eGPUTextureType type, int mip_len, eGPUTextureFormat tex_format, eGPUDataFormat data_format, eGPUTextureUsage usage, const void *pixels)
BLI_INLINE float fb(float length, float L)
static void clear(Message &msg)
static Context * unwrap(GPUContext *ctx)
size_t to_block_size(eGPUTextureFormat data_type)
static GPUContext * wrap(Context *ctx)
@ GPU_FORMAT_NORMALIZED_INTEGER
@ GPU_FORMAT_DEPTH_STENCIL
size_t to_bytesize(GPUIndexBufType type)
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)
static void update(bNodeTree *ntree)
GPUSamplerFiltering filtering