Blender V5.3
mtl_shader.mm
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <fmt/ranges.h>
10
11#include "BKE_global.hh"
12
13#include "DNA_userdef_types.h"
14
15#include "BLI_string.hh"
16#include "BLI_time.hh"
17
18#include <algorithm>
19#include <fmt/format.h>
20#include <fstream>
21#include <iostream>
22#include <map>
23#include <mutex>
24#include <regex>
25#include <sstream>
26#include <string>
27
28#include <cstring>
29
30#include "GPU_platform.hh"
31#include "GPU_vertex_format.hh"
32
34#include "mtl_common.hh"
35#include "mtl_context.hh"
36#include "mtl_debug.hh"
38#include "mtl_shader.hh"
41#include "mtl_shader_log.hh"
42#include "mtl_texture.hh"
43#include "mtl_vertex_buffer.hh"
44
45using namespace blender::gpu;
46using namespace blender::gpu::shader;
47
48namespace blender::gpu {
49
50static CLG_LogRef LOG = {"gpu.metal"};
51
52const char *to_string(ShaderStage stage)
53{
54 switch (stage) {
56 return "Vertex Shader";
58 return "Fragment Shader";
60 return "Compute Shader";
62 break;
63 }
64 return "Unknown Shader Stage";
65}
66
67std::string shader_stage_define(const ShaderStage stage)
68{
69 std::string define = "#define ";
70 switch (stage) {
72 define += "GPU_VERTEX_SHADER";
73 break;
75 define += "GPU_FRAGMENT_SHADER";
76 break;
78 define += "GPU_COMPUTE_SHADER";
79 break;
80 default:
82 }
83 return define;
84}
85
86/* -------------------------------------------------------------------- */
89
90/* Create empty shader to be populated later. */
92{
93 context_ = ctx;
94}
95
97{
98 if (this->is_valid()) {
99 /* Free uniform data block. */
100 MEM_SAFE_DELETE(push_constant_buf_);
101
102 /* Free Metal resources.
103 * This is done in the order of:
104 * 1. PipelineState objects
105 * 2. MTLFunctions
106 * 3. MTLLibraries
107 * So that each object releases it's references to the one following it. */
108 if (pso_descriptor_ != nil) {
109 [pso_descriptor_ release];
110 pso_descriptor_ = nil;
111 }
112
113 /* Free Pipeline Cache. */
114 pso_cache_lock_.lock();
115 for (const MTLRenderPipelineStateInstance *pso_inst : pso_cache_.values()) {
116 /* Free pipeline state object. */
117 if (pso_inst->pso) {
118 [pso_inst->pso release];
119 }
120 /* Free vertex function. */
121 if (pso_inst->vert) {
122 [pso_inst->vert release];
123 }
124 /* Free fragment function. */
125 if (pso_inst->frag) {
126 [pso_inst->frag release];
127 }
128 delete pso_inst;
129 }
130 pso_cache_.clear();
131
132 /* Free Compute pipeline cache. */
133 for (const MTLComputePipelineStateInstance *pso_inst : compute_pso_cache_.values()) {
134 /* Free pipeline state object. */
135 if (pso_inst->pso) {
136 [pso_inst->pso release];
137 }
138 /* Free compute function. */
139 if (pso_inst->compute) {
140 [pso_inst->compute release];
141 }
142 }
143 compute_pso_cache_.clear();
144 pso_cache_lock_.unlock();
145
146 /* Free shader libraries. */
147 if (shader_library_vert_ != nil) {
148 [shader_library_vert_ release];
149 shader_library_vert_ = nil;
150 }
151 if (shader_library_frag_ != nil) {
152 [shader_library_frag_ release];
153 shader_library_frag_ = nil;
154 }
155 if (shader_library_comp_ != nil) {
156 [shader_library_comp_ release];
157 shader_library_comp_ = nil;
158 }
159
160 /* NOTE(Metal): #ShaderInterface deletion is handled in the super destructor `~Shader()`. */
161 }
162 valid_ = false;
163}
164
166 const shader::ShaderCreateInfo &original_info)
167{
168 if (!MTLBackend::get_capabilities().supports_texture_atomics) {
169 /* This function can lazily create the patched_info_. */
171 }
172
173 if (original_info.max_sampler_slot() >= 16) {
174 if (patched_info_ == nullptr) {
175 patched_info_ = std::make_unique<PatchedShaderCreateInfo>(original_info);
176 }
178 }
179
180 return patched_info_ != nullptr ? patched_info_->info : original_info;
181}
182
184
185/* -------------------------------------------------------------------- */
188
189std::string MTLShader::entry_point_name_get(const ShaderStage stage)
190{
191 std::string name = this->name_get();
192 /* Escape the shader name to be able to use it inside an identifier. */
193 for (char &c : name) {
194 if (!std::isalnum(c)) {
195 c = '_';
196 }
197 }
198
199 switch (stage) {
201 return "_" + name + "_vert";
203 return "_" + name + "_frag";
205 return "_" + name + "_comp";
206 default:
208 return "";
209 }
210}
211
212/* Note: returns a retained object. */
213static ::MTLCompileOptions *get_compile_options(const bool use_subpass_input,
214 const bool use_texture_atomic,
215 const bool use_ray_query)
216{
217 ::MTLCompileOptions *options = [[MTLCompileOptions alloc] init];
218 options.languageVersion = MTLLanguageVersion2_2;
219 options.fastMathEnabled = YES;
220 /* TODO(fclem): Only use this on shaders that matters. */
221 options.preserveInvariance = YES;
222 /* Raster order groups for tile data in struct require Metal 2.3.
223 * Retaining Metal 2.2. for old shaders to maintain backwards
224 * compatibility for existing features. */
225 if (use_subpass_input) {
226 options.languageVersion = MTLLanguageVersion2_3;
227 }
228 /* Inline ray queries requires Metal 3.0. */
229 if (use_ray_query) {
230 options.languageVersion = MTLLanguageVersion3_0;
231 }
232#if defined(MAC_OS_VERSION_14_0)
233 if (@available(macOS 14.0, *)) {
234 /* Texture atomics requires Metal 3.1. */
235 if (use_texture_atomic) {
236 options.languageVersion = MTLLanguageVersion3_1;
237 }
238 }
239#endif
240 return options;
241}
242
243id<MTLLibrary> MTLShader::create_shader_library(const shader::ShaderCreateInfo &info,
244 const ShaderStage stage,
246{
247 std::pair<std::string, std::string> wrapper = generate_entry_point(
248 info, stage, entry_point_name_get(stage));
249
250 std::string shader_compat;
251 {
252 std::stringstream ss;
253 /* Shader stage needs to be defined before the compat part. */
254 ss << shader_stage_define(stage) << "\n";
255 ss << "#define MTL_WORKGROUP_SIZE_X " << info.compute_layout_.local_size_x << "\n";
256 ss << "#define MTL_WORKGROUP_SIZE_Y " << info.compute_layout_.local_size_y << "\n";
257 ss << "#define MTL_WORKGROUP_SIZE_Z " << info.compute_layout_.local_size_z << "\n";
258 ss << "#define GPU_PROVOKING_VERTEX_LAST\n";
260 ss << "#define MTL_USE_SAMPLER_ARGUMENT_BUFFER\n";
261 }
262
263 if (flag_is_set(info.builtins_combined(), BuiltinBits::TEXTURE_ATOMIC) &&
264 MTLBackend::get_capabilities().supports_texture_atomics)
265 {
266 ss << "#define MTL_SUPPORTS_TEXTURE_ATOMICS 1\n";
267 }
268
269 if (flag_is_set(info.builtins_combined(), BuiltinBits::RAY_QUERY)) {
270 ss << "#define MTL_USE_RAY_QUERY\n";
271 }
272
273 shader::GeneratedSource defines_src{"gpu_shader_msl_defines.msl", {}, ss.str()};
274 shader::GeneratedSource wrapper_src{
275 "gpu_shader_msl_wrapper.msl", {"gpu_shader_msl_types.msl"}, wrapper.first};
276 shader::GeneratedSourceList generated_sources{defines_src, wrapper_src};
277
278 /* Concatenate common source. */
279 Vector<StringRefNull> compatibility_src = gpu_shader_dependency_get_resolved_source(
280 "gpu_shader_compat_msl.msl", generated_sources);
281 shader_compat = fmt::to_string(fmt::join(compatibility_src, ""));
282 }
283
284 sources[SOURCES_INDEX_VERSION] = shader_compat;
285
286 const std::string original_source = fmt::to_string(fmt::join(sources, "")) + wrapper.second;
287
289 this->name_get(), this->entry_point_name_get(stage), ".msl", original_source);
290
291 std::string processed_source;
292 if (!this->skip_preprocessor) {
293 processed_source = run_preprocessor(original_source, G.debug & G_DEBUG_GPU_SHADER_NO_DCE);
294
296 this->entry_point_name_get(stage) + ".expanded",
297 ".msl",
298 processed_source);
299 }
300 else {
301 processed_source = original_source;
302 }
303
304 /* Ray-query shaders need the Metal raytracing header prepended to the final source. */
305 if (flag_is_set(info.builtins_combined(), BuiltinBits::RAY_QUERY)) {
306 processed_source = "#include <metal_raytracing>\nusing namespace metal::raytracing;\n" +
307 processed_source;
308 }
309
310 {
311 ::MTLCompileOptions *options = get_compile_options(
312 !info.subpass_inputs_.is_empty(),
313 flag_is_set(info.builtins_combined(), BuiltinBits::TEXTURE_ATOMIC),
314 flag_is_set(info.builtins_combined(), BuiltinBits::RAY_QUERY));
315
316 NSError *error = nullptr;
317 id<MTLLibrary> library = [context_->device
318 newLibraryWithSource:[NSString stringWithUTF8String:processed_source.c_str()]
320 error:&error];
321 library.label = [NSString stringWithUTF8String:this->name];
322
323 [options release];
324
325 if (error == nullptr) {
326 return library;
327 }
328
329 NSString *error_localized = [error localizedDescription];
330
331 /* Only fail if genuine error and not warning. */
332 if ([error_localized rangeOfString:@"Compilation succeeded"].length > 0) {
333 /* TODO(fclem): Add option to display warning. */
334 return library;
335 }
336
337 [library release];
338
339 MTLLogParser parser;
340 print_log({original_source}, [error_localized UTF8String], to_string(stage), true, &parser);
341 }
342 return nil;
343}
344
347{
348 shader_library_vert_ = create_shader_library(info, ShaderStage::VERTEX, sources);
349}
350
352 MutableSpan<StringRefNull> /*sources*/)
353{
354 MTL_LOG_ERROR("MTLShader::geometry_shader_from_glsl - Geometry shaders unsupported!");
355}
356
359{
360 shader_library_frag_ = create_shader_library(info, ShaderStage::FRAGMENT, sources);
361}
362
365{
366 shader_library_comp_ = create_shader_library(info, ShaderStage::COMPUTE, sources);
367}
368
370{
371 /* Check if Shader has already been finalized. */
372 if (this->is_valid()) {
373 MTL_LOG_ERROR("Shader (%p) '%s' has already been finalized!", this, this->name_get().c_str());
374 return false;
375 }
376
377 if (this->shader_library_vert_ == nil && this->shader_library_frag_ == nil &&
378 this->shader_library_comp_ == nil)
379 {
380 /* All compilations failed. */
381 return false;
382 }
383
384 const bool is_compute = (this->shader_library_vert_ == nil && this->shader_library_frag_ == nil);
385
386 if (!is_compute && (this->shader_library_vert_ == nil || this->shader_library_frag_ == nil)) {
387 /* One stage failed to compile. */
388 return false;
389 }
390
391 /* Prepare backing data storage for local uniforms. */
392 if (info->push_constants_.is_empty() == false) {
393 push_constant_buf_ = MEM_new<MTLPushConstantBuf>("MTLPushConstantBuf", *info);
394 }
395
396 /* Ensure we have a valid shader interface. */
397 this->interface = new MTLShaderInterface(this->name, *info, push_constant_buf_);
398
399 /* Shader has successfully been created. */
400 valid_ = true;
401
402 if (is_compute) {
403 /* If this is a compute shader, bake base PSO for compute straight-away.
404 * NOTE: This will compile the base unspecialized variant. */
405
406 this->compute_pso_common_state_.set_compute_workgroup_size(info->compute_layout_.local_size_x,
409
410 /* Set descriptor to default shader constants */
411 MTLComputePipelineStateDescriptor compute_pipeline_descriptor(this->constants->values);
412
413 this->bake_compute_pipeline_state(context_, compute_pipeline_descriptor);
414 }
415 else {
416 /* Prepare Render pipeline descriptor. */
417 pso_descriptor_ = [[MTLRenderPipelineDescriptor alloc] init];
418 pso_descriptor_.label = [NSString stringWithUTF8String:this->name];
419 }
420
421 return true;
422}
423
425
426/* -------------------------------------------------------------------- */
429
431{
433 /* Copy constants state. */
434 ctx->specialization_constants_set(constants_state);
435
436 if (interface == nullptr || !this->is_valid()) {
438 "MTLShader::bind - Shader '%s' has no valid implementation in Metal, draw calls will be "
439 "skipped.",
440 this->name_get().c_str());
441 }
442 ctx->pipeline_state.active_shader = this;
443}
444
446{
448 ctx->pipeline_state.active_shader = nullptr;
449}
450
451void MTLShader::uniform_float(int location, int comp_len, int array_size, const float *data)
452{
453 BLI_assert(this);
454 if (!this->is_valid()) {
455 return;
456 }
457
458 if (push_constant_buf_ == nullptr || location < 0 || location >= push_constant_buf_->size()) {
459 MTL_LOG_WARNING("Shader %s: Invalid uniform location %d", this->name, location);
460 return;
461 }
462
463 if (comp_len == 9) {
464 /* Convert float3x3 case into float3[3] case. They have the same alignment. */
465 comp_len = 3;
466 array_size *= 3;
467 }
468 else if (comp_len == 16) {
469 /* Convert float4x4 case into float4[4] case. They have the same alignment. */
470 comp_len = 4;
471 array_size *= 4;
472 }
473 else {
474 /* Input and output are both packed. Convert to a 1 iteration assignment below. */
475 comp_len *= array_size;
476 array_size = 1;
477 }
478
479 /* It is more efficient on the host to only modify data if it has changed.
480 * Data modifications are small, so memory comparison is cheap.
481 * If uniforms have remained unchanged, then we avoid both copying
482 * data into the local uniform struct, and upload of the modified uniform
483 * contents in the command stream. */
484 bool update = false;
485
486 /* float3 is 16 bytes on Metal. This is the only case where we need this iteration. */
487 constexpr int size_padded = 16;
488 const size_t data_size = comp_len * sizeof(float);
489 for (int i : IndexRange(array_size)) {
490 const void *src = data + i * comp_len;
491 void *dst = push_constant_buf_->data() + (location + i * size_padded);
492 if (update || memcmp(dst, src, data_size) != 0) {
493 memcpy(dst, src, data_size);
494 update = true;
495 }
496 }
497
498 if (update) {
499 push_constant_buf_->tag_dirty();
500 }
501}
502
503void MTLShader::uniform_int(int location, int comp_len, int array_size, const int *data)
504{
505 static_assert(sizeof(int) == sizeof(float), "int to float reinterpret expect matching size");
506 uniform_float(location, comp_len, array_size, reinterpret_cast<const float *>(data));
507}
508
509/* Attempts to pre-generate a PSO based on the parent shaders PSO
510 * (Material shaders only) */
512{
513 if (parent_shader_ != nullptr) {
515 MTLShader *parent_mtl = static_cast<MTLShader *>(parent_shader_);
516
517 /* Extract PSO descriptors from parent shader. */
520
521 parent_mtl->pso_cache_lock_.lock();
522 for (const auto &pso_entry : parent_mtl->pso_cache_.items()) {
523 const MTLRenderPipelineStateDescriptor &pso_descriptor = pso_entry.key;
524 const MTLRenderPipelineStateInstance *pso_inst = pso_entry.value;
525 descriptors.append(pso_descriptor);
526 prim_classes.append(pso_inst->prim_type);
527 }
528 parent_mtl->pso_cache_lock_.unlock();
529
530 /* Warm shader cache with applied limit.
531 * If limit is <= 0, compile all PSO permutations. */
532 limit = (limit > 0) ? limit : descriptors.size();
533 for (int i : IndexRange(min_ii(descriptors.size(), limit))) {
534 const MTLRenderPipelineStateDescriptor &pso_descriptor = descriptors[i];
535 const MTLPrimitiveTopologyClass &prim_class = prim_classes[i];
536 bake_graphic_pipeline_state(ctx, prim_class, pso_descriptor);
537 }
538 }
539}
540
542
543/* -------------------------------------------------------------------- */
547
554static ::MTLFunctionConstantValues *populate_specialization_constant_values(
555 const shader::SpecializationConstants &shader_constants,
556 const SpecializationStateDescriptor &specialization_descriptor)
557{
558 ::MTLFunctionConstantValues *values = [MTLFunctionConstantValues new];
559
560 for (auto i : shader_constants.types.index_range()) {
561 const shader::SpecializationConstant::Value &value = specialization_descriptor.values[i];
562
564 switch (shader_constants.types[i]) {
565 case Type::int_t:
566 [values setConstantValue:&value.i type:MTLDataTypeInt atIndex:index];
567 break;
568 case Type::uint_t:
569 [values setConstantValue:&value.u type:MTLDataTypeUInt atIndex:index];
570 break;
571 case Type::bool_t:
572 [values setConstantValue:&value.u type:MTLDataTypeBool atIndex:index];
573 break;
574 case Type::float_t:
575 [values setConstantValue:&value.f type:MTLDataTypeFloat atIndex:index];
576 break;
577 default:
578 BLI_assert_msg(false, "Unsupported custom constant type.");
579 break;
580 }
581 }
582 return values;
583}
584
585
586/* -------------------------------------------------------------------- */
589
590static uint32_t get_buffers_binding_mask(NSArray<MTLArgument *> *args)
591{
592 uint32_t mask = 0u;
593 for (int i = 0; i < [args count]; i++) {
594 MTLArgument *arg = [args objectAtIndex:i];
595 if ([arg type] == MTLArgumentTypeBuffer && [arg isActive] == TRUE) {
596 int index = [arg index];
597 if (index >= 0 && index < MTL_MAX_BUFFER_BINDINGS) {
598 mask |= (1 << index);
599 }
600 }
601 }
602 return mask;
603}
604
605static uint16_t get_images_binding_mask(NSArray<MTLArgument *> *args)
606{
607 uint16_t mask = 0u;
608 for (int i = 0; i < [args count]; i++) {
609 MTLArgument *arg = [args objectAtIndex:i];
610 if ([arg type] == MTLArgumentTypeTexture && [arg isActive] == TRUE) {
611 int index = [arg index];
612 if (index >= 0 && index < MTL_MAX_IMAGE_SLOTS) {
613 mask |= (1 << index);
614 }
615 }
616 }
617 return mask;
618}
619
620static uint64_t get_samplers_binding_mask(NSArray<MTLArgument *> *args)
621{
622 uint64_t mask = 0u;
623 for (int i = 0; i < [args count]; i++) {
624 MTLArgument *arg = [args objectAtIndex:i];
625 if ([arg type] == MTLArgumentTypeTexture && [arg isActive] == TRUE) {
626 int index = [arg index];
628 mask |= (1 << (index - MTL_MAX_IMAGE_SLOTS));
629 }
630 }
631 }
632 return mask;
633}
634
636 MTLRenderPipelineReflection *reflection_data)
637{
638 /* Extract shader reflection data for buffer bindings.
639 * This reflection data is used to contrast the binding information
640 * we know about in the interface against the bindings in the finalized
641 * PSO. This accounts for bindings which have been stripped out during
642 * optimization, and allows us to both avoid over-binding and also
643 * allows us to verify size-correctness for bindings, to ensure
644 * that buffers bound are not smaller than the size of expected data. */
645 this->used_buf_vert_mask = get_buffers_binding_mask([reflection_data vertexArguments]);
646 this->used_buf_frag_mask = get_buffers_binding_mask([reflection_data fragmentArguments]);
647
648 this->used_ima_vert_mask = get_images_binding_mask([reflection_data vertexArguments]);
649 this->used_ima_frag_mask = get_images_binding_mask([reflection_data fragmentArguments]);
650
651 this->used_tex_vert_mask = get_samplers_binding_mask([reflection_data vertexArguments]);
652 this->used_tex_frag_mask = get_samplers_binding_mask([reflection_data fragmentArguments]);
653}
654
668 MTLContext *ctx, MTLPrimitiveTopologyClass prim_type)
669{
671 /* NOTE(Metal): PSO cache can be accessed from multiple threads, though these operations should
672 * be thread-safe due to organization of high-level renderer. If there are any issues, then
673 * access can be guarded as appropriate. */
674 BLI_assert(this->is_valid());
675
676 /* NOTE(Metal): Vertex input assembly description will have been populated externally
677 * via #MTLBatch or #MTLImmediate during binding or draw. */
678
679 /* Resolve Context Frame-buffer state. */
680 MTLFrameBuffer *framebuffer = ctx->get_current_framebuffer();
681
682 /* Update global pipeline descriptor. */
683 MTLStateManager *state_manager = static_cast<MTLStateManager *>(
685 MTLRenderPipelineStateDescriptor &pipeline_descriptor = state_manager->get_pipeline_descriptor();
686
687 pipeline_descriptor.num_color_attachments = 0;
688 pipeline_descriptor.color_attachment_mask = 0xFFu;
689 for (int attachment = 0; attachment < GPU_FB_MAX_COLOR_ATTACHMENT; attachment++) {
690 MTLAttachment color_attachment = framebuffer->get_color_attachment(attachment);
691
692 if (color_attachment.used) {
693 /* If SRGB is disabled and format is SRGB, use color data directly with no conversions
694 * between linear and SRGB. */
695 MTLPixelFormat mtl_format = gpu_texture_format_to_metal(
696 color_attachment.texture->format_get());
697 if (framebuffer->get_is_srgb() && !framebuffer->get_srgb_enabled()) {
698 mtl_format = MTLPixelFormatRGBA8Unorm;
699 }
700 pipeline_descriptor.color_attachment_format[attachment] = mtl_format;
701 }
702 else {
703 pipeline_descriptor.color_attachment_format[attachment] = MTLPixelFormatInvalid;
704 }
705
706 pipeline_descriptor.num_color_attachments += (color_attachment.used) ? 1 : 0;
707
708 if (color_attachment.ignored) {
709 pipeline_descriptor.color_attachment_mask &= ~(1 << attachment);
710 }
711 }
712 MTLAttachment depth_attachment = framebuffer->get_depth_attachment();
713 MTLAttachment stencil_attachment = framebuffer->get_stencil_attachment();
714 pipeline_descriptor.depth_attachment_format = (depth_attachment.used) ?
716 depth_attachment.texture->format_get()) :
717 MTLPixelFormatInvalid;
718 pipeline_descriptor.stencil_attachment_format =
719 (stencil_attachment.used) ?
720 gpu_texture_format_to_metal(stencil_attachment.texture->format_get()) :
721 MTLPixelFormatInvalid;
722
723 /* Resolve Context Pipeline State (required by PSO). */
724 pipeline_descriptor.color_write_mask = ctx->pipeline_state.color_write_mask;
725 pipeline_descriptor.blending_enabled = ctx->pipeline_state.blending_enabled;
726 pipeline_descriptor.alpha_blend_op = ctx->pipeline_state.alpha_blend_op;
727 pipeline_descriptor.rgb_blend_op = ctx->pipeline_state.rgb_blend_op;
732 pipeline_descriptor.point_size = ctx->pipeline_state.point_size;
733
734 /* Resolve clipping plane enablement. */
735 pipeline_descriptor.clipping_plane_enable_mask = 0;
736 for (const int plane : IndexRange(6)) {
737 pipeline_descriptor.clipping_plane_enable_mask =
738 pipeline_descriptor.clipping_plane_enable_mask |
739 ((ctx->pipeline_state.clip_distance_enabled[plane]) ? (1 << plane) : 0);
740 }
741 MTLShaderInterface &interface = this->get_interface();
742 /* Primitive Type -- Primitive topology class needs to be specified for layered rendering. */
743 bool requires_specific_topology_class = interface.use_layer() ||
744 interface.use_viewport_index() ||
745 prim_type == MTLPrimitiveTopologyClassPoint;
746 pipeline_descriptor.vertex_descriptor.prim_topology_class =
747 (requires_specific_topology_class) ? prim_type : MTLPrimitiveTopologyClassUnspecified;
748
749 /* Specialization configuration. */
750 pipeline_descriptor.specialization_state = {ctx->constants_state.values};
751
752 /* Bake pipeline state using global descriptor. */
753 return bake_graphic_pipeline_state(ctx, prim_type, pipeline_descriptor);
754}
755
756/* Variant which bakes a pipeline state based on an existing MTLRenderPipelineStateDescriptor.
757 * This function should be callable from a secondary compilation thread. */
759 MTLContext *ctx,
760 MTLPrimitiveTopologyClass prim_type,
761 const MTLRenderPipelineStateDescriptor &pipeline_descriptor)
762{
763 BLI_assert(this->is_valid());
764
765 /* Check if current PSO exists in the cache. */
766 pso_cache_lock_.lock();
767 MTLRenderPipelineStateInstance **pso_lookup = pso_cache_.lookup_ptr(pipeline_descriptor);
768 MTLRenderPipelineStateInstance *pipeline_state = (pso_lookup) ? *pso_lookup : nullptr;
769 pso_cache_lock_.unlock();
770
771 if (pipeline_state != nullptr) {
772 return pipeline_state;
773 }
774
775 /* TODO: When fetching a specialized variant of a shader, if this does not yet exist, verify
776 * whether the base unspecialized variant exists:
777 * - If unspecialized version exists: Compile specialized PSO asynchronously, returning base PSO
778 * and flagging state of specialization in cache as being built.
779 * - If unspecialized does NOT exist, build specialized version straight away, as we pay the
780 * cost of compilation in both cases regardless. */
781
782 /* Prepare Render Pipeline Descriptor. */
783
784 ::MTLFunctionConstantValues *values = populate_specialization_constant_values(
785 *this->constants, pipeline_descriptor.specialization_state);
786
787 /* Prepare Vertex descriptor based on current pipeline vertex binding state. */
788 ::MTLRenderPipelineDescriptor *desc = pso_descriptor_;
789 [desc reset];
790 desc.label = [NSString stringWithUTF8String:this->name];
791
792 const MTLVertexDescriptor &gpu_vert_desc = pipeline_descriptor.vertex_descriptor;
793 ::MTLVertexDescriptor *mtl_vert_desc = desc.vertexDescriptor;
794
795 uint32_t vbo_bind_mask = 0;
796
797 for (const uint i : IndexRange(gpu_vert_desc.max_attribute_value + 1)) {
798 const MTLVertexAttributeDescriptorPSO &attribute_desc = gpu_vert_desc.attributes[i];
799 /* Copy metal back-end attribute descriptor state into PSO descriptor.
800 * NOTE: need to copy each element due to direct assignment restrictions.
801 * Also note */
802 ::MTLVertexAttributeDescriptor *mtl_attribute = mtl_vert_desc.attributes[i];
803 mtl_attribute.format = attribute_desc.format;
804 mtl_attribute.offset = attribute_desc.offset;
805 mtl_attribute.bufferIndex = attribute_desc.buffer_index;
806 }
807
808 for (const uint i : IndexRange(gpu_vert_desc.num_vert_buffers)) {
809 const MTLVertexBufferLayoutDescriptorPSO &buf_layout = gpu_vert_desc.buffer_layouts[i];
810 /* Copy metal back-end buffer layout state into PSO descriptor.
811 * NOTE: need to copy each element due to copying from internal
812 * back-end descriptor to Metal API descriptor. */
813 MTLVertexBufferLayoutDescriptor *mtl_layout = mtl_vert_desc.layouts[buf_layout.buffer_slot];
814 mtl_layout.stepFunction = buf_layout.step_function;
815 mtl_layout.stepRate = buf_layout.step_rate;
816 mtl_layout.stride = buf_layout.stride;
817 vbo_bind_mask |= 1 << buf_layout.buffer_slot;
818 }
819
820 /* Null buffer index is used if an attribute is not found in the
821 * bound VBOs #VertexFormat. */
822 /* WATCH: Hope that it doesn't conflict with and existing buffer. */
823 const int null_buffer_index = 31 - bitscan_reverse_uint(get_interface().vertex_buffer_mask());
824 bool using_null_buffer = false;
825
827 ::MTLVertexAttributeDescriptor *mtl_attribute = mtl_vert_desc.attributes[attr.binding];
828 if (mtl_attribute.format == MTLVertexFormatInvalid) {
829 /* An attribute should be bound there but no buffer was provided.
830 * Mimic OpenGL behavior by binding a dummy buffer with 0 stride. */
831 shader::Type input_type = shader::Type(get_interface().attr_types_[attr.binding]);
832 mtl_attribute.format = gpu_type_to_metal_vertex_format(input_type);
833 mtl_attribute.offset = 0;
834 mtl_attribute.bufferIndex = null_buffer_index;
835 using_null_buffer = true;
836 }
837 }
838
839 if (using_null_buffer) {
840 MTLVertexBufferLayoutDescriptor *mtl_layout = mtl_vert_desc.layouts[null_buffer_index];
841 /* Use constant step function such that null buffer can contain just a singular dummy
842 * attribute. */
843 mtl_layout.stepFunction = MTLVertexStepFunctionConstant;
844 mtl_layout.stepRate = 0;
845 mtl_layout.stride = 16; /* Doesn't matter as stepRate is 0. */
846 vbo_bind_mask |= 1 << null_buffer_index;
847 }
848
849 /* Primitive Topology. */
850 desc.inputPrimitiveTopology = pipeline_descriptor.vertex_descriptor.prim_topology_class;
851
852 /* gl_PointSize constant. */
853 bool null_pointsize = true;
854 float MTL_pointsize = pipeline_descriptor.point_size;
855 if (pipeline_descriptor.vertex_descriptor.prim_topology_class == MTLPrimitiveTopologyClassPoint)
856 {
857 /* `if pointsize is > 0.0`, PROGRAM_POINT_SIZE is enabled, and `gl_PointSize` shader keyword
858 * overrides the value. Otherwise, if < 0.0, use global constant point size. */
859 if (MTL_pointsize < 0.0) {
860 MTL_pointsize = fabsf(MTL_pointsize);
861 [values setConstantValue:&MTL_pointsize
862 type:MTLDataTypeFloat
863 withName:@"MTL_global_pointsize"];
864 null_pointsize = false;
865 }
866 }
867
868 if (null_pointsize) {
869 MTL_pointsize = 0.0f;
870 [values setConstantValue:&MTL_pointsize
871 type:MTLDataTypeFloat
872 withName:@"MTL_global_pointsize"];
873 }
874
875 bool has_error = false;
876 {
877 std::string function_name = entry_point_name_get(ShaderStage::VERTEX);
878 NSError *error = nullptr;
879
880 desc.vertexFunction = [shader_library_vert_
881 newFunctionWithName:[NSString stringWithUTF8String:function_name.c_str()]
882 constantValues:values
883 error:&error];
884 if (error) {
885 has_error |= (
886 [[error localizedDescription] rangeOfString:@"Compilation succeeded"].location ==
887 NSNotFound);
888
889 const char *errors_c_str = [[error localizedDescription] UTF8String];
890 MTL_LOG_ERROR("%s : %s", function_name.c_str(), errors_c_str);
891 }
892 }
893
894 {
895 std::string function_name = entry_point_name_get(ShaderStage::FRAGMENT);
896 NSError *error = nullptr;
897
898 desc.fragmentFunction = [shader_library_frag_
899 newFunctionWithName:[NSString stringWithUTF8String:function_name.c_str()]
900 constantValues:values
901 error:&error];
902 if (error) {
903 has_error |= (
904 [[error localizedDescription] rangeOfString:@"Compilation succeeded"].location ==
905 NSNotFound);
906
907 const char *errors_c_str = [[error localizedDescription] UTF8String];
908 MTL_LOG_ERROR("%s : %s", function_name.c_str(), errors_c_str);
909 }
910 }
911
912 [values release];
913
914 /* Only exit out if genuine error and not warning */
915 if (has_error) {
916 return nullptr;
917 }
918
919 /* Setup pixel format state */
920 for (int color_attachment = 0; color_attachment < GPU_FB_MAX_COLOR_ATTACHMENT;
921 color_attachment++)
922 {
923 /* Fetch color attachment pixel format in back-end pipeline state. */
924 MTLPixelFormat pixel_format = pipeline_descriptor.color_attachment_format[color_attachment];
925 /* Populate MTL API PSO attachment descriptor. */
926 MTLRenderPipelineColorAttachmentDescriptor *col_attachment =
927 desc.colorAttachments[color_attachment];
928
929 col_attachment.pixelFormat = pixel_format;
930 if (pixel_format != MTLPixelFormatInvalid) {
931 bool format_supports_blending = mtl_format_supports_blending(pixel_format);
932
933 if ((pipeline_descriptor.color_attachment_mask >> color_attachment) & 1) {
934 col_attachment.writeMask = pipeline_descriptor.color_write_mask;
935 }
936 else {
937 /* Attachment was transitioned to ignored. */
938 col_attachment.writeMask = MTLColorWriteMaskNone;
939 }
940 col_attachment.blendingEnabled = pipeline_descriptor.blending_enabled &&
941 format_supports_blending;
942 if (format_supports_blending && pipeline_descriptor.blending_enabled) {
943 col_attachment.alphaBlendOperation = pipeline_descriptor.alpha_blend_op;
944 col_attachment.rgbBlendOperation = pipeline_descriptor.rgb_blend_op;
945 col_attachment.destinationAlphaBlendFactor = pipeline_descriptor.dest_alpha_blend_factor;
946 col_attachment.destinationRGBBlendFactor = pipeline_descriptor.dest_rgb_blend_factor;
947 col_attachment.sourceAlphaBlendFactor = pipeline_descriptor.src_alpha_blend_factor;
948 col_attachment.sourceRGBBlendFactor = pipeline_descriptor.src_rgb_blend_factor;
949 }
950 else {
951 if (pipeline_descriptor.blending_enabled && !format_supports_blending) {
952 CLOG_WARN(&LOG,
953 "Attempting to Bake PSO, but MTLPixelFormat %d does not support blending",
954 (int)pixel_format);
955 }
956 }
957 }
958 }
959 desc.depthAttachmentPixelFormat = pipeline_descriptor.depth_attachment_format;
960 desc.stencilAttachmentPixelFormat = pipeline_descriptor.stencil_attachment_format;
961
962 /* Bind-point range validation.
963 * We need to ensure that the PSO will have valid bind-point ranges, or is using the
964 * appropriate bindless fallback path if any bind limits are exceeded. */
965#ifdef NDEBUG
966 /* Ensure Buffer bindings are within range. */
967 BLI_assert_msg((MTL_uniform_buffer_base_index + get_max_ubo_index() + 2) <
969 "UBO and SSBO bindings exceed the fragment bind table limit.");
970#endif
971
972 @autoreleasepool {
973 MTLAutoreleasedRenderPipelineReflection reflection_data;
974 NSError *error = nullptr;
975
976 /* Compile PSO */
978 newRenderPipelineStateWithDescriptor:desc
979 options:MTLPipelineOptionBufferTypeInfo
980 reflection:&reflection_data
981 error:&error];
982 if (error) {
984 "Failed to create PSO for shader: %s error %s",
985 this->name,
986 [[error localizedDescription] UTF8String]);
987 BLI_assert(false);
988 return nullptr;
989 }
990 if (!pso) {
992 &LOG, "Failed to create PSO for shader: %s, but no error was provided!", this->name);
993 BLI_assert(false);
994 return nullptr;
995 }
996
997 /* Prepare pipeline state instance. */
999 pso_inst->vert = desc.vertexFunction;
1000 pso_inst->frag = desc.fragmentFunction;
1001 pso_inst->pso = pso;
1002 pso_inst->null_attribute_buffer_index = (using_null_buffer) ? null_buffer_index : -1;
1003 pso_inst->prim_type = prim_type;
1004
1005 pso_inst->parse_reflection_data(reflection_data);
1006 /* IMPORTANT: Discard any stale SSBOs or UBOs bindings that could override vertex bindings. */
1007 pso_inst->used_buf_vert_mask &= ~vbo_bind_mask;
1008
1009 /* Insert into pso cache. */
1010 pso_cache_lock_.lock();
1011 pso_inst->shader_pso_index = pso_cache_.size();
1012 pso_cache_.add(pipeline_descriptor, pso_inst);
1013 pso_cache_lock_.unlock();
1014 CLOG_DEBUG(&LOG,
1015 "PSO CACHE: Stored new variant in PSO cache for shader '%s' Hash: '%llu'",
1016 this->name,
1017 (unsigned long long)pipeline_descriptor.hash());
1018 return pso_inst;
1019 }
1020}
1021
1023 MTLContext *ctx, MTLComputePipelineStateDescriptor &compute_pipeline_descriptor)
1024{
1025 BLI_assert(this->is_valid());
1026 BLI_assert(shader_library_comp_ != nil);
1027
1028 /* Check if current PSO exists in the cache. */
1029 pso_cache_lock_.lock();
1030 MTLComputePipelineStateInstance *const *pso_lookup = compute_pso_cache_.lookup_ptr(
1031 compute_pipeline_descriptor);
1032 MTLComputePipelineStateInstance *pipeline_state = (pso_lookup) ? *pso_lookup : nullptr;
1033 pso_cache_lock_.unlock();
1034
1035 if (pipeline_state != nullptr) {
1036 /* Return cached PSO state. */
1037 BLI_assert(pipeline_state->pso != nil);
1038 return pipeline_state;
1039 }
1040 /* Prepare Compute Pipeline Descriptor. */
1041
1042 /* Setup function specialization constants, used to modify and optimize
1043 * generated code based on current render pipeline configuration. */
1044 ::MTLFunctionConstantValues *values = populate_specialization_constant_values(
1045 *this->constants, compute_pipeline_descriptor.specialization_state);
1046
1047 /* TODO: Compile specialized shader variants asynchronously. */
1048
1049 std::string function_name = entry_point_name_get(ShaderStage::COMPUTE);
1050 NSError *error = nullptr;
1051
1052 /* Compile compute function. */
1053 id<MTLFunction> compute_function = [shader_library_comp_
1054 newFunctionWithName:[NSString stringWithUTF8String:function_name.c_str()]
1055 constantValues:values
1056 error:&error];
1057 compute_function.label = [NSString stringWithUTF8String:this->name];
1058
1059 [values release];
1060
1061 if (error) {
1062 CLOG_WARN(&LOG,
1063 "Metal Shader compute function, error %s",
1064 [[error localizedDescription] UTF8String]);
1065
1066 /* Only exit out if genuine error and not warning */
1067 if ([[error localizedDescription] rangeOfString:@"Compilation succeeded"].location ==
1068 NSNotFound)
1069 {
1070 return nullptr;
1071 }
1072 }
1073
1074 /* Compile PSO. */
1075 ::MTLComputePipelineDescriptor *desc = [[MTLComputePipelineDescriptor alloc] init];
1076 desc.label = [NSString stringWithUTF8String:this->name];
1077 desc.computeFunction = compute_function;
1078
1080 newComputePipelineStateWithDescriptor:desc
1081 options:MTLPipelineOptionNone
1082 reflection:nullptr
1083 error:&error];
1084
1085 /* If PSO has compiled but max theoretical threads-per-threadgroup is lower than required
1086 * dispatch size, recompile with increased limit. NOTE: This will result in a performance drop,
1087 * ideally the source shader should be modified to reduce local register pressure, or, local
1088 * work-group size should be reduced.
1089 * Similarly, the custom tuning parameter "mtl_max_total_threads_per_threadgroup" can be
1090 * specified to a sufficiently large value to avoid this. */
1091 if (pso) {
1092 uint num_required_threads_per_threadgroup = compute_pso_common_state_.threadgroup_x_len *
1093 compute_pso_common_state_.threadgroup_y_len *
1094 compute_pso_common_state_.threadgroup_z_len;
1095 if (pso.maxTotalThreadsPerThreadgroup < num_required_threads_per_threadgroup) {
1097 "Shader '%s' requires %u threads per threadgroup, but PSO limit is: %lu. Recompiling "
1098 "with increased limit on descriptor.\n",
1099 this->name,
1100 num_required_threads_per_threadgroup,
1101 (unsigned long)pso.maxTotalThreadsPerThreadgroup);
1102 [pso release];
1103 pso = nil;
1104 desc.maxTotalThreadsPerThreadgroup = 1024;
1105 pso = [ctx->device newComputePipelineStateWithDescriptor:desc
1106 options:MTLPipelineOptionNone
1107 reflection:nullptr
1108 error:&error];
1109 }
1110 }
1111
1112 [desc release];
1113
1114 if (error) {
1115 CLOG_ERROR(&LOG,
1116 "Failed to create PSO for compute shader: %s error %s",
1117 this->name,
1118 [[error localizedDescription] UTF8String]);
1119 return nullptr;
1120 }
1121 if (!pso) {
1122 CLOG_ERROR(&LOG,
1123 "Failed to create PSO for compute shader: %s, but no error was provided!",
1124 this->name);
1125 return nullptr;
1126 }
1127
1128 /* Gather reflection data and create MTLComputePipelineStateInstance to store results. */
1130 compute_pso_instance->compute = compute_function;
1131 compute_pso_instance->pso = pso;
1132 pso_cache_lock_.lock();
1133 compute_pso_instance->shader_pso_index = compute_pso_cache_.size();
1134 compute_pso_cache_.add(compute_pipeline_descriptor, compute_pso_instance);
1135 pso_cache_lock_.unlock();
1136
1137 return compute_pso_instance;
1138}
1139
1140
1141/* -------------------------------------------------------------------- */
1144
1149
1151{
1152 MTLShader *shader = static_cast<MTLShader *>(compile(info, true));
1153
1154 if (shader) {
1155 /* Generate and cache any render PSOs if possible (typically materials only)
1156 * (Finalize() will already bake a Compute PSO if possible) */
1157 shader->warm_cache(-1);
1158 }
1159
1160 return shader;
1161}
1162
1164{
1165 MTLShader *shader = static_cast<MTLShader *>(specialization.shader);
1166
1167 BLI_assert_msg(shader->is_valid(),
1168 "Shader must be finalized before precompiling specializations");
1169
1170 if (!shader->has_compute_shader_lib()) {
1171 /* Currently only support Compute */
1172 return;
1173 }
1174
1175 /* Create descriptor using these specialization constants. */
1176 MTLComputePipelineStateDescriptor compute_pipeline_descriptor(specialization.constants.values);
1177
1178 MTLContext *metal_context = static_cast<MTLContext *>(Context::get());
1179 shader->bake_compute_pipeline_state(metal_context, compute_pipeline_descriptor);
1180}
1181
1183
1184} // namespace blender::gpu
Platform independent time functions.
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
SIMD_FORCE_INLINE bool isActive() const
void reset()
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
Definition btVector3.h:257
constexpr IndexRange()=default
static Context * get()
static MTLCapabilities & get_capabilities()
MTLFrameBuffer * get_current_framebuffer()
static MTLContext * get()
MTLContextGlobalShaderPipelineState pipeline_state
void specialization_constants_set(const shader::SpecializationConstants *constants_state)
MTLAttachment get_color_attachment(uint slot)
Shader * compile_shader(const shader::ShaderCreateInfo &info) override
void specialize_shader(const ShaderSpecialization &specialization) override
void warm_cache(int limit) override
void vertex_shader_from_glsl(const shader::ShaderCreateInfo &info, MutableSpan< StringRefNull > sources) override
void compute_shader_from_glsl(const shader::ShaderCreateInfo &info, MutableSpan< StringRefNull > sources) override
MTLComputePipelineStateInstance * bake_compute_pipeline_state(MTLContext *ctx, MTLComputePipelineStateDescriptor &compute_pipeline_descriptor)
const shader::ShaderCreateInfo & patch_create_info(const shader::ShaderCreateInfo &original_info) override
void uniform_int(int location, int comp_len, int array_size, const int *data) override
void bind(const shader::SpecializationConstants *constants_state) override
bool finalize(const shader::ShaderCreateInfo *info=nullptr) override
MTLShaderInterface & get_interface()
void geometry_shader_from_glsl(const shader::ShaderCreateInfo &info, MutableSpan< StringRefNull > sources) override
void unbind() override
void uniform_float(int location, int comp_len, int array_size, const float *data) override
MTLRenderPipelineStateInstance * bake_graphic_pipeline_state(MTLContext *ctx, MTLPrimitiveTopologyClass prim_type, const MTLRenderPipelineStateDescriptor &pipeline_descriptor)
MTLRenderPipelineStateInstance * bake_current_pipeline_state(MTLContext *ctx, MTLPrimitiveTopologyClass prim_type)
MTLShader(MTLContext *ctx, const char *name)
Definition mtl_shader.mm:91
void init(const shader::ShaderCreateInfo &, bool) override
void fragment_shader_from_glsl(const shader::ShaderCreateInfo &info, MutableSpan< StringRefNull > sources) override
MTLRenderPipelineStateDescriptor & get_pipeline_descriptor()
Definition mtl_state.hh:57
Shader * compile(const shader::ShaderCreateInfo &info, bool is_codegen_only)
ShaderCompiler(uint32_t threads_count=1, GPUWorker::ContextType context_type=GPUWorker::ContextType::PerThread, bool support_specializations=false)
std::unique_ptr< PatchedShaderCreateInfo > patched_info_
static void dump_source_to_disk(StringRef shader_name, StringRef shader_name_with_stage_name, StringRef extension, StringRef source)
Definition gpu_shader.cc:43
std::unique_ptr< const shader::SpecializationConstants > constants
ShaderInterface * interface
StringRefNull name_get() const
static std::string run_preprocessor(StringRef source, bool no_dead_code_elimination)
void print_log(Span< StringRefNull > sources, const char *log, const char *stage, bool error, GPULogParser *parser)
Shader(const char *name)
TextureFormat format_get() const
CCL_NAMESPACE_BEGIN struct Options options
#define GPU_FB_MAX_COLOR_ATTACHMENT
#define SOURCES_INDEX_VERSION
#define MTL_MAX_BUFFER_BINDINGS
#define MTL_MAX_TEXTURE_SLOTS
#define MTL_MAX_IMAGE_SLOTS
#define MTL_LOG_WARNING(info,...)
Definition mtl_debug.hh:39
#define MTL_LOG_ERROR(info,...)
Definition mtl_debug.hh:31
#define MTL_SPECIALIZATION_CONSTANT_OFFSET
Vector< shader::GeneratedSource, 0 > GeneratedSourceList
Vector< StringRefNull > gpu_shader_dependency_get_resolved_source(const StringRefNull shader_source_name, const shader::GeneratedSourceList &generated_sources, const StringRefNull shader_name)
MTLPixelFormat gpu_texture_format_to_metal(TextureFormat tex_format)
const char * to_string(ShaderStage stage)
Definition mtl_shader.mm:52
std::pair< std::string, std::string > generate_entry_point(const ShaderCreateInfo &info, const ShaderStage stage, const StringRefNull entry_point_name)
static uint16_t get_images_binding_mask(NSArray< MTLArgument * > *args)
static CLG_LogRef LOG
Definition mtl_shader.mm:50
::MTLCompileOptions * get_compile_options(const bool use_subpass_input, const bool use_texture_atomic, const bool use_ray_query)
std::string shader_stage_define(const ShaderStage stage)
Definition mtl_shader.mm:67
MTLVertexFormat gpu_type_to_metal_vertex_format(shader::Type type)
::MTLFunctionConstantValues * populate_specialization_constant_values(const shader::SpecializationConstants &shader_constants, const SpecializationStateDescriptor &specialization_descriptor)
bool mtl_format_supports_blending(MTLPixelFormat format)
static uint64_t get_samplers_binding_mask(NSArray< MTLArgument * > *args)
void patch_create_info_atomic_workaround(std::unique_ptr< PatchedShaderCreateInfo > &patched_info, const shader::ShaderCreateInfo &original_info)
static uint32_t get_buffers_binding_mask(NSArray< MTLArgument * > *args)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
unsigned int uint
Definition BKE_text.h:55
@ G_DEBUG_GPU_SHADER_NO_DCE
Global G
Definition blender.cc:57
unsigned short uint16_t
Definition BKE_text.h:80
unsigned int uint32_t
Definition BKE_text.h:81
BMesh const char void * data
MINLINE unsigned int bitscan_reverse_uint(unsigned int a)
int GPU_max_parallel_compilations()
MINLINE int min_ii(int a, int b)
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
gpu::shader::SpecializationConstants constants
MTLPixelFormat color_attachment_format[GPU_FB_MAX_COLOR_ATTACHMENT]
void parse_reflection_data(::MTLRenderPipelineReflection *reflection_data)
::MTLPrimitiveTopologyClass prim_topology_class
MTLVertexAttributeDescriptorPSO attributes[GPU_VERT_ATTR_MAX_LEN]
MTLVertexBufferLayoutDescriptorPSO buffer_layouts[GPU_BATCH_VBO_MAX_LEN]
Vector< shader::SpecializationConstant::Value > values
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
Vector< SpecializationConstant::Value, 8 > values
int size() const
Definition vector.hh:130