22#include <Cocoa/Cocoa.h>
23#include <Metal/Metal.h>
24#include <QuartzCore/QuartzCore.h>
27@class MTLCommandQueue;
28@class MTLRenderPipelineState;
65 return (
uint64_t)string_hasher(this->input_data_type + this->output_data_type +
66 std::to_string((this->component_count_input << 9) |
67 (this->component_count_output << 5) |
68 (this->is_clear ? 1 : 0)));
123 return uint64_t(string_hasher(this->input_data_type + this->output_data_type +
124 std::to_string((this->component_count_input << 8) +
125 this->component_count_output +
126 (this->depth_format_mode << 28))));
150 return (this->state == other.
state);
155 uint integer_representation = 0;
156 integer_representation |= this->state.
filtering;
157 integer_representation |= this->state.
extend_x << 8;
158 integer_representation |= this->state.
extend_yz << 12;
159 integer_representation |= this->state.
custom_type << 16;
160 integer_representation |= this->state.
type << 24;
161 return integer_representation;
166 uint64_t integer_representation = 0;
167 integer_representation |= this->state.
filtering;
168 integer_representation |= this->state.
extend_x << 8;
169 integer_representation |= this->state.
extend_yz << 12;
170 integer_representation |= this->state.
custom_type << 16;
171 integer_representation |= this->state.
type << 24;
172 return integer_representation;
187 MTL_TEXTURE_MODE_DEFAULT,
188 MTL_TEXTURE_MODE_EXTERNAL,
189 MTL_TEXTURE_MODE_VBO,
190 MTL_TEXTURE_MODE_TEXTURE_VIEW
196 bool is_baked_ =
false;
197 MTLTextureDescriptor *texture_descriptor_ =
nullptr;
198 id<MTLTexture> texture_ = nil;
201 size_t aligned_w_ = 0;
212 int tex_buffer_metadata_[4];
216 uint blit_fb_slice_ = 0;
217 uint blit_fb_mip_ = 0;
220 id<MTLTexture> texture_no_srgb_ = nil;
237 enum TextureViewDirtyState {
238 TEXTURE_VIEW_NOT_DIRTY = 0,
239 TEXTURE_VIEW_SWIZZLE_DIRTY = (1 << 0),
240 TEXTURE_VIEW_MIP_DIRTY = (1 << 1)
242 id<MTLTexture> mip_swizzle_view_ = nil;
243 char tex_swizzle_mask_[4];
244 MTLTextureSwizzleChannels mtl_swizzle_mask_;
245 bool mip_range_dirty_ =
false;
247 bool texture_view_stencil_ =
false;
248 int mip_texture_base_level_ = 0;
249 int mip_texture_max_level_ = 1000;
250 int mip_texture_base_layer_ = 0;
251 int texture_view_dirty_flags_ = TEXTURE_VIEW_NOT_DIRTY;
254 int mtl_max_mips_ = 1;
255 bool has_generated_mips_ =
false;
261 MTLVertBuf *vert_buffer_;
262 id<MTLBuffer> vert_buffer_mtl_;
274 id<MTLTexture> metal_texture);
278 int mip,
int offset[3],
int extent[3],
eGPUDataFormat type,
const void *
data)
override;
282 GPUPixelBuffer *pixbuf)
override;
287 void swizzle_set(
const char swizzle_mask[4])
override;
300 return (mtl_swizzle_mask_.red != MTLTextureSwizzleRed ||
301 mtl_swizzle_mask_.green != MTLTextureSwizzleGreen ||
302 mtl_swizzle_mask_.blue != MTLTextureSwizzleBlue ||
303 mtl_swizzle_mask_.alpha != MTLTextureSwizzleAlpha);
308 if (resource_mode_ == MTL_TEXTURE_MODE_VBO) {
309 return vert_buffer_mtl_;
318 return tex_buffer_metadata_;
327 bool use_stencil)
override;
331 void mtl_texture_init();
335 void prepare_internal();
342 void ensure_mipmaps(
int miplvl);
345 void add_subresource(
uint level);
347 void read_internal(
int mip,
355 int num_output_components,
356 size_t debug_data_size,
358 void bake_mip_swizzle_view();
360 id<MTLTexture> get_metal_handle();
361 id<MTLTexture> get_metal_handle_base();
362 id<MTLTexture> get_non_srgb_handle();
364 void blit(id<MTLBlitCommandEncoder> blit_encoder,
419 struct TextureUpdateParams {
423 uint unpack_row_length;
426 id<MTLComputePipelineState> texture_update_1d_get_kernel(
428 id<MTLComputePipelineState> texture_update_1d_array_get_kernel(
430 id<MTLComputePipelineState> texture_update_2d_get_kernel(
432 id<MTLComputePipelineState> texture_update_2d_array_get_kernel(
434 id<MTLComputePipelineState> texture_update_3d_get_kernel(
437 id<MTLComputePipelineState> mtl_texture_update_impl(
440 &specialization_cache,
450 void update_sub_depth_2d(
454 struct TextureReadParams {
460 id<MTLComputePipelineState> texture_read_1d_get_kernel(
462 id<MTLComputePipelineState> texture_read_1d_array_get_kernel(
464 id<MTLComputePipelineState> texture_read_2d_get_kernel(
466 id<MTLComputePipelineState> texture_read_2d_array_get_kernel(
468 id<MTLComputePipelineState> texture_read_3d_get_kernel(
471 id<MTLComputePipelineState> mtl_texture_read_impl(
474 &specialization_cache,
478 gpu::Shader *fullscreen_blit_sh_get();
480 MEM_CXX_CLASS_ALLOC_FUNCS(
"MTLTexture")
485 id<MTLBuffer> buffer_ = nil;
491 void *
map()
override;
492 void unmap()
override;
498 MEM_CXX_CLASS_ALLOC_FUNCS(
"MTLPixelBuffer")
564 return MTLTextureType1D;
566 return MTLTextureType2D;
568 return MTLTextureType3D;
570 return MTLTextureTypeCube;
572 return MTLTextureTypeTextureBuffer;
574 return MTLTextureType1DArray;
576 return MTLTextureType2DArray;
578 return MTLTextureTypeCubeArray;
582 return MTLTextureType2D;
590 case MTLPixelFormatRGBA8Unorm_sRGB:
591 case MTLPixelFormatBGRA8Unorm_sRGB:
592 case MTLPixelFormatDepth16Unorm:
593 case MTLPixelFormatDepth32Float:
594 case MTLPixelFormatDepth32Float_Stencil8:
595 case MTLPixelFormatBGR10A2Unorm:
596 case MTLPixelFormatDepth24Unorm_Stencil8:
609 case MTLPixelFormatRGBA8Unorm_sRGB:
610 return MTLPixelFormatRGBA8Unorm;
611 case MTLPixelFormatBGRA8Unorm_sRGB:
612 return MTLPixelFormatBGRA8Unorm;
613 case MTLPixelFormatDepth16Unorm:
614 return MTLPixelFormatR16Unorm;
615 case MTLPixelFormatDepth32Float:
616 return MTLPixelFormatR32Float;
617 case MTLPixelFormatDepth32Float_Stencil8:
621 return MTLPixelFormatInvalid;
622 case MTLPixelFormatBGR10A2Unorm:
626 return MTLPixelFormatInvalid;
627 case MTLPixelFormatDepth24Unorm_Stencil8:
631 return MTLPixelFormatInvalid;
640 MTLTextureUsage mtl_usage = MTLTextureUsageUnknown;
642 return MTLTextureUsageUnknown;
647 mtl_usage = mtl_usage | MTLTextureUsageShaderRead;
650 mtl_usage = mtl_usage | MTLTextureUsageShaderWrite;
653 mtl_usage = mtl_usage | MTLTextureUsageRenderTarget;
656 mtl_usage = mtl_usage | MTLTextureUsagePixelFormatView;
658#if defined(MAC_OS_VERSION_14_0)
659 if (@available(macOS 14.0, *)) {
661 mtl_usage = mtl_usage | MTLTextureUsageShaderAtomic;
671 if (mtl_usage == MTLTextureUsageUnknown) {
674 if (mtl_usage & MTLTextureUsageShaderRead) {
677 if (mtl_usage & MTLTextureUsageShaderWrite) {
680 if (mtl_usage & MTLTextureUsageRenderTarget) {
683 if (mtl_usage & MTLTextureUsagePixelFormatView) {
#define BLI_assert_unreachable()
@ GPU_DATA_UINT_24_8_DEPRECATED
@ GPU_DATA_2_10_10_10_REV
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_WRITE
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_ATTACHMENT
@ GPU_TEXTURE_USAGE_GENERAL
@ GPU_TEXTURE_USAGE_ATOMIC
@ GPU_TEXTURE_USAGE_FORMAT_VIEW
Read Guarded memory(de)allocation.
BMesh const char void * data
unsigned long long int uint64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void reset()
clear internal cached data and reset random seed
GPUPixelBufferNativeHandle get_native_handle() override
id< MTLBuffer > get_metal_buffer()
size_t get_size() override
MTLPixelBuffer(size_t size)
bool has_custom_swizzle()
friend class MTLFrameBuffer
void copy_to(Texture *dst) override
friend class MTLStateManager
void update_sub(int mip, int offset[3], int extent[3], eGPUDataFormat type, const void *data) override
MTLTexture(const char *name)
void clear(eGPUDataFormat format, const void *data) override
friend class MTLStorageBuf
MTLStorageBuf * get_storagebuf()
void mip_range_set(int min, int max) override
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
char name_[DEBUG_NAME_LEN]
Texture(const char *name)
@ MTL_DEPTH_UPDATE_MODE_INT32
@ MTL_DEPTH_UPDATE_MODE_INT24
@ MTL_DEPTH_UPDATE_MODE_FLOAT
size_t get_mtl_format_bytesize(MTLPixelFormat tex_format)
MTLPixelFormat gpu_texture_format_to_metal(TextureFormat tex_format)
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)
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)
DepthTextureUpdateMode data_mode
bool operator==(const DepthTextureUpdateRoutineSpecialisation &other) const
GPUSamplerCustomType custom_type
GPUSamplerExtendMode extend_yz
static constexpr GPUSamplerState default_sampler()
GPUSamplerFiltering filtering
GPUSamplerExtendMode extend_x
std::string output_data_type
std::string input_data_type
int component_count_input
int component_count_output
bool operator==(const TextureReadRoutineSpecialisation &other) const
int component_count_output
int component_count_input
std::string input_data_type
std::string output_data_type
bool operator==(const TextureUpdateRoutineSpecialisation &other) const
bool operator==(const MTLSamplerState &other) const