45 return MTLPixelFormatRGBA8Uint;
47 return MTLPixelFormatRGBA8Sint;
49 return MTLPixelFormatRGBA8Unorm;
51 return MTLPixelFormatRGBA32Uint;
53 return MTLPixelFormatRGBA32Sint;
55 return MTLPixelFormatRGBA32Float;
57 return MTLPixelFormatRGBA16Uint;
59 return MTLPixelFormatRGBA16Sint;
61 return MTLPixelFormatRGBA16Float;
63 return MTLPixelFormatRGBA16Unorm;
65 return MTLPixelFormatRG8Uint;
67 return MTLPixelFormatRG8Sint;
69 return MTLPixelFormatRG8Unorm;
71 return MTLPixelFormatRG32Uint;
73 return MTLPixelFormatRG32Sint;
75 return MTLPixelFormatRG32Float;
77 return MTLPixelFormatRG16Uint;
79 return MTLPixelFormatRG16Sint;
81 return MTLPixelFormatRG16Float;
83 return MTLPixelFormatRG16Float;
85 return MTLPixelFormatR8Uint;
87 return MTLPixelFormatR8Sint;
89 return MTLPixelFormatR8Unorm;
91 return MTLPixelFormatR32Uint;
93 return MTLPixelFormatR32Sint;
95 return MTLPixelFormatR32Float;
97 return MTLPixelFormatR16Uint;
99 return MTLPixelFormatR16Sint;
101 return MTLPixelFormatR16Float;
103 return MTLPixelFormatR16Snorm;
107 return MTLPixelFormatRG11B10Float;
109 return MTLPixelFormatDepth32Float_Stencil8;
111 BLI_assert(
false &&
"GPU_DEPTH24_STENCIL8 not supported by Apple Silicon.");
112 return MTLPixelFormatDepth24Unorm_Stencil8;
115 return MTLPixelFormatRGBA8Unorm_sRGB;
117 return MTLPixelFormatRGBA16Float;
122 return MTLPixelFormatDepth32Float;
124 return MTLPixelFormatDepth16Unorm;
127 BLI_assert(!
"Unrecognised GPU pixel format!\n");
128 return MTLPixelFormatRGBA8Unorm;
135 switch (tex_format) {
136 case MTLPixelFormatRGBA8Uint:
137 case MTLPixelFormatRGBA8Sint:
138 case MTLPixelFormatRGBA8Unorm:
140 case MTLPixelFormatRGBA32Uint:
141 case MTLPixelFormatRGBA32Sint:
142 case MTLPixelFormatRGBA32Float:
144 case MTLPixelFormatRGBA16Uint:
145 case MTLPixelFormatRGBA16Sint:
146 case MTLPixelFormatRGBA16Float:
147 case MTLPixelFormatRGBA16Unorm:
149 case MTLPixelFormatRG8Uint:
150 case MTLPixelFormatRG8Sint:
151 case MTLPixelFormatRG8Unorm:
153 case MTLPixelFormatRG32Uint:
154 case MTLPixelFormatRG32Sint:
155 case MTLPixelFormatRG32Float:
157 case MTLPixelFormatRG16Uint:
158 case MTLPixelFormatRG16Sint:
159 case MTLPixelFormatRG16Float:
161 case MTLPixelFormatR8Uint:
162 case MTLPixelFormatR8Sint:
163 case MTLPixelFormatR8Unorm:
165 case MTLPixelFormatR32Uint:
166 case MTLPixelFormatR32Sint:
167 case MTLPixelFormatR32Float:
169 case MTLPixelFormatR16Uint:
170 case MTLPixelFormatR16Sint:
171 case MTLPixelFormatR16Float:
172 case MTLPixelFormatR16Snorm:
174 case MTLPixelFormatRG11B10Float:
176 case MTLPixelFormatDepth32Float_Stencil8:
178 case MTLPixelFormatRGBA8Unorm_sRGB:
179 case MTLPixelFormatDepth32Float:
180 case MTLPixelFormatDepth24Unorm_Stencil8:
182 case MTLPixelFormatDepth16Unorm:
186 BLI_assert(!
"Unrecognised GPU pixel format!\n");
194 switch (tex_format) {
195 case MTLPixelFormatRGBA8Uint:
196 case MTLPixelFormatRGBA8Sint:
197 case MTLPixelFormatRGBA8Unorm:
198 case MTLPixelFormatRGBA32Uint:
199 case MTLPixelFormatRGBA32Sint:
200 case MTLPixelFormatRGBA32Float:
201 case MTLPixelFormatRGBA16Uint:
202 case MTLPixelFormatRGBA16Sint:
203 case MTLPixelFormatRGBA16Float:
204 case MTLPixelFormatRGBA16Unorm:
205 case MTLPixelFormatRGBA8Unorm_sRGB:
208 case MTLPixelFormatRG11B10Float:
211 case MTLPixelFormatRG8Uint:
212 case MTLPixelFormatRG8Sint:
213 case MTLPixelFormatRG8Unorm:
214 case MTLPixelFormatRG32Uint:
215 case MTLPixelFormatRG32Sint:
216 case MTLPixelFormatRG32Float:
217 case MTLPixelFormatRG16Uint:
218 case MTLPixelFormatRG16Sint:
219 case MTLPixelFormatRG16Float:
220 case MTLPixelFormatDepth32Float_Stencil8:
223 case MTLPixelFormatR8Uint:
224 case MTLPixelFormatR8Sint:
225 case MTLPixelFormatR8Unorm:
226 case MTLPixelFormatR32Uint:
227 case MTLPixelFormatR32Sint:
228 case MTLPixelFormatR32Float:
229 case MTLPixelFormatR16Uint:
230 case MTLPixelFormatR16Sint:
231 case MTLPixelFormatR16Float:
232 case MTLPixelFormatR16Snorm:
233 case MTLPixelFormatDepth32Float:
234 case MTLPixelFormatDepth16Unorm:
235 case MTLPixelFormatDepth24Unorm_Stencil8:
241 BLI_assert(!
"Unrecognised GPU pixel format!\n");
254 case MTLPixelFormatA8Unorm:
255 case MTLPixelFormatR8Uint:
256 case MTLPixelFormatR8Sint:
257 case MTLPixelFormatR16Uint:
258 case MTLPixelFormatR16Sint:
259 case MTLPixelFormatRG32Uint:
260 case MTLPixelFormatRG32Sint:
261 case MTLPixelFormatRGBA8Uint:
262 case MTLPixelFormatRGBA8Sint:
263 case MTLPixelFormatRGBA32Uint:
264 case MTLPixelFormatRGBA32Sint:
265 case MTLPixelFormatDepth16Unorm:
266 case MTLPixelFormatDepth32Float:
267 case MTLPixelFormatInvalid:
268 case MTLPixelFormatBGR10A2Unorm:
269 case MTLPixelFormatRGB10A2Uint:
277 case MTLPixelFormatA8Unorm:
278 case MTLPixelFormatR8Uint:
279 case MTLPixelFormatR8Sint:
280 case MTLPixelFormatR16Uint:
281 case MTLPixelFormatR16Sint:
282 case MTLPixelFormatRG32Uint:
283 case MTLPixelFormatRG32Sint:
284 case MTLPixelFormatRGBA8Uint:
285 case MTLPixelFormatRGBA8Sint:
286 case MTLPixelFormatRGBA32Uint:
287 case MTLPixelFormatRGBA32Sint:
288 case MTLPixelFormatRGBA32Float:
289 case MTLPixelFormatDepth16Unorm:
290 case MTLPixelFormatDepth32Float:
291 case MTLPixelFormatInvalid:
292 case MTLPixelFormatBGR10A2Unorm:
293 case MTLPixelFormatRGB10A2Uint:
307 id<MTLComputePipelineState> gpu::MTLTexture::mtl_texture_update_impl(
310 &specialisation_cache,
314 id<MTLComputePipelineState> *
result = specialisation_cache.lookup_ptr(specialisation_params);
319 id<MTLComputePipelineState> return_pso = nil;
327 NSString *tex_update_kernel_src = [NSString
331 MTLCompileOptions *
options = [[[MTLCompileOptions alloc]
init] autorelease];
332 options.languageVersion = MTLLanguageVersion2_2;
333 options.preprocessorMacros = @{
335 [NSString stringWithUTF8String:specialisation_params.
input_data_type.c_str()],
336 @"OUTPUT_DATA_TYPE" :
337 [NSString stringWithUTF8String:specialisation_params.
output_data_type.c_str()],
338 @"COMPONENT_COUNT_INPUT" :
340 @"COMPONENT_COUNT_OUTPUT" :
342 @"TEX_TYPE" : [NSNumber numberWithInt:((int)(texture_type))]
347 id<MTLLibrary> temp_lib = [[ctx->device newLibraryWithSource:tex_update_kernel_src
351 NSLog(
@"Compile Error - Metal Shader Library error %@ ",
error);
358 id<MTLFunction> temp_compute_function = [[temp_lib
359 newFunctionWithName:
@"compute_texture_update"] autorelease];
363 id<MTLComputePipelineState> compute_pso = [ctx->device
364 newComputePipelineStateWithFunction:temp_compute_function
366 if (
error || compute_pso == nil) {
367 NSLog(
@"Failed to prepare texture_update MTLComputePipelineState %@",
error);
372 [compute_pso retain];
373 specialisation_cache.add_new(specialisation_params, compute_pso);
374 return_pso = compute_pso;
381 id<MTLComputePipelineState> gpu::MTLTexture::texture_update_1d_get_kernel(
386 return mtl_texture_update_impl(specialisation,
387 mtl_context->get_texture_utils().texture_1d_update_compute_psos,
391 id<MTLComputePipelineState> gpu::MTLTexture::texture_update_1d_array_get_kernel(
396 return mtl_texture_update_impl(
398 mtl_context->get_texture_utils().texture_1d_array_update_compute_psos,
402 id<MTLComputePipelineState> gpu::MTLTexture::texture_update_2d_get_kernel(
407 return mtl_texture_update_impl(specialisation,
408 mtl_context->get_texture_utils().texture_2d_update_compute_psos,
412 id<MTLComputePipelineState> gpu::MTLTexture::texture_update_2d_array_get_kernel(
417 return mtl_texture_update_impl(
419 mtl_context->get_texture_utils().texture_2d_array_update_compute_psos,
423 id<MTLComputePipelineState> gpu::MTLTexture::texture_update_3d_get_kernel(
428 return mtl_texture_update_impl(specialisation,
429 mtl_context->get_texture_utils().texture_3d_update_compute_psos,
436 GPUShader *gpu::MTLTexture::depth_2d_update_sh_get(
444 GPUShader **
result = mtl_context->get_texture_utils().depth_2d_update_shaders.lookup_ptr(
471 "depth_2d_update_sh_get");
472 mtl_context->get_texture_utils().depth_2d_update_shaders.add_new(specialisation, shader);
476 GPUShader *gpu::MTLTexture::fullscreen_blit_sh_get()
481 if (mtl_context->get_texture_utils().fullscreen_blit_shader ==
nullptr) {
486 mtl_context->get_texture_utils().fullscreen_blit_shader = shader;
488 return mtl_context->get_texture_utils().fullscreen_blit_shader;
492 void gpu::MTLTexture::update_sub_depth_2d(
525 BLI_assert(
false &&
"Unsupported eGPUDataFormat being passed to depth texture update\n");
531 "depth_intermediate_copy_tex", w_, h_, 1,
format,
nullptr);
534 gpu::MTLTexture *mtl_tex =
static_cast<gpu::MTLTexture *
>(
unwrap(r32_tex_tmp));
541 if (extent[0] == w_ && extent[1] == h_) {
543 GPU_framebuffer_clear_depth(depth_fb_temp, 0.0);
544 GPU_framebuffer_clear_stencil(depth_fb_temp, 0);
547 GPUShader *depth_2d_update_sh = depth_2d_update_sh_get(specialisation);
578 if (restore_fb !=
nullptr) {
593 id<MTLComputePipelineState> gpu::MTLTexture::mtl_texture_read_impl(
596 &specialisation_cache,
600 id<MTLComputePipelineState> *
result = specialisation_cache.lookup_ptr(specialisation_params);
605 id<MTLComputePipelineState> return_pso = nil;
613 NSString *tex_update_kernel_src = [NSString
617 long long int depth_scale_factor = 1;
624 depth_scale_factor = 1;
628 depth_scale_factor = 0xFFFFFFu;
632 depth_scale_factor = 0xFFFFFFFFu;
641 MTLCompileOptions *
options = [[[MTLCompileOptions alloc]
init] autorelease];
642 options.languageVersion = MTLLanguageVersion2_2;
643 options.preprocessorMacros = @{
645 [NSString stringWithUTF8String:specialisation_params.
input_data_type.c_str()],
646 @"OUTPUT_DATA_TYPE" :
647 [NSString stringWithUTF8String:specialisation_params.
output_data_type.c_str()],
648 @"COMPONENT_COUNT_INPUT" :
650 @"COMPONENT_COUNT_OUTPUT" :
652 @"WRITE_COMPONENT_COUNT" :
656 [NSNumber numberWithInt:((specialisation_params.
depth_format_mode > 0) ? 1 : 0)],
657 @"DEPTH_SCALE_FACTOR" : [NSNumber numberWithLongLong:depth_scale_factor],
658 @"TEX_TYPE" : [NSNumber numberWithInt:((int)(texture_type))]
663 id<MTLLibrary> temp_lib = [[ctx->device newLibraryWithSource:tex_update_kernel_src
667 NSLog(
@"Compile Error - Metal Shader Library error %@ ",
error);
674 id<MTLFunction> temp_compute_function = [[temp_lib newFunctionWithName:
@"compute_texture_read"]
679 id<MTLComputePipelineState> compute_pso = [ctx->device
680 newComputePipelineStateWithFunction:temp_compute_function
682 if (
error || compute_pso == nil) {
683 NSLog(
@"Failed to prepare texture_read MTLComputePipelineState %@",
error);
689 [compute_pso retain];
690 specialisation_cache.add_new(specialisation_params, compute_pso);
691 return_pso = compute_pso;
698 id<MTLComputePipelineState> gpu::MTLTexture::texture_read_2d_get_kernel(
703 return mtl_texture_read_impl(specialisation,
704 mtl_context->get_texture_utils().texture_2d_read_compute_psos,
708 id<MTLComputePipelineState> gpu::MTLTexture::texture_read_2d_array_get_kernel(
713 return mtl_texture_read_impl(specialisation,
714 mtl_context->get_texture_utils().texture_2d_array_read_compute_psos,
718 id<MTLComputePipelineState> gpu::MTLTexture::texture_read_1d_get_kernel(
723 return mtl_texture_read_impl(specialisation,
724 mtl_context->get_texture_utils().texture_1d_read_compute_psos,
728 id<MTLComputePipelineState> gpu::MTLTexture::texture_read_1d_array_get_kernel(
733 return mtl_texture_read_impl(specialisation,
734 mtl_context->get_texture_utils().texture_1d_array_read_compute_psos,
738 id<MTLComputePipelineState> gpu::MTLTexture::texture_read_3d_get_kernel(
743 return mtl_texture_read_impl(specialisation,
744 mtl_context->get_texture_utils().texture_3d_read_compute_psos,
#define BLI_assert_msg(a, msg)
MINLINE int min_ii(int a, int b)
void GPU_batch_set_shader(GPUBatch *batch, GPUShader *shader)
#define GPU_batch_texture_bind(batch, name, tex)
void GPU_batch_draw(GPUBatch *batch)
#define GPU_batch_uniform_2f(batch, name, x, y)
#define GPU_batch_uniform_1i(batch, name, x)
struct GPUBatch * GPU_batch_preset_quad(void)
GPUContext * GPU_context_active_get(void)
struct GPUFrameBuffer GPUFrameBuffer
void GPU_framebuffer_restore(void)
GPUFrameBuffer * GPU_framebuffer_active_get(void)
void GPU_framebuffer_free(GPUFrameBuffer *fb)
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
GPUFrameBuffer * GPU_framebuffer_create(const char *name)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
GPUShader * GPU_shader_create(const char *vertcode, const char *fragcode, const char *geomcode, const char *libcode, const char *defines, const char *shname)
struct GPUShader GPUShader
void GPU_scissor_test(bool enable)
uint GPU_stencil_mask_get(void)
void GPU_depth_mask(bool depth)
void GPU_stencil_test(eGPUStencilTest test)
void GPU_stencil_write_mask_set(uint write_mask)
void GPU_stencil_reference_set(uint reference)
void GPU_scissor(int x, int y, int width, int height)
eGPUStencilTest GPU_stencil_test_get(void)
bool GPU_depth_mask_get(void)
eGPUDepthTest GPU_depth_test_get(void)
void GPU_depth_test(eGPUDepthTest test)
void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat, bool use_clamp)
struct GPUTexture GPUTexture
void GPU_texture_free(GPUTexture *tex)
void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter)
GPUTexture * GPU_texture_create_2d(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Texture
vertex_source("basic_depth_pointcloud_vert.glsl") .additional_info("draw_pointcloud")
static MTLCapabilities & get_capabilities()
CCL_NAMESPACE_BEGIN struct Options options
out_color fragment_source("eevee_film_frag.glsl") .additional_info("draw_fullscreen"
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img GPU_RGBA16F
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx GPU_R32F
void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int mip)
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
static void error(const char *str)
@ MTL_DEPTH_UPDATE_MODE_INT32
@ MTL_DEPTH_UPDATE_MODE_INT24
@ MTL_DEPTH_UPDATE_MODE_FLOAT
char datatoc_gpu_shader_fullscreen_blit_frag_glsl[]
char datatoc_gpu_shader_fullscreen_blit_vert_glsl[]
char datatoc_depth_2d_update_int32_frag_glsl[]
char datatoc_compute_texture_update_msl[]
char datatoc_depth_2d_update_int24_frag_glsl[]
char datatoc_depth_2d_update_vert_glsl[]
char datatoc_depth_2d_update_float_frag_glsl[]
char datatoc_compute_texture_read_msl[]
MTLPixelFormat gpu_texture_format_to_metal(eGPUTextureFormat tex_format)
bool validate_data_format_mtl(eGPUTextureFormat tex_format, eGPUDataFormat data_format)
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)
int get_mtl_format_num_components(MTLPixelFormat tex_format)
bool mtl_format_supports_blending(MTLPixelFormat format)
int get_mtl_format_bytesize(MTLPixelFormat tex_format)
DepthTextureUpdateMode data_mode
std::string output_data_type
std::string input_data_type
int component_count_input
int component_count_output
int component_count_output
int component_count_input
std::string input_data_type
std::string output_data_type
bool supports_family_mac1
bool supports_family_mac_catalyst1