22#include <Cocoa/Cocoa.h>
23#include <Metal/Metal.h>
24#include <QuartzCore/QuartzCore.h>
27@class MTLCommandQueue;
28@class MTLRenderPipelineState;
67 return uint64_t(string_hasher(this->input_data_type + this->output_data_type +
68 std::to_string((this->component_count_input << 9) |
69 (this->component_count_output << 5) |
70 (this->is_clear ? 1 : 0))));
125 return uint64_t(string_hasher(this->input_data_type + this->output_data_type +
126 std::to_string((this->component_count_input << 8) +
127 this->component_count_output +
128 (this->depth_format_mode << 28))));
152 return (this->state == other.
state);
157 uint integer_representation = 0;
158 integer_representation |= this->state.
filtering;
159 integer_representation |= this->state.
extend_x << 8;
160 integer_representation |= this->state.
extend_yz << 12;
161 integer_representation |= this->state.
custom_type << 16;
162 integer_representation |= this->state.
type << 24;
163 return integer_representation;
168 uint64_t integer_representation = 0;
169 integer_representation |= this->state.
filtering;
170 integer_representation |= this->state.
extend_x << 8;
171 integer_representation |= this->state.
extend_yz << 12;
172 integer_representation |= this->state.
custom_type << 16;
173 integer_representation |= this->state.
type << 24;
174 return integer_representation;
194 MTL_TEXTURE_MODE_DEFAULT,
195 MTL_TEXTURE_MODE_EXTERNAL,
196 MTL_TEXTURE_MODE_VBO,
197 MTL_TEXTURE_MODE_TEXTURE_VIEW
203 bool is_baked_ =
false;
204 MTLTextureDescriptor *texture_descriptor_ =
nullptr;
208 size_t aligned_w_ = 0;
219 int tex_buffer_metadata_[4];
223 uint blit_fb_slice_ = 0;
224 uint blit_fb_mip_ = 0;
243 enum TextureViewDirtyState {
244 TEXTURE_VIEW_NOT_DIRTY = 0,
245 TEXTURE_VIEW_SWIZZLE_DIRTY = (1 << 0),
246 TEXTURE_VIEW_MIP_DIRTY = (1 << 1)
249 char tex_swizzle_mask_[4];
250 MTLTextureSwizzleChannels mtl_swizzle_mask_;
251 bool mip_range_dirty_ =
false;
253 bool texture_view_stencil_ =
false;
254 int texture_view_dirty_flags_ = TEXTURE_VIEW_NOT_DIRTY;
257 int mtl_max_mips_ = 1;
258 bool has_generated_mips_ =
false;
284 const uint unpack_row_length)
override;
288 GPUPixelBuffer *pixbuf)
override;
293 void swizzle_set(
const char swizzle_mask[4])
override;
300 return name_.c_str();
305 return (mtl_swizzle_mask_.red != MTLTextureSwizzleRed ||
306 mtl_swizzle_mask_.green != MTLTextureSwizzleGreen ||
307 mtl_swizzle_mask_.blue != MTLTextureSwizzleBlue ||
308 mtl_swizzle_mask_.alpha != MTLTextureSwizzleAlpha);
313 if (resource_mode_ == MTL_TEXTURE_MODE_VBO) {
314 return vert_buffer_mtl_;
323 return tex_buffer_metadata_;
338 void mtl_texture_init();
342 void prepare_internal();
350 void mip_range_set(
int min,
int max);
351 void ensure_mipmaps(
int miplvl);
354 void add_subresource(
uint level);
356 void read_internal(
int mip,
364 int num_output_components,
365 size_t debug_data_size,
367 void bake_mip_swizzle_view();
424 struct TextureUpdateParams {
428 int unpack_row_length;
454 void update_sub_depth_2d(
458 struct TextureReadParams {
464 id<MTLComputePipelineState> texture_read_1d_get_kernel(
465 TextureReadRoutineSpecialization specialization);
466 id<MTLComputePipelineState> texture_read_1d_array_get_kernel(
467 TextureReadRoutineSpecialization specialization);
468 id<MTLComputePipelineState> texture_read_2d_get_kernel(
469 TextureReadRoutineSpecialization specialization);
470 id<MTLComputePipelineState> texture_read_2d_array_get_kernel(
471 TextureReadRoutineSpecialization specialization);
472 id<MTLComputePipelineState> texture_read_3d_get_kernel(
473 TextureReadRoutineSpecialization specialization);
475 id<MTLComputePipelineState> mtl_texture_read_impl(
476 TextureReadRoutineSpecialization specialization_params,
477 Map<TextureReadRoutineSpecialization, id<MTLComputePipelineState>> &specialization_cache,
481 gpu::Shader *fullscreen_blit_sh_get();
483 MEM_CXX_CLASS_ALLOC_FUNCS(
"MTLTexture")
494 void *
map()
override;
495 void unmap()
override;
501 MEM_CXX_CLASS_ALLOC_FUNCS(
"MTLPixelBuffer")
567 return MTLTextureType1D;
569 return MTLTextureType2D;
571 return MTLTextureType3D;
573 return MTLTextureTypeCube;
575 return MTLTextureTypeTextureBuffer;
577 return MTLTextureType1DArray;
579 return MTLTextureType2DArray;
581 return MTLTextureTypeCubeArray;
585 return MTLTextureType2D;
593 case MTLPixelFormatRGBA8Unorm_sRGB:
594 case MTLPixelFormatBGRA8Unorm_sRGB:
595 case MTLPixelFormatDepth16Unorm:
596 case MTLPixelFormatDepth32Float:
597 case MTLPixelFormatDepth32Float_Stencil8:
598 case MTLPixelFormatBGR10A2Unorm:
599 case MTLPixelFormatDepth24Unorm_Stencil8:
612 case MTLPixelFormatRGBA8Unorm_sRGB:
613 return MTLPixelFormatRGBA8Unorm;
614 case MTLPixelFormatBGRA8Unorm_sRGB:
615 return MTLPixelFormatBGRA8Unorm;
616 case MTLPixelFormatDepth16Unorm:
617 return MTLPixelFormatR16Unorm;
618 case MTLPixelFormatDepth32Float:
619 return MTLPixelFormatR32Float;
620 case MTLPixelFormatDepth32Float_Stencil8:
624 return MTLPixelFormatInvalid;
625 case MTLPixelFormatBGR10A2Unorm:
629 return MTLPixelFormatInvalid;
630 case MTLPixelFormatDepth24Unorm_Stencil8:
634 return MTLPixelFormatInvalid;
643 MTLTextureUsage mtl_usage = MTLTextureUsageUnknown;
645 return MTLTextureUsageUnknown;
650 mtl_usage = mtl_usage | MTLTextureUsageShaderRead;
653 mtl_usage = mtl_usage | MTLTextureUsageShaderWrite;
656 mtl_usage = mtl_usage | MTLTextureUsageRenderTarget;
659 mtl_usage = mtl_usage | MTLTextureUsagePixelFormatView;
661#if defined(MAC_OS_VERSION_14_0)
662 if (@available(macOS 14.0, *)) {
664 mtl_usage = mtl_usage | MTLTextureUsageShaderAtomic;
674 if (mtl_usage == MTLTextureUsageUnknown) {
677 if (mtl_usage & MTLTextureUsageShaderRead) {
680 if (mtl_usage & MTLTextureUsageShaderWrite) {
683 if (mtl_usage & MTLTextureUsageRenderTarget) {
686 if (mtl_usage & MTLTextureUsagePixelFormatView) {
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
GPUPixelBufferNativeHandle get_native_handle() override
id< MTLBuffer > get_metal_buffer()
size_t get_size() override
MTLPixelBuffer(size_t size)
void update_sub(int mip, int offset[3], int extent[3], eGPUDataFormat type, const void *data, const uint unpack_row_length) override
bool has_custom_swizzle()
friend class MTLFrameBuffer
id< MTLTexture > get_non_srgb_handle()
friend class MTLTexturePool
id< MTLTexture > get_metal_handle()
friend class MTLStateManager
friend void xr_blit(id< MTLTexture > metal_xr_texture, int ofsx, int ofsy, int width, int height)
MTLTexture(const char *name)
friend class MTLStorageBuf
MTLSamplerState get_sampler_state()
void read(int mip, eGPUDataFormat type, void *data) override
id< MTLTexture > get_metal_handle_base()
MTLStorageBuf * get_storagebuf()
const int * get_texture_metadata_ptr() const
void generate_mipmap() override
bool init_internal() override
void swizzle_set(const char swizzle_mask[4]) override
id< MTLBuffer > get_vertex_buffer() const
void clear(const double4 data) override
void copy_to(Texture *dst, IndexRange mip_levels) override
Texture(const char *name)
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
size_t get_mtl_format_bytesize(MTLPixelFormat tex_format)
MTLPixelFormat gpu_texture_format_to_metal(TextureFormat tex_format)
static Context * unwrap(GPUContext *ctx)
static const int MTL_MAX_FBO_ATTACHED
std::string tex_data_format_to_msl_type_str(eGPUDataFormat type)
bool mtl_format_is_writable(MTLPixelFormat format)
static GPUContext * wrap(Context *ctx)
std::string tex_data_format_to_msl_texture_template_type(eGPUDataFormat type)
MTLPixelFormat mtl_format_get_writeable_view_format(MTLPixelFormat format)
int get_mtl_format_num_components(MTLPixelFormat tex_format)
static const int MTL_MAX_MIPMAP_COUNT
const MTLSamplerState DEFAULT_SAMPLER_STATE
MTLTextureUsage mtl_usage_from_gpu(eGPUTextureUsage usage)
MTLTextureType to_metal_type(GPUTextureType type)
bool mtl_format_supports_blending(MTLPixelFormat format)
eGPUTextureUsage gpu_usage_from_mtl(MTLTextureUsage mtl_usage)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
@ GPU_DATA_2_10_10_10_REV
@ GPU_DATA_UINT_24_8_DEPRECATED
@ MTL_DEPTH_UPDATE_MODE_INT32
@ MTL_DEPTH_UPDATE_MODE_INT24
@ MTL_DEPTH_UPDATE_MODE_FLOAT
@ GPU_TEXTURE_USAGE_FORMAT_VIEW
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_WRITE
@ GPU_TEXTURE_USAGE_GENERAL
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_ATOMIC
@ GPU_TEXTURE_USAGE_ATTACHMENT
BMesh const char void * data
VecBase< double, 4 > double4
DepthTextureUpdateMode data_mode
bool operator==(const DepthTextureUpdateRoutineSpecialization &other) const
GPUSamplerExtendMode extend_yz
GPUSamplerFiltering filtering
GPUSamplerCustomType custom_type
GPUSamplerExtendMode extend_x
static constexpr GPUSamplerState default_sampler()
int component_count_input
std::string input_data_type
std::string output_data_type
bool operator==(const TextureReadRoutineSpecialization &other) const
int component_count_output
std::string input_data_type
bool operator==(const TextureUpdateRoutineSpecialization &other) const
int component_count_input
std::string output_data_type
int component_count_output
bool operator==(const MTLSamplerState &other) const