90 return gpu::TextureFormat::SFLOAT_16;
93 return gpu::TextureFormat::SFLOAT_16_16_16_16;
97 return gpu::TextureFormat::SFLOAT_16_16_16_16;
99 return gpu::TextureFormat::SFLOAT_16_16;
101 return gpu::TextureFormat::SINT_16;
103 return gpu::TextureFormat::SINT_16_16;
107 return gpu::TextureFormat::SINT_16_16_16_16;
109 return gpu::TextureFormat::SINT_16_16_16_16;
112 return gpu::TextureFormat::SINT_8;
115 return gpu::TextureFormat::SFLOAT_16_16_16_16;
119 return gpu::TextureFormat::SINT_8;
121 return gpu::TextureFormat::SFLOAT_16_16_16_16;
140 return gpu::TextureFormat::SFLOAT_32;
143 return gpu::TextureFormat::SFLOAT_32_32_32_32;
147 return gpu::TextureFormat::SFLOAT_32_32_32_32;
149 return gpu::TextureFormat::SFLOAT_32_32;
151 return gpu::TextureFormat::SINT_32;
153 return gpu::TextureFormat::SINT_32_32;
157 return gpu::TextureFormat::SINT_32_32_32_32;
159 return gpu::TextureFormat::SINT_32_32_32_32;
162 return gpu::TextureFormat::SINT_8;
165 return gpu::TextureFormat::SFLOAT_32_32_32_32;
169 return gpu::TextureFormat::SINT_8;
171 return gpu::TextureFormat::SFLOAT_32_32_32_32;
190 return gpu::TextureFormat::SFLOAT_32_32_32_32;
236 case gpu::TextureFormat::SFLOAT_16:
237 case gpu::TextureFormat::SFLOAT_16_16:
238 case gpu::TextureFormat::SFLOAT_16_16_16:
239 case gpu::TextureFormat::SFLOAT_16_16_16_16:
240 case gpu::TextureFormat::SINT_16:
241 case gpu::TextureFormat::SINT_16_16:
242 case gpu::TextureFormat::SINT_16_16_16_16:
246 case gpu::TextureFormat::SINT_8:
249 case gpu::TextureFormat::SFLOAT_32:
250 return gpu::TextureFormat::SFLOAT_16;
251 case gpu::TextureFormat::SFLOAT_32_32:
252 return gpu::TextureFormat::SFLOAT_16_16;
253 case gpu::TextureFormat::SFLOAT_32_32_32:
254 return gpu::TextureFormat::SFLOAT_16_16_16;
255 case gpu::TextureFormat::SFLOAT_32_32_32_32:
256 return gpu::TextureFormat::SFLOAT_16_16_16_16;
257 case gpu::TextureFormat::SINT_32:
258 return gpu::TextureFormat::SINT_16;
259 case gpu::TextureFormat::SINT_32_32:
260 return gpu::TextureFormat::SINT_16_16;
261 case gpu::TextureFormat::SINT_32_32_32_32:
262 return gpu::TextureFormat::SINT_16_16_16_16;
270 case gpu::TextureFormat::SFLOAT_32:
271 case gpu::TextureFormat::SFLOAT_32_32:
272 case gpu::TextureFormat::SFLOAT_32_32_32:
273 case gpu::TextureFormat::SFLOAT_32_32_32_32:
274 case gpu::TextureFormat::SINT_32:
275 case gpu::TextureFormat::SINT_32_32:
276 case gpu::TextureFormat::SINT_32_32_32_32:
280 case gpu::TextureFormat::SINT_8:
283 case gpu::TextureFormat::SFLOAT_16:
284 return gpu::TextureFormat::SFLOAT_32;
285 case gpu::TextureFormat::SFLOAT_16_16:
286 return gpu::TextureFormat::SFLOAT_32_32;
287 case gpu::TextureFormat::SFLOAT_16_16_16:
288 return gpu::TextureFormat::SFLOAT_32_32_32;
289 case gpu::TextureFormat::SFLOAT_16_16_16_16:
290 return gpu::TextureFormat::SFLOAT_32_32_32_32;
291 case gpu::TextureFormat::SINT_16:
292 return gpu::TextureFormat::SINT_32;
293 case gpu::TextureFormat::SINT_16_16:
294 return gpu::TextureFormat::SINT_32_32;
295 case gpu::TextureFormat::SINT_16_16_16_16:
296 return gpu::TextureFormat::SINT_32_32_32_32;
310 case gpu::TextureFormat::SFLOAT_16:
311 case gpu::TextureFormat::SFLOAT_16_16:
312 case gpu::TextureFormat::SFLOAT_16_16_16:
313 case gpu::TextureFormat::SFLOAT_16_16_16_16:
314 case gpu::TextureFormat::SINT_16:
315 case gpu::TextureFormat::SINT_16_16:
316 case gpu::TextureFormat::SINT_16_16_16_16:
318 case gpu::TextureFormat::SFLOAT_32:
319 case gpu::TextureFormat::SFLOAT_32_32:
320 case gpu::TextureFormat::SFLOAT_32_32_32:
321 case gpu::TextureFormat::SFLOAT_32_32_32_32:
322 case gpu::TextureFormat::SINT_32:
323 case gpu::TextureFormat::SINT_32_32:
324 case gpu::TextureFormat::SINT_32_32_32_32:
327 case gpu::TextureFormat::SINT_8:
340 case gpu::TextureFormat::SFLOAT_16:
341 case gpu::TextureFormat::SFLOAT_32:
343 case gpu::TextureFormat::SFLOAT_16_16:
344 case gpu::TextureFormat::SFLOAT_32_32:
346 case gpu::TextureFormat::SFLOAT_16_16_16:
347 case gpu::TextureFormat::SFLOAT_32_32_32:
349 case gpu::TextureFormat::SFLOAT_16_16_16_16:
350 case gpu::TextureFormat::SFLOAT_32_32_32_32:
352 case gpu::TextureFormat::SINT_16:
353 case gpu::TextureFormat::SINT_32:
355 case gpu::TextureFormat::SINT_16_16:
356 case gpu::TextureFormat::SINT_32_32:
358 case gpu::TextureFormat::SINT_16_16_16_16:
359 case gpu::TextureFormat::SINT_32_32_32_32:
361 case gpu::TextureFormat::SINT_8:
499 const std::optional<ResultStorageType> storage_type)
501 Domain sanitized_domain = domain;
502 const bool use_gpu = storage_type.has_value() ?
505 const int max_size = use_gpu ? 8192 : 32768;
507 return sanitized_domain;
520 const bool is_from_pool_;
526 const bool is_from_pool)
533 __func__, size.x, size.y, 4, 1, format, usage,
nullptr);
535 else if (is_from_pool) {
555 const bool from_pool,
556 const std::optional<ResultStorageType> storage_type)
564 const bool use_gpu = storage_type.has_value() ?
570 domain_.data_size, this->type(), this->precision(), from_pool);
572 gpu_texture_ = new_texture->data.texture;
580 cpu_data_ = new_array->data.as_span();
598 single_value_ = 0.0f;
601 single_value_ =
float2(0.0f);
604 single_value_ =
float3(0.0f);
607 single_value_ =
float4(0.0f);
610 single_value_ =
Color(0.0f);
616 single_value_ =
int2(0);
619 single_value_ =
int3(0);
622 single_value_ =
int4(0);
625 single_value_ =
false;
637 single_value_ = std::string(
"");
640 single_value_ =
static_cast<Object *
>(
nullptr);
643 single_value_ =
static_cast<Image *
>(
nullptr);
646 single_value_ =
static_cast<VFont *
>(
nullptr);
649 single_value_ =
static_cast<Scene *
>(
nullptr);
652 single_value_ =
static_cast<Text *
>(
nullptr);
655 single_value_ =
static_cast<Mask *
>(
nullptr);
679 switch (this->
type()) {
722 for (
int i = 0; i < 4; i++) {
725 this->load_pixel<
float4x4>(texel)[i]);
757 switch (this->
type()) {
862 const char *texture_name)
const
880 __func__, 1, 1, 4, 1, format, usage,
nullptr);
889 int2(1, 1), 4, 1, format, usage);
893 int2(1, 1), 1, format, usage);
898 switch (this->
type()) {
948 return single_value_texture;
1007 derived_resources_ =
nullptr;
1018 gpu::TextureFormat::SFLOAT_32_32_32,
1019 gpu::TextureFormat::SFLOAT_16_16_16))
1026 gpu::TextureFormat::SINT_32_32_32,
1027 gpu::TextureFormat::SINT_16_16_16))
1034 result.get_gpu_texture_format();
1061 domain_.transformation = transformation;
1066 domain_.transform(transformation);
1071 return domain_.realization_options;
1076 return domain_.realization_options;
1081 reference_count_ = count;
1086 reference_count_ -= count;
1094 if (reference_count_ != 0) {
1107 delete derived_resources_;
1108 derived_resources_ =
nullptr;
1111 switch (storage_type_) {
1113 single_value_ = std::monostate{};
1116 gpu_texture_ =
nullptr;
1119 cpu_data_ =
GSpan();
1126 return reference_count_ != 0;
1131 if (!derived_resources_) {
1134 return *derived_resources_;
1163 switch (storage_type_) {
1165 return !std::holds_alternative<std::monostate>(single_value_);
1177 return reference_count_;
1231 return pixel_size * image_size.x * image_size.y;
1238 return std::visit([](
const auto &value) {
return GPointer(&value); }, single_value_);
1245 return std::visit([](
auto &value) {
return GMutablePointer(&value); }, single_value_);
1250 switch (precision) {
#define BLI_assert_unreachable()
static const CPPType & get()
GMutablePointer()=default
const void * data() const
ImplicitSharedValue(Args &&...args)
friend class ImplicitSharingPtr
constexpr const char * data() const
GPUData(const int2 size, const ResultType type, const ResultPrecision precision, const bool is_from_pool)
void decrement_reference_count(int count=1)
void share_data(const Result &source)
RealizationOptions & get_realization_options()
Result upload_to_gpu(const bool from_pool) const
bool is_single_value() const
void unbind_as_texture_or_single_value(gpu::Texture *single_value_texture) const
const CPPType & get_cpp_type() const
void store_pixel(const int2 &texel, const T &pixel_value)
bool should_compute() const
int reference_count() const
void allocate_texture(const Domain domain, const bool from_pool=true, const std::optional< ResultStorageType > storage_type=std::nullopt)
static eGPUDataFormat gpu_data_format(const ResultType type)
int64_t size_in_bytes() const
void unbind_as_texture() const
int64_t channels_count() const
static gpu::TextureFormat gpu_texture_format(ResultType type, ResultPrecision precision)
Result download_to_cpu() const
static const char * type_name(const ResultType type)
bool is_allocated() const
void set_transformation(const float3x3 &transformation)
static bool is_single_value_only_type(ResultType type)
GPointer single_value() const
const ImplicitSharingPtr & sharing_info() const
eGPUDataFormat get_gpu_data_format() const
gpu::Texture * gpu_texture() const
GMutableSpan cpu_data_for_write()
static ResultType type(gpu::TextureFormat format)
void bind_as_texture(gpu::Shader *shader, const char *texture_name) const
gpu::TextureFormat get_gpu_texture_format() const
void set_precision(ResultPrecision precision)
void transform(const float3x3 &transformation)
static const CPPType & cpp_type(const ResultType type)
T load_pixel(const int2 &texel) const
void unbind_as_image() const
void allocate_single_value()
static ResultPrecision precision(gpu::TextureFormat format)
DerivedResources & derived_resources()
void bind_as_image(gpu::Shader *shader, const char *image_name, bool read=false) const
void set_reference_count(int count)
gpu::Texture * bind_as_texture_or_single_value(gpu::Shader *shader, const char *texture_name) const
const T & get_single_value() const
void set_type(ResultType type)
virtual Texture * acquire_texture_2d_array(int2 extent, int layer_len, int mip_len, TextureFormat format, eGPUTextureUsage usage, const char *name=nullptr)=0
virtual void release_texture(Texture *tex)=0
virtual Texture * acquire_texture_2d(int2 extent, int mip_len, TextureFormat format, eGPUTextureUsage usage, const char *name=nullptr)=0
static TexturePool & get()
static BundlePtr create()
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
StringRefNull to_string(const Interpolation &interpolation)
static Domain sanitize_domain_data_size(const Domain domain, const Context &context, const std::optional< ResultStorageType > storage_type)
static bool is_compatible_texture(const gpu::Texture *texture, const Result &result)
ColorSceneLinear4f< eAlpha::Premultiplied > Color
ImplicitSharingPtr< Closure > ClosurePtr
static void bind_texture(gpu::Shader *shader, gpu::Texture *texture, const StringRef texture_name)
void parallel_for(const int2 range, const Function &function)
QuaternionBase< float > Quaternion
T clamp(const T &a, const T &min, const T &max)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int GPU_shader_get_sampler_binding(gpu::Shader *shader, const char *name)
void GPU_texture_update(gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
gpu::TextureFormat GPU_texture_format(const gpu::Texture *texture)
void GPU_texture_image_unbind(gpu::Texture *texture)
GPUBackendType GPU_backend_get_type()
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)
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)
@ GPU_TEXTURE_USAGE_GENERAL
void GPU_memory_barrier(GPUBarrier barrier)
BMesh const char void * data
int GPU_texture_width(const gpu::Texture *texture)
@ GPU_BARRIER_TEXTURE_FETCH
@ GPU_BARRIER_TEXTURE_UPDATE
@ GPU_BARRIER_SHADER_IMAGE_ACCESS
size_t GPU_texture_component_len(gpu::TextureFormat format)
void GPU_texture_bind(gpu::Texture *texture, int unit)
int GPU_texture_height(const gpu::Texture *texture)
void GPU_texture_free(gpu::Texture *texture)
void GPU_texture_image_bind(gpu::Texture *texture, int unit)
void GPU_texture_unbind(gpu::Texture *texture)
void * GPU_texture_read(gpu::Texture *texture, eGPUDataFormat data_format, int mip_level)
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)