Blender V4.5
mtl_texture.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_assert.h"
12#include "BLI_map.hh"
13#include "GPU_texture.hh"
14#include "MEM_guardedalloc.h"
15
17
18#include <mutex>
19#include <string>
20#include <thread>
21
22#include <Cocoa/Cocoa.h>
23#include <Metal/Metal.h>
24#include <QuartzCore/QuartzCore.h>
25
26@class CAMetalLayer;
27@class MTLCommandQueue;
28@class MTLRenderPipelineState;
29
30struct GPUFrameBuffer;
31
32/* Texture Update system structs. */
34
35 /* The METAL type of data in input array, e.g. half, float, short, int */
36 std::string input_data_type;
37
38 /* The type of the texture data texture2d<T,..>, e.g. T=float, half, int etc. */
39 std::string output_data_type;
40
41 /* Number of image channels provided in input texture data array (min=1, max=4). */
43
44 /* Number of channels the destination texture has (min=1, max=4). */
46
47 /* Whether the update routine is a clear, and only the first texel of the input data buffer will
48 * be read. */
50
59
60 uint64_t hash() const
61 {
63 return (uint64_t)string_hasher(this->input_data_type + this->output_data_type +
64 std::to_string((this->component_count_input << 9) |
65 (this->component_count_output << 5) |
66 (this->is_clear ? 1 : 0)));
67 }
68};
69
70/* Type of data is being written to the depth target:
71 * 0 = floating point (0.0 - 1.0)
72 * 1 = 24 bit integer (0 - 2^24)
73 * 2 = 32 bit integer (0 - 2^32) */
74
80
83
85 {
86 return ((data_mode == other.data_mode));
87 }
88
89 uint64_t hash() const
90 {
91 return (uint64_t)(this->data_mode);
92 }
93};
94
95/* Texture Read system structs. */
97 std::string input_data_type;
98 std::string output_data_type;
101
102 /* Format for depth data.
103 * 0 = Not a Depth format,
104 * 1 = FLOAT DEPTH,
105 * 2 = 24Bit Integer Depth,
106 * 4 = 32bit Unsigned-Integer Depth. */
108
117
119 {
121 return uint64_t(string_hasher(this->input_data_type + this->output_data_type +
122 std::to_string((this->component_count_input << 8) +
123 this->component_count_output +
124 (this->depth_format_mode << 28))));
125 }
126};
127
128namespace blender::gpu {
129
130class MTLContext;
131class MTLVertBuf;
132class MTLStorageBuf;
133class MTLBuffer;
134
135/* Metal Texture internal implementation. */
136static const int MTL_MAX_MIPMAP_COUNT = 15; /* Max: 16384x16384 */
137static const int MTL_MAX_FBO_ATTACHED = 16;
138
139/* Samplers */
142
143 /* Mip min and mip max on sampler state always the same.
144 * Level range now controlled with textureView to be consistent with GL baseLevel. */
145 bool operator==(const MTLSamplerState &other) const
146 {
147 /* Add other parameters as needed. */
148 return (this->state == other.state);
149 }
150
151 operator uint() const
152 {
153 uint integer_representation = 0;
154 integer_representation |= this->state.filtering;
155 integer_representation |= this->state.extend_x << 8;
156 integer_representation |= this->state.extend_yz << 12;
157 integer_representation |= this->state.custom_type << 16;
158 integer_representation |= this->state.type << 24;
159 return integer_representation;
160 }
161
162 operator uint64_t() const
163 {
164 uint64_t integer_representation = 0;
165 integer_representation |= this->state.filtering;
166 integer_representation |= this->state.extend_x << 8;
167 integer_representation |= this->state.extend_yz << 12;
168 integer_representation |= this->state.custom_type << 16;
169 integer_representation |= this->state.type << 24;
170 return integer_representation;
171 }
172};
173
175
176class MTLTexture : public Texture {
177 friend class MTLContext;
178 friend class MTLStateManager;
179 friend class MTLFrameBuffer;
180 friend class MTLStorageBuf;
181
182 private:
183 /* Where the textures data comes from. */
184 enum {
185 MTL_TEXTURE_MODE_DEFAULT, /* Texture is self-initialized (Standard). */
186 MTL_TEXTURE_MODE_EXTERNAL, /* Texture source from external id<MTLTexture> handle */
187 MTL_TEXTURE_MODE_VBO, /* Texture source initialized from VBO */
188 MTL_TEXTURE_MODE_TEXTURE_VIEW /* Texture is a view into an existing texture. */
189 } resource_mode_;
190
191 /* 'baking' refers to the generation of GPU-backed resources. This flag ensures GPU resources are
192 * ready. Baking is generally deferred until as late as possible, to ensure all associated
193 * resource state has been specified up-front. */
194 bool is_baked_ = false;
195 MTLTextureDescriptor *texture_descriptor_ = nullptr;
196 id<MTLTexture> texture_ = nil;
197
198 /* Texture Storage. */
199 size_t aligned_w_ = 0;
200
201 /* Storage buffer view.
202 * Buffer backed textures can be wrapped with a storage buffer instance for direct data
203 * reading/writing. Required for atomic operations on texture data when texture atomics are
204 * unsupported.
205 *
206 * tex_buffer_metadata_ packs 4 parameters required by the shader to perform texture space
207 * remapping: (x, y, z) = (width, height, depth/layers) (w) = aligned width. */
208 MTLBuffer *backing_buffer_ = nullptr;
209 MTLStorageBuf *storage_buffer_ = nullptr;
210 int tex_buffer_metadata_[4];
211
212 /* Blit Frame-buffer. */
213 GPUFrameBuffer *blit_fb_ = nullptr;
214 uint blit_fb_slice_ = 0;
215 uint blit_fb_mip_ = 0;
216
217 /* Non-SRGB texture view, used for when a framebuffer is bound with SRGB disabled. */
218 id<MTLTexture> texture_no_srgb_ = nil;
219
220 /* Texture view properties */
221 /* In Metal, we use texture views to either limit mipmap ranges,
222 * , apply a swizzle mask, or both.
223 *
224 * We apply the mip limit in the view rather than in the sampler, as
225 * certain effects and functionality such as textureSize rely on the base level
226 * being modified.
227 *
228 * Texture views can also point to external textures, rather than the owned
229 * texture if MTL_TEXTURE_MODE_TEXTURE_VIEW is used.
230 * If this mode is used, source_texture points to a GPUTexture from which
231 * we pull their texture handle as a root.
232 */
233 const GPUTexture *source_texture_ = nullptr;
234
235 enum TextureViewDirtyState {
236 TEXTURE_VIEW_NOT_DIRTY = 0,
237 TEXTURE_VIEW_SWIZZLE_DIRTY = (1 << 0),
238 TEXTURE_VIEW_MIP_DIRTY = (1 << 1)
239 };
240 id<MTLTexture> mip_swizzle_view_ = nil;
241 char tex_swizzle_mask_[4];
242 MTLTextureSwizzleChannels mtl_swizzle_mask_;
243 bool mip_range_dirty_ = false;
244
245 bool texture_view_stencil_ = false;
246 int mip_texture_base_level_ = 0;
247 int mip_texture_max_level_ = 1000;
248 int mip_texture_base_layer_ = 0;
249 int texture_view_dirty_flags_ = TEXTURE_VIEW_NOT_DIRTY;
250
251 /* Max mip-maps for currently allocated texture resource. */
252 int mtl_max_mips_ = 1;
253 bool has_generated_mips_ = false;
254
255 /* We may modify the requested usage flags so store them separately. */
256 eGPUTextureUsage internal_gpu_image_usage_flags_;
257
258 /* VBO. */
259 MTLVertBuf *vert_buffer_;
260 id<MTLBuffer> vert_buffer_mtl_;
261
262 /* Whether the texture's properties or state has changed (e.g. mipmap range), and re-baking of
263 * GPU resource is required. */
264 bool is_dirty_;
265 bool is_bound_;
266
267 public:
268 MTLTexture(const char *name);
269 MTLTexture(const char *name,
271 eGPUTextureType type,
272 id<MTLTexture> metal_texture);
273 ~MTLTexture() override;
274
275 void update_sub(
276 int mip, int offset[3], int extent[3], eGPUDataFormat type, const void *data) override;
277 void update_sub(int offset[3],
278 int extent[3],
280 GPUPixelBuffer *pixbuf) override;
281
282 void generate_mipmap() override;
283 void copy_to(Texture *dst) override;
284 void clear(eGPUDataFormat format, const void *data) override;
285 void swizzle_set(const char swizzle_mask[4]) override;
286 void mip_range_set(int min, int max) override;
287 void *read(int mip, eGPUDataFormat type) override;
288
289 /* Remove once no longer required -- will just return 0 for now in MTL path. */
290 uint gl_bindcode_get() const override;
291
292 bool is_format_srgb();
293 bool texture_is_baked();
294 const char *get_name()
295 {
296 return name_;
297 }
298
300 {
301 return (mtl_swizzle_mask_.red != MTLTextureSwizzleRed ||
302 mtl_swizzle_mask_.green != MTLTextureSwizzleGreen ||
303 mtl_swizzle_mask_.blue != MTLTextureSwizzleBlue ||
304 mtl_swizzle_mask_.alpha != MTLTextureSwizzleAlpha);
305 }
306
307 id<MTLBuffer> get_vertex_buffer() const
308 {
309 if (resource_mode_ == MTL_TEXTURE_MODE_VBO) {
310 return vert_buffer_mtl_;
311 }
312 return nil;
313 }
314
316
317 const int *get_texture_metadata_ptr() const
318 {
319 return tex_buffer_metadata_;
320 }
321
322 protected:
323 bool init_internal() override;
324 bool init_internal(VertBuf *vbo) override;
325 bool init_internal(GPUTexture *src,
326 int mip_offset,
327 int layer_offset,
328 bool use_stencil) override; /* Texture View */
329
330 private:
331 /* Common Constructor, default initialization. */
332 void mtl_texture_init();
333
334 /* Post-construction and member initialization, prior to baking.
335 * Called during init_internal */
336 void prepare_internal();
337
338 /* Generate Metal GPU resources and upload data if needed */
339 void ensure_baked();
340
341 /* Delete associated Metal GPU resources. */
342 void reset();
343 void ensure_mipmaps(int miplvl);
344
345 /* Flags a given mip level as being used. */
346 void add_subresource(uint level);
347
348 void read_internal(int mip,
349 int x_off,
350 int y_off,
351 int z_off,
352 int width,
353 int height,
354 int depth,
355 eGPUDataFormat desired_output_format,
356 int num_output_components,
357 size_t debug_data_size,
358 void *r_data);
359 void bake_mip_swizzle_view();
360
361 id<MTLTexture> get_metal_handle();
362 id<MTLTexture> get_metal_handle_base();
363 id<MTLTexture> get_non_srgb_handle();
364 MTLSamplerState get_sampler_state();
365 void blit(id<MTLBlitCommandEncoder> blit_encoder,
366 uint src_x_offset,
367 uint src_y_offset,
368 uint src_z_offset,
369 uint src_slice,
370 uint src_mip,
371 gpu::MTLTexture *dst,
372 uint dst_x_offset,
373 uint dst_y_offset,
374 uint dst_z_offset,
375 uint dst_slice,
376 uint dst_mip,
377 uint width,
378 uint height,
379 uint depth);
380 void blit(gpu::MTLTexture *dst,
381 uint src_x_offset,
382 uint src_y_offset,
383 uint dst_x_offset,
384 uint dst_y_offset,
385 uint src_mip,
386 uint dst_mip,
387 uint dst_slice,
388 int width,
389 int height);
390 GPUFrameBuffer *get_blit_framebuffer(int dst_slice, uint dst_mip);
391 /* Texture Update function Utilities. */
392 /* Metal texture updating does not provide the same range of functionality for type conversion
393 * and format compatibility as are available in OpenGL. To achieve the same level of
394 * functionality, we need to instead use compute kernels to perform texture data conversions
395 * where appropriate.
396 * There are a number of different inputs which affect permutations and thus require different
397 * shaders and PSOs, such as:
398 * - Texture format
399 * - Texture type (e.g. 2D, 3D, 2D Array, Depth etc;)
400 * - Source data format and component count (e.g. floating point)
401 *
402 * MECHANISM:
403 *
404 * blender::map<INPUT DEFINES STRUCT, compute PSO> update_2d_array_kernel_psos;
405 * - Generate compute shader with configured kernel below with variable parameters depending
406 * on input/output format configurations. Do not need to keep source or descriptors around,
407 * just PSO, as same input defines will always generate the same code.
408 *
409 * - IF datatype IS an exact match e.g. :
410 * - Per-component size matches (e.g. GPU_DATA_UBYTE)
411 * OR GPU_DATA_10_11_11_REV && GPU_R11G11B10 (equiv)
412 * OR D24S8 and GPU_DATA_UINT_24_8
413 * We can use BLIT ENCODER.
414 *
415 * OTHERWISE TRIGGER COMPUTE:
416 * - Compute sizes will vary. Threads per grid WILL match 'extent'.
417 * Dimensions will vary depending on texture type.
418 * - Will use setBytes with 'TextureUpdateParams' struct to pass in useful member params.
419 */
420 struct TextureUpdateParams {
421 int mip_index;
422 int extent[3]; /* Width, Height, Slice on 2D Array tex. */
423 int offset[3]; /* Width, Height, Slice on 2D Array tex. */
424 uint unpack_row_length; /* Number of pixels between bytes in input data. */
425 };
426
427 id<MTLComputePipelineState> texture_update_1d_get_kernel(
429 id<MTLComputePipelineState> texture_update_1d_array_get_kernel(
431 id<MTLComputePipelineState> texture_update_2d_get_kernel(
433 id<MTLComputePipelineState> texture_update_2d_array_get_kernel(
435 id<MTLComputePipelineState> texture_update_3d_get_kernel(
437
438 id<MTLComputePipelineState> mtl_texture_update_impl(
439 TextureUpdateRoutineSpecialisation specialization_params,
440 blender::Map<TextureUpdateRoutineSpecialisation, id<MTLComputePipelineState>>
441 &specialization_cache,
442 eGPUTextureType texture_type);
443
444 /* Depth Update Utilities */
445 /* Depth texture updates are not directly supported with Blit operations, similarly, we cannot
446 * use a compute shader to write to depth, so we must instead render to a depth target.
447 * These processes use vertex/fragment shaders to render texture data from an intermediate
448 * source, in order to prime the depth buffer. */
449 GPUShader *depth_2d_update_sh_get(DepthTextureUpdateRoutineSpecialisation specialization);
450
451 void update_sub_depth_2d(
452 int mip, int offset[3], int extent[3], eGPUDataFormat type, const void *data);
453
454 /* Texture Read function utilities -- Follows a similar mechanism to the updating routines */
455 struct TextureReadParams {
456 int mip_index;
457 int extent[3]; /* Width, Height, Slice on 2D Array tex. */
458 int offset[3]; /* Width, Height, Slice on 2D Array tex. */
459 };
460
461 id<MTLComputePipelineState> texture_read_1d_get_kernel(
462 TextureReadRoutineSpecialisation specialization);
463 id<MTLComputePipelineState> texture_read_1d_array_get_kernel(
464 TextureReadRoutineSpecialisation specialization);
465 id<MTLComputePipelineState> texture_read_2d_get_kernel(
466 TextureReadRoutineSpecialisation specialization);
467 id<MTLComputePipelineState> texture_read_2d_array_get_kernel(
468 TextureReadRoutineSpecialisation specialization);
469 id<MTLComputePipelineState> texture_read_3d_get_kernel(
470 TextureReadRoutineSpecialisation specialization);
471
472 id<MTLComputePipelineState> mtl_texture_read_impl(
473 TextureReadRoutineSpecialisation specialization_params,
474 blender::Map<TextureReadRoutineSpecialisation, id<MTLComputePipelineState>>
475 &specialization_cache,
476 eGPUTextureType texture_type);
477
478 /* fullscreen blit utilities. */
479 GPUShader *fullscreen_blit_sh_get();
480
481 MEM_CXX_CLASS_ALLOC_FUNCS("MTLTexture")
482};
483
485 private:
486 id<MTLBuffer> buffer_ = nil;
487
488 public:
489 MTLPixelBuffer(size_t size);
491
492 void *map() override;
493 void unmap() override;
495 size_t get_size() override;
496
497 id<MTLBuffer> get_metal_buffer();
498
499 MEM_CXX_CLASS_ALLOC_FUNCS("MTLPixelBuffer")
500};
501
502/* Utility */
503MTLPixelFormat gpu_texture_format_to_metal(eGPUTextureFormat tex_format);
504size_t get_mtl_format_bytesize(MTLPixelFormat tex_format);
505int get_mtl_format_num_components(MTLPixelFormat tex_format);
506bool mtl_format_supports_blending(MTLPixelFormat format);
507
508/* The type used to define the per-component data in the input buffer. */
510{
511 switch (type) {
512 case GPU_DATA_FLOAT:
513 return "float";
515 return "half";
516 case GPU_DATA_INT:
517 return "int";
518 case GPU_DATA_UINT:
519 return "uint";
520 case GPU_DATA_UBYTE:
521 return "uchar";
523 return "uint"; /* Problematic type - but will match alignment. */
526 return "float"; /* Problematic type - each component will be read as a float. */
527 default:
528 BLI_assert(false);
529 break;
530 }
531 return "";
532}
533
534/* The type T which goes into texture2d<T, access>. */
536{
537 switch (type) {
538 case GPU_DATA_FLOAT:
539 return "float";
541 return "half";
542 case GPU_DATA_INT:
543 return "int";
544 case GPU_DATA_UINT:
545 return "uint";
546 case GPU_DATA_UBYTE:
547 return "ushort";
549 return "uint"; /* Problematic type. */
552 return "float"; /* Problematic type. */
553 default:
554 BLI_assert(false);
555 break;
556 }
557 return "";
558}
559
560/* Fetch Metal texture type from GPU texture type. */
561inline MTLTextureType to_metal_type(eGPUTextureType type)
562{
563 switch (type) {
564 case GPU_TEXTURE_1D:
565 return MTLTextureType1D;
566 case GPU_TEXTURE_2D:
567 return MTLTextureType2D;
568 case GPU_TEXTURE_3D:
569 return MTLTextureType3D;
570 case GPU_TEXTURE_CUBE:
571 return MTLTextureTypeCube;
573 return MTLTextureTypeTextureBuffer;
575 return MTLTextureType1DArray;
577 return MTLTextureType2DArray;
579 return MTLTextureTypeCubeArray;
580 default:
582 }
583 return MTLTextureType2D;
584}
585
586/* Determine whether format is writable or not. Use mtl_format_get_writeable_view_format(..) for
587 * these. */
588inline bool mtl_format_is_writable(MTLPixelFormat format)
589{
590 switch (format) {
591 case MTLPixelFormatRGBA8Unorm_sRGB:
592 case MTLPixelFormatBGRA8Unorm_sRGB:
593 case MTLPixelFormatDepth16Unorm:
594 case MTLPixelFormatDepth32Float:
595 case MTLPixelFormatDepth32Float_Stencil8:
596 case MTLPixelFormatBGR10A2Unorm:
597 case MTLPixelFormatDepth24Unorm_Stencil8:
598 return false;
599 default:
600 return true;
601 }
602 return true;
603}
604
605/* For the cases where a texture format is unwritable, we can create a texture view of a similar
606 * format */
607inline MTLPixelFormat mtl_format_get_writeable_view_format(MTLPixelFormat format)
608{
609 switch (format) {
610 case MTLPixelFormatRGBA8Unorm_sRGB:
611 return MTLPixelFormatRGBA8Unorm;
612 case MTLPixelFormatBGRA8Unorm_sRGB:
613 return MTLPixelFormatBGRA8Unorm;
614 case MTLPixelFormatDepth16Unorm:
615 return MTLPixelFormatR16Unorm;
616 case MTLPixelFormatDepth32Float:
617 return MTLPixelFormatR32Float;
618 case MTLPixelFormatDepth32Float_Stencil8:
619 // return MTLPixelFormatRG32Float;
620 /* No alternative mirror format. This should not be used for
621 * manual data upload */
622 return MTLPixelFormatInvalid;
623 case MTLPixelFormatBGR10A2Unorm:
624 // return MTLPixelFormatBGRA8Unorm;
625 /* No alternative mirror format. This should not be used for
626 * manual data upload */
627 return MTLPixelFormatInvalid;
628 case MTLPixelFormatDepth24Unorm_Stencil8:
629 /* No direct format, but we'll just mirror the bytes -- `Uint`
630 * should ensure bytes are not re-normalized or manipulated */
631 // return MTLPixelFormatR32Uint;
632 return MTLPixelFormatInvalid;
633 default:
634 return format;
635 }
636 return format;
637}
638
639inline MTLTextureUsage mtl_usage_from_gpu(eGPUTextureUsage usage)
640{
641 MTLTextureUsage mtl_usage = MTLTextureUsageUnknown;
642 if (usage == GPU_TEXTURE_USAGE_GENERAL) {
643 return MTLTextureUsageUnknown;
644 }
645 /* Host read implies general read support, as the compute-based host read routine requires
646 * reading of texture data. */
648 mtl_usage = mtl_usage | MTLTextureUsageShaderRead;
649 }
650 if (usage & GPU_TEXTURE_USAGE_SHADER_WRITE) {
651 mtl_usage = mtl_usage | MTLTextureUsageShaderWrite;
652 }
653 if (usage & GPU_TEXTURE_USAGE_ATTACHMENT) {
654 mtl_usage = mtl_usage | MTLTextureUsageRenderTarget;
655 }
656 if (usage & GPU_TEXTURE_USAGE_FORMAT_VIEW) {
657 mtl_usage = mtl_usage | MTLTextureUsagePixelFormatView;
658 }
659#if defined(MAC_OS_VERSION_14_0)
660 if (@available(macOS 14.0, *)) {
661 if (usage & GPU_TEXTURE_USAGE_ATOMIC) {
662 mtl_usage = mtl_usage | MTLTextureUsageShaderAtomic;
663 }
664 }
665#endif
666 return mtl_usage;
667}
668
669inline eGPUTextureUsage gpu_usage_from_mtl(MTLTextureUsage mtl_usage)
670{
672 if (mtl_usage == MTLTextureUsageUnknown) {
674 }
675 if (mtl_usage & MTLTextureUsageShaderRead) {
676 usage = usage | GPU_TEXTURE_USAGE_SHADER_READ;
677 }
678 if (mtl_usage & MTLTextureUsageShaderWrite) {
679 usage = usage | GPU_TEXTURE_USAGE_SHADER_WRITE;
680 }
681 if (mtl_usage & MTLTextureUsageRenderTarget) {
682 usage = usage | GPU_TEXTURE_USAGE_ATTACHMENT;
683 }
684 if (mtl_usage & MTLTextureUsagePixelFormatView) {
685 usage = usage | GPU_TEXTURE_USAGE_FORMAT_VIEW;
686 }
687 return usage;
688}
689
690} // namespace blender::gpu
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define BLI_assert(a)
Definition BLI_assert.h:46
unsigned int uint
eGPUDataFormat
@ GPU_DATA_HALF_FLOAT
@ GPU_DATA_UINT_24_8
@ GPU_DATA_INT
@ GPU_DATA_10_11_11_REV
@ GPU_DATA_UBYTE
@ GPU_DATA_UINT
@ GPU_DATA_2_10_10_10_REV
@ GPU_DATA_FLOAT
eGPUTextureUsage
@ 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
eGPUTextureFormat
Read Guarded memory(de)allocation.
BMesh const char void * data
unsigned long long int uint64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void reset()
clear internal cached data and reset random seed
GPUPixelBufferNativeHandle get_native_handle() override
id< MTLBuffer > get_metal_buffer()
void copy_to(Texture *dst) override
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
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
uint gl_bindcode_get() const override
char name_[DEBUG_NAME_LEN]
Texture(const char *name)
format
DepthTextureUpdateMode
@ 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)
#define min(a, b)
Definition sort.cc:36
bool operator==(const DepthTextureUpdateRoutineSpecialisation &other) const
GPUSamplerCustomType custom_type
GPUSamplerExtendMode extend_yz
static constexpr GPUSamplerState default_sampler()
GPUSamplerFiltering filtering
GPUSamplerExtendMode extend_x
GPUSamplerStateType type
bool operator==(const TextureReadRoutineSpecialisation &other) const
bool operator==(const TextureUpdateRoutineSpecialisation &other) const
bool operator==(const MTLSamplerState &other) const
read
max
Definition text_draw.cc:251