76 const bool float_rect = (ibuf->
float_data() !=
nullptr);
82 *r_texture_format = is_grayscale ?
83 (use_high_bitdepth ? gpu::TextureFormat::SFLOAT_32 :
84 gpu::TextureFormat::SFLOAT_16) :
85 (use_high_bitdepth ? gpu::TextureFormat::SFLOAT_32_32_32_32 :
86 gpu::TextureFormat::SFLOAT_16_16_16_16);
93 *r_texture_format = (is_grayscale) ? gpu::TextureFormat::UNORM_8 :
94 gpu::TextureFormat::UNORM_8_8_8_8;
98 *r_texture_format = (is_grayscale) ? gpu::TextureFormat::SFLOAT_16 :
99 gpu::TextureFormat::SRGBA_8_8_8_8;
103 *r_texture_format = (is_grayscale) ? gpu::TextureFormat::SFLOAT_16 :
104 gpu::TextureFormat::SFLOAT_16_16_16_16;
125 *r_texture_format = use_srgb ? gpu::TextureFormat::SRGB_DXT1 : gpu::TextureFormat::SNORM_DXT1;
129 *r_texture_format = use_srgb ? gpu::TextureFormat::SRGB_DXT3 : gpu::TextureFormat::SNORM_DXT3;
133 *r_texture_format = use_srgb ? gpu::TextureFormat::SRGB_DXT5 : gpu::TextureFormat::SNORM_DXT5;
142 const T *src,
const int channels,
const int stride,
const int w,
const int h,
T *r_gray)
144 for (
int row = 0; row < h; row++) {
145 for (
int col = 0; col <
w; col++) {
146 r_gray[size_t(row) *
w + col] = src[(size_t(row) * stride + col) * channels];
155 const bool is_grayscale,
156 const bool store_premultiplied)
226 const int2 src_offset,
228 const std::optional<int2> scaled_size,
229 const bool premultiplied_alpha,
230 const bool is_grayscale,
234 source_buffer, is_grayscale, premultiplied_alpha);
251 premultiplied_alpha);
254 r_upload.
stride = src_size.x;
270 premultiplied_alpha);
273 r_upload.
stride = src_size.x;
280 (
int64_t(src_offset.y) * source_buffer->
x + src_offset.x);
289 r_upload.
stride = source_buffer->
x;
292 int2 size = src_size;
295 if (scaled_size.has_value()) {
302 if (buffer ==
nullptr) {
303 r_upload.
data =
nullptr;
308 const bool threaded =
int64_t(size.x) * size.y >= 512 * 512;
332 r_upload.
data = is_float ?
static_cast<const void *
>(buffer->
float_data()) :
333 static_cast<const void *
>(buffer->
byte_data());
334 r_upload.
stride = scaled_size->x;
342 if (buffer ==
nullptr) {
343 r_upload.
data =
nullptr;
372 static_cast<const void *
>(buffer->
float_data()) :
373 static_cast<const void *
>(buffer->
byte_data());
377 r_upload.
size = size;
407 bool use_high_bitdepth,
438 const std::optional<int2> scaled_size = (ibuf->
x !=
w || ibuf->
y != h) ?
439 std::optional<int2>(
int2(
w, h)) :
444 ibuf,
int2(0),
int2(ibuf->
x, ibuf->
y), scaled_size, use_premult, is_grayscale, upload);
461 int size[2] = {ibuf->
x, ibuf->
y};
466 bool do_rescale = (ibuf->
x != size[0]) || (ibuf->
y != size[1]);
469 if (do_rescale && ibuf->
x != ibuf->
y) {
470 if (ibuf->
x > ibuf->
y) {
471 size[1] =
math::max(1,
int(ibuf->
y * (
float(size[0]) / ibuf->
x)));
474 size[0] =
math::max(1,
int(ibuf->
x * (
float(size[1]) / ibuf->
y)));
483 "DDS image '%s' is not in a supported GPU compression format",
486 else if (do_rescale) {
488 &
LOG,
"DDS image '%s' can't use compressed due to size limit", ibuf->
filepath.c_str());
496 "DDS image '%s' can't use compressed due to non power of two size",
503 ibuf->
filepath.c_str(), ibuf->
x, ibuf->
y, mip_count);
504 if (compressed_data !=
nullptr) {
508 use_mipmap ? mip_count : 1,
512 MEM_delete(compressed_data);
513 if (tex !=
nullptr) {
517 "DDS image '%s' failed to create compressed GPU texture",
539 name,
UNPACK2(size), use_mipmap ? 9999 : 1, tex_format, usage,
nullptr);
540 if (tex ==
nullptr) {
541 size[0] =
max_ii(1, size[0] / 2);
542 size[1] =
max_ii(1, size[1] / 2);
544 name,
UNPACK2(size), use_mipmap ? 9999 : 1, tex_format, usage,
nullptr);
548 const std::optional<int2> scaled_size = do_rescale ? std::optional<int2>(
int2(size)) :
585 const int tx_begin = std::max(
bounds.xmin, 0) / chunk_size;
586 const int ty_begin = std::max(
bounds.ymin, 0) / chunk_size;
587 const int tx_end = std::min((
bounds.xmax - 1) / chunk_size, size.x - 1);
588 const int ty_end = std::min((
bounds.ymax - 1) / chunk_size, size.y - 1);
589 for (
int ty = ty_begin; ty <= ty_end; ty++) {
590 for (
int tx = tx_begin; tx <= tx_end; tx++) {
591 modified_chunks[
int64_t(ty) * size.x + tx].set();
602 const float xratio = limit.x /
float(full.x);
603 const float yratio = limit.y /
float(full.y);
607 offset.x = int(offset.x * xratio);
608 offset.y = int(offset.y * yratio);
609 int2 scaled_size =
int2(
int(
ceil(xratio * size.x)),
int(
ceil(yratio * size.y)));
612 if (offset.x + scaled_size.x > limit.x) {
615 if (offset.y + scaled_size.y > limit.y) {
624 const bool store_premultiplied,
630 const int2 tile_offset,
631 const int2 tile_size,
637 const bool scaled = (ibuf->
x != limit_w) || (ibuf->
y != limit_h);
653 std::optional<int2> scaled_size;
660 offset += tile_offset;
665 ibuf,
int2(
x,
y),
int2(
w, h), scaled_size, store_premultiplied, use_grayscale, upload);
682 &r_bounds, offset.x, offset.x + upload.
size.x, offset.y, offset.y + upload.
size.y);
688 const bool store_premultiplied,
691 const int2 tile_offset,
692 const int2 tile_size)
702 (tile_offset !=
int2(0, 0) || tile_size !=
int2(ibuf->
x, ibuf->
y)));
704 int2 modified_chunks_size;
705 if (compute_chunks) {
707 modified_chunks.
resize(
int64_t(modified_chunks_size.x) * modified_chunks_size.y,
false);
730 if (compute_chunks) {
738 compute_chunks ?
BitSpan(modified_chunks) :
753 switch (changes.
kind) {
754 case Changes::Kind::Full:
755 case Changes::Kind::Resized:
760 case Changes::Kind::Partial:
772 case Changes::Kind::None:
809 if (tex ==
nullptr) {
832 return gpu_texture_format;
868 const float half_min = -65504;
869 const float half_max = 65504;
876 int rect_float_len = image_buffer->
x * image_buffer->
y *
879 for (
int i = 0; i < rect_float_len; i++) {
880 rect_float[i] =
clamp_f(rect_float[i], half_min, half_max);
Platform independent time functions.
#define CLOG_WARN(clg_ref,...)
#define DDS_COMPRESSED_DXT3
#define DDS_COMPRESSED_DXT1
#define DDS_COMPRESSED_DXT5
Read Blender memory allocation and freeing.
btMatrix3x3 scaled(const btVector3 &s) const
Create a scaled copy of the matrix.
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
void resize(const int64_t new_size_in_bits, const bool value=false)
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
T max(const T &a, const T &b)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool IMB_gpu_get_compressed_format(const ImBuf *ibuf, gpu::TextureFormat *r_texture_format)
uint padding(uint offset, uint alignment)
void IMB_assign_gpu_texture(ImBuf *ibuf, gpu::Texture *texture)
void GPU_texture_update(gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
gpu::TextureFormat GPU_texture_format(const gpu::Texture *texture)
gpu::Texture * GPU_texture_create_compressed_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const void *data)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void imb_gpu_extract_first_channel(const T *src, const int channels, const int stride, const int w, const int h, T *r_gray)
int64_t BLI_time_now_seconds_i()
static int2 imb_gpu_texture_update_offset_size(int2 &offset, const int2 size, const int2 limit, const int2 full)
bool BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest)
void GPU_texture_update_mipmap_chain(gpu::Texture *texture)
constexpr int GPU_TEXTURE_MIPMAP_UPDATE_CHUNK_SIZE
static void imb_gpu_texture_default_init_mipmap(gpu::Texture *tex)
void BLI_rcti_init_minmax(struct rcti *rect)
gpu::TextureFormat IMB_gpu_get_texture_format(const ImBuf *ibuf, bool high_bitdepth, bool use_grayscale)
@ GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER
@ GPU_SAMPLER_EXTEND_MODE_REPEAT
gpu::Texture * GPU_texture_create_2d_array(const char *name, int width, int height, int layer_len, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
MINLINE int max_ii(int a, int b)
static void imb_gpu_texture_apply_partial_updates(ImBuf *ibuf, const bool use_premult)
void GPU_texture_anisotropic_filter(gpu::Texture *texture, bool use_aniso)
static void imb_gpu_texture_update_region(gpu::Texture *tex, ImBuf *ibuf, const bool store_premultiplied, int x, int y, int w, int h, const int layer, const int2 tile_offset, const int2 tile_size, rcti &r_bounds)
imbuf::ChangesetID IMB_partial_update_changeset_id_current()
static void imb_gpu_mipmap_modified_chunks_mark(MutableBitSpan modified_chunks, const int2 size, const rcti &bounds)
void IMB_colormanagement_imbuf_to_byte_texture(unsigned char *out_buffer, int offset_x, int offset_y, int width, int height, const ImBuf *ibuf, bool store_premultiplied)
void GPU_texture_update_sub(gpu::Texture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth, uint unpack_row_length=0)
void GPU_texture_mipmap_mode(gpu::Texture *texture, bool use_mipmap, bool use_filter)
bool IMB_colormanagement_space_is_scene_linear(const ColorSpace *colorspace)
bool IMB_colormanagement_space_is_scene_linear_srgb(const ColorSpace *colorspace)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
void IMB_freeImBuf(ImBuf *ibuf)
VecBase< int32_t, 2 > int2
static GPUTextureConversion imb_gpu_texture_conversion(const ImBuf *ibuf, const bool is_grayscale, const bool store_premultiplied)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_GENERAL
@ GPU_TEXTURE_USAGE_HOST_READ
uint8_t * imb_load_dds_compressed_data(const char *filepath, int width, int height, int &r_mipcount)
void IMB_gpu_clamp_half_float(ImBuf *image_buffer)
void GPU_texture_update_mipmap_chain_partial(gpu::Texture *texture, int layer, BitSpan modified_chunks)
void GPU_texture_swizzle_set(gpu::Texture *texture, const char swizzle[4])
int GPU_texture_width(const gpu::Texture *texture)
void IMB_scale_box(const float *src_buffer, int2 src_size, int channels, float *dst_buffer, int2 dst_size, bool threaded, int src_stride=0)
static void imb_gpu_texture_default_init(gpu::Texture *tex, const ImBuf *ibuf)
void IMB_gpu_texture_apply_partial_update(gpu::Texture *tex, ImBuf *ibuf, bool store_premultiplied, const imbuf::partial_update::Changes &changes, int layer=-1, int2 tile_offset=int2(0), int2 tile_size=int2(0))
size_t GPU_texture_component_len(gpu::TextureFormat format)
bool BLI_rcti_is_empty(const struct rcti *rect)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
static void get_gpu_texture_data(ImBuf *source_buffer, const int2 src_offset, const int2 src_size, const std::optional< int2 > scaled_size, const bool premultiplied_alpha, const bool is_grayscale, GPUTextureUpload &r_upload)
void GPU_texture_extend_mode(gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
static void imb_gpu_texture_default_init_array(gpu::Texture *tex)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, ImBufFlags flags)
bool IMB_alpha_affects_rgb(const ImBuf *ibuf)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
bool GPU_texture_has_compressed_format(const gpu::Texture *texture)
imbuf::ChangesetID IMB_partial_update_changeset_id_next()
void IMB_update_gpu_texture_sub(gpu::Texture *tex, ImBuf *ibuf, int x, int y, int z, int w, int h, bool use_grayscale, bool use_premult)
bool IMB_colormanagement_space_is_data(const ColorSpace *colorspace)
gpu::Texture * IMB_acquire_gpu_texture(const char *name, ImBuf *ibuf, GPUTextureCreateFlags texture_create_flags, bool try_only=false)
gpu::Texture * IMB_create_gpu_texture(const char *name, ImBuf *ibuf, GPUTextureCreateFlags flags)
int GPU_texture_height(const gpu::Texture *texture)
void GPU_texture_free(gpu::Texture *texture)
void IMB_free_gpu_textures(ImBuf *ibuf)
MINLINE uint divide_ceil_u(uint a, uint b)
static bool imb_is_grayscale_texture_format_compatible(const ImBuf *ibuf)
imbuf::partial_update::Changes IMB_partial_update_collect(ImBuf *ibuf, imbuf::ChangesetID last_changeset_id)
void IMB_partial_update_flush(ImBuf *ibuf)
void GPU_texture_unbind(gpu::Texture *texture)
bool IMB_alloc_float_pixels(ImBuf *ibuf, unsigned int channels, bool initialize_pixels=true)
MINLINE int is_power_of_2_i(int n)
static int2 imb_gpu_mipmap_modified_chunks_size(gpu::Texture *tex)
MINLINE int min_ii(int a, int b)
void IMB_colormanagement_imbuf_to_float_texture(float *out_buffer, int offset_x, int offset_y, int width, int height, const ImBuf *ibuf, bool store_premultiplied)
static const char * imb_gpu_get_swizzle(const ImBuf *ibuf)
gpu::Texture * IMB_touch_gpu_texture(const char *name, ImBuf *ibuf, int w, int h, int layers, bool use_high_bitdepth, bool use_grayscale)
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
static void imb_gpu_get_format(const ImBuf *ibuf, bool high_bitdepth, bool use_grayscale, gpu::TextureFormat *r_texture_format)
ocio::ColorSpace ColorSpace
int GPU_texture_size_with_limit(int res)
MINLINE float clamp_f(float value, float min, float max)
void GPU_texture_ref(gpu::Texture *texture)
eGPUTextureUsage GPU_texture_mipmap_usage(gpu::TextureFormat format)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
GPUTextureUpload()=default
const ColorSpace * colorspace
const ColorSpace * colorspace
std::atomic< imbuf::ChangesetID > partial_update_changeset_id
std::atomic< gpu::Texture * > texture
ImbFormatOptions foptions
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
const uint8_t * byte_data() const
uint8_t * byte_data_for_write()
const float * float_data() const
void assign_byte_data(uint8_t *data)
float * float_data_for_write()
BitVector modified_chunks
Vector< rcti > modified_regions() const