11#include <Cocoa/Cocoa.h>
12#include <Metal/Metal.h>
13#include <QuartzCore/QuartzCore.h>
25@class MTLCommandQueue;
26@class MTLRenderPipelineState;
61 return (
uint64_t)string_hasher(this->input_data_type + this->output_data_type +
62 std::to_string((this->component_count_input << 9) |
63 (this->component_count_output << 5) |
64 (this->is_clear ? 1 : 0)));
119 return uint64_t(string_hasher(this->input_data_type + this->output_data_type +
120 std::to_string((this->component_count_input << 8) +
121 this->component_count_output +
122 (this->depth_format_mode << 28))));
146 return (this->state == other.state);
151 uint integer_representation = 0;
152 integer_representation |= this->state.
filtering;
153 integer_representation |= this->state.
extend_x << 8;
154 integer_representation |= this->state.
extend_yz << 12;
155 integer_representation |= this->state.
custom_type << 16;
156 integer_representation |= this->state.
type << 24;
157 return integer_representation;
162 uint64_t integer_representation = 0;
163 integer_representation |= this->state.
filtering;
164 integer_representation |= this->state.
extend_x << 8;
165 integer_representation |= this->state.
extend_yz << 12;
166 integer_representation |= this->state.
custom_type << 16;
167 integer_representation |= this->state.
type << 24;
168 return integer_representation;
183 MTL_TEXTURE_MODE_DEFAULT,
184 MTL_TEXTURE_MODE_EXTERNAL,
185 MTL_TEXTURE_MODE_VBO,
186 MTL_TEXTURE_MODE_TEXTURE_VIEW
192 bool is_baked_ =
false;
193 MTLTextureDescriptor *texture_descriptor_ =
nullptr;
194 id<MTLTexture> texture_ = nil;
197 size_t aligned_w_ = 0;
208 int tex_buffer_metadata_[4];
211 GPUFrameBuffer *blit_fb_ =
nullptr;
212 uint blit_fb_slice_ = 0;
213 uint blit_fb_mip_ = 0;
216 id<MTLTexture> texture_no_srgb_ = nil;
231 const GPUTexture *source_texture_ =
nullptr;
233 enum TextureViewDirtyState {
234 TEXTURE_VIEW_NOT_DIRTY = 0,
235 TEXTURE_VIEW_SWIZZLE_DIRTY = (1 << 0),
236 TEXTURE_VIEW_MIP_DIRTY = (1 << 1)
238 id<MTLTexture> mip_swizzle_view_ = nil;
239 char tex_swizzle_mask_[4];
240 MTLTextureSwizzleChannels mtl_swizzle_mask_;
241 bool mip_range_dirty_ =
false;
243 bool texture_view_stencil_ =
false;
244 int mip_texture_base_level_ = 0;
245 int mip_texture_max_level_ = 1000;
246 int mip_texture_base_layer_ = 0;
247 int texture_view_dirty_flags_ = TEXTURE_VIEW_NOT_DIRTY;
250 int mtl_max_mips_ = 1;
251 bool has_generated_mips_ =
false;
257 MTLVertBuf *vert_buffer_;
258 id<MTLBuffer> vert_buffer_mtl_;
270 id<MTLTexture> metal_texture);
274 int mip,
int offset[3],
int extent[3],
eGPUDataFormat type,
const void *data)
override;
278 GPUPixelBuffer *pixbuf)
override;
281 void copy_to(Texture *dst)
override;
283 void swizzle_set(
const char swizzle_mask[4])
override;
299 return (mtl_swizzle_mask_.red != MTLTextureSwizzleRed ||
300 mtl_swizzle_mask_.green != MTLTextureSwizzleGreen ||
301 mtl_swizzle_mask_.blue != MTLTextureSwizzleBlue ||
302 mtl_swizzle_mask_.alpha != MTLTextureSwizzleAlpha);
307 if (resource_mode_ == MTL_TEXTURE_MODE_VBO) {
308 return vert_buffer_mtl_;
317 return tex_buffer_metadata_;
326 bool use_stencil)
override;
330 void mtl_texture_init();
334 void prepare_internal();
341 void ensure_mipmaps(
int miplvl);
344 void add_subresource(
uint level);
346 void read_internal(
int mip,
354 int num_output_components,
355 size_t debug_data_size,
357 void bake_mip_swizzle_view();
359 id<MTLTexture> get_metal_handle();
360 id<MTLTexture> get_metal_handle_base();
361 id<MTLTexture> get_non_srgb_handle();
363 void blit(id<MTLBlitCommandEncoder> blit_encoder,
388 GPUFrameBuffer *get_blit_framebuffer(
int dst_slice,
uint dst_mip);
418 struct TextureUpdateParams {
422 uint unpack_row_length;
425 id<MTLComputePipelineState> texture_update_1d_get_kernel(
427 id<MTLComputePipelineState> texture_update_1d_array_get_kernel(
429 id<MTLComputePipelineState> texture_update_2d_get_kernel(
431 id<MTLComputePipelineState> texture_update_2d_array_get_kernel(
433 id<MTLComputePipelineState> texture_update_3d_get_kernel(
436 id<MTLComputePipelineState> mtl_texture_update_impl(
439 &specialization_cache,
449 void update_sub_depth_2d(
450 int mip,
int offset[3],
int extent[3],
eGPUDataFormat type,
const void *data);
453 struct TextureReadParams {
459 id<MTLComputePipelineState> texture_read_1d_get_kernel(
461 id<MTLComputePipelineState> texture_read_1d_array_get_kernel(
463 id<MTLComputePipelineState> texture_read_2d_get_kernel(
465 id<MTLComputePipelineState> texture_read_2d_array_get_kernel(
467 id<MTLComputePipelineState> texture_read_3d_get_kernel(
470 id<MTLComputePipelineState> mtl_texture_read_impl(
473 &specialization_cache,
479 MEM_CXX_CLASS_ALLOC_FUNCS(
"MTLTexture")
484 id<MTLBuffer> buffer_ = nil;
490 void *
map()
override;
491 void unmap()
override;
497 MEM_CXX_CLASS_ALLOC_FUNCS(
"MTLPixelBuffer")
563 return MTLTextureType1D;
565 return MTLTextureType2D;
567 return MTLTextureType3D;
569 return MTLTextureTypeCube;
571 return MTLTextureTypeTextureBuffer;
573 return MTLTextureType1DArray;
575 return MTLTextureType2DArray;
577 return MTLTextureTypeCubeArray;
581 return MTLTextureType2D;
589 case MTLPixelFormatRGBA8Unorm_sRGB:
590 case MTLPixelFormatBGRA8Unorm_sRGB:
591 case MTLPixelFormatDepth16Unorm:
592 case MTLPixelFormatDepth32Float:
593 case MTLPixelFormatDepth32Float_Stencil8:
594 case MTLPixelFormatBGR10A2Unorm:
595 case MTLPixelFormatDepth24Unorm_Stencil8:
608 case MTLPixelFormatRGBA8Unorm_sRGB:
609 return MTLPixelFormatRGBA8Unorm;
610 case MTLPixelFormatBGRA8Unorm_sRGB:
611 return MTLPixelFormatBGRA8Unorm;
612 case MTLPixelFormatDepth16Unorm:
613 return MTLPixelFormatR16Unorm;
614 case MTLPixelFormatDepth32Float:
615 return MTLPixelFormatR32Float;
616 case MTLPixelFormatDepth32Float_Stencil8:
620 return MTLPixelFormatInvalid;
621 case MTLPixelFormatBGR10A2Unorm:
625 return MTLPixelFormatInvalid;
626 case MTLPixelFormatDepth24Unorm_Stencil8:
630 return MTLPixelFormatInvalid;
639 MTLTextureUsage mtl_usage = MTLTextureUsageUnknown;
641 return MTLTextureUsageUnknown;
646 mtl_usage = mtl_usage | MTLTextureUsageShaderRead;
649 mtl_usage = mtl_usage | MTLTextureUsageShaderWrite;
652 mtl_usage = mtl_usage | MTLTextureUsageRenderTarget;
655 mtl_usage = mtl_usage | MTLTextureUsagePixelFormatView;
657#if defined(MAC_OS_VERSION_14_0)
658 if (@available(macOS 14.0, *)) {
660 mtl_usage = mtl_usage | MTLTextureUsageShaderAtomic;
670 if (mtl_usage == MTLTextureUsageUnknown) {
673 if (mtl_usage & MTLTextureUsageShaderRead) {
676 if (mtl_usage & MTLTextureUsageShaderWrite) {
679 if (mtl_usage & MTLTextureUsageRenderTarget) {
682 if (mtl_usage & MTLTextureUsagePixelFormatView) {
#define BLI_assert_unreachable()
@ 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.
struct GPUShader GPUShader
void reset()
clear internal cached data and reset random seed
id< MTLBuffer > get_metal_buffer()
size_t get_size() override
MTLPixelBuffer(size_t size)
int64_t get_native_handle() override
uint gl_bindcode_get() const override
bool has_custom_swizzle()
void * read(int mip, eGPUDataFormat type) override
void copy_to(Texture *dst) override
void update_sub(int mip, int offset[3], int extent[3], eGPUDataFormat type, const void *data) override
const int * get_texture_metdata_ptr() const
MTLTexture(const char *name)
void clear(eGPUDataFormat format, const void *data) override
MTLStorageBuf * get_storagebuf()
void mip_range_set(int min, int max) override
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]
@ 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(eGPUTextureFormat 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(eGPUTextureType type)
bool mtl_format_supports_blending(MTLPixelFormat format)
eGPUTextureUsage gpu_usage_from_mtl(MTLTextureUsage mtl_usage)
unsigned __int64 uint64_t
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