40 return MTLPixelFormatRGBA8Uint;
42 return MTLPixelFormatRGBA8Sint;
44 return MTLPixelFormatRGBA8Unorm;
46 return MTLPixelFormatRGBA32Uint;
48 return MTLPixelFormatRGBA32Sint;
50 return MTLPixelFormatRGBA32Float;
52 return MTLPixelFormatRGBA16Uint;
54 return MTLPixelFormatRGBA16Sint;
56 return MTLPixelFormatRGBA16Float;
58 return MTLPixelFormatRGBA16Unorm;
60 return MTLPixelFormatRG8Uint;
62 return MTLPixelFormatRG8Sint;
64 return MTLPixelFormatRG8Unorm;
66 return MTLPixelFormatRG32Uint;
68 return MTLPixelFormatRG32Sint;
70 return MTLPixelFormatRG32Float;
72 return MTLPixelFormatRG16Uint;
74 return MTLPixelFormatRG16Sint;
76 return MTLPixelFormatRG16Float;
78 return MTLPixelFormatRG16Unorm;
80 return MTLPixelFormatR8Uint;
82 return MTLPixelFormatR8Sint;
84 return MTLPixelFormatR8Unorm;
86 return MTLPixelFormatR32Uint;
88 return MTLPixelFormatR32Sint;
90 return MTLPixelFormatR32Float;
92 return MTLPixelFormatR16Uint;
94 return MTLPixelFormatR16Sint;
96 return MTLPixelFormatR16Float;
98 return MTLPixelFormatR16Unorm;
101 return MTLPixelFormatRGB10A2Unorm;
103 return MTLPixelFormatRGB10A2Uint;
105 return MTLPixelFormatRG11B10Float;
109 return MTLPixelFormatDepth32Float_Stencil8;
111 return MTLPixelFormatRGBA8Unorm_sRGB;
115 return MTLPixelFormatRGBA16Float;
117 return MTLPixelFormatRGBA16Snorm;
119 return MTLPixelFormatRGBA8Snorm;
122 return MTLPixelFormatRGBA32Float;
125 return MTLPixelFormatRGBA32Sint;
128 return MTLPixelFormatRGBA32Uint;
131 return MTLPixelFormatRGBA16Snorm;
134 return MTLPixelFormatRGBA16Sint;
137 return MTLPixelFormatRGBA16Uint;
140 return MTLPixelFormatRGBA16Unorm;
143 return MTLPixelFormatRGBA8Snorm;
146 return MTLPixelFormatRGBA8Unorm;
149 return MTLPixelFormatRGBA8Sint;
152 return MTLPixelFormatRGBA8Uint;
154 return MTLPixelFormatRG16Snorm;
156 return MTLPixelFormatRG8Snorm;
158 return MTLPixelFormatR16Snorm;
160 return MTLPixelFormatR8Snorm;
163 return MTLPixelFormatBC1_RGBA_sRGB;
165 return MTLPixelFormatBC2_RGBA_sRGB;
167 return MTLPixelFormatBC3_RGBA_sRGB;
169 return MTLPixelFormatBC1_RGBA;
171 return MTLPixelFormatBC2_RGBA;
173 return MTLPixelFormatBC3_RGBA;
176 return MTLPixelFormatRGBA8Unorm_sRGB;
178 return MTLPixelFormatRGB9E5Float;
181 return MTLPixelFormatDepth32Float;
185 return MTLPixelFormatDepth32Float;
187 return MTLPixelFormatDepth16Unorm;
190 return MTLPixelFormatRGBA8Unorm;
195 switch (tex_format) {
196 case MTLPixelFormatRGBA8Uint:
197 case MTLPixelFormatRGBA8Sint:
198 case MTLPixelFormatRGBA8Unorm:
199 case MTLPixelFormatRGBA8Snorm:
200 case MTLPixelFormatRGB10A2Uint:
201 case MTLPixelFormatRGB10A2Unorm:
203 case MTLPixelFormatRGBA32Uint:
204 case MTLPixelFormatRGBA32Sint:
205 case MTLPixelFormatRGBA32Float:
207 case MTLPixelFormatRGBA16Uint:
208 case MTLPixelFormatRGBA16Sint:
209 case MTLPixelFormatRGBA16Float:
210 case MTLPixelFormatRGBA16Unorm:
211 case MTLPixelFormatRGBA16Snorm:
213 case MTLPixelFormatRG8Uint:
214 case MTLPixelFormatRG8Sint:
215 case MTLPixelFormatRG8Unorm:
216 case MTLPixelFormatRG8Snorm:
217 case MTLPixelFormatRG8Unorm_sRGB:
219 case MTLPixelFormatRG32Uint:
220 case MTLPixelFormatRG32Sint:
221 case MTLPixelFormatRG32Float:
223 case MTLPixelFormatRG16Uint:
224 case MTLPixelFormatRG16Sint:
225 case MTLPixelFormatRG16Float:
226 case MTLPixelFormatRG16Unorm:
227 case MTLPixelFormatRG16Snorm:
229 case MTLPixelFormatR8Uint:
230 case MTLPixelFormatR8Sint:
231 case MTLPixelFormatR8Unorm:
232 case MTLPixelFormatR8Snorm:
234 case MTLPixelFormatR32Uint:
235 case MTLPixelFormatR32Sint:
236 case MTLPixelFormatR32Float:
238 case MTLPixelFormatR16Uint:
239 case MTLPixelFormatR16Sint:
240 case MTLPixelFormatR16Float:
241 case MTLPixelFormatR16Snorm:
242 case MTLPixelFormatR16Unorm:
244 case MTLPixelFormatRG11B10Float:
246 case MTLPixelFormatDepth32Float_Stencil8:
248 case MTLPixelFormatRGBA8Unorm_sRGB:
249 case MTLPixelFormatDepth32Float:
250 case MTLPixelFormatDepth24Unorm_Stencil8:
252 case MTLPixelFormatDepth16Unorm:
254 case MTLPixelFormatBC1_RGBA:
255 case MTLPixelFormatBC1_RGBA_sRGB:
257 case MTLPixelFormatBC2_RGBA:
258 case MTLPixelFormatBC2_RGBA_sRGB:
259 case MTLPixelFormatBC3_RGBA:
260 case MTLPixelFormatBC3_RGBA_sRGB:
271 switch (tex_format) {
272 case MTLPixelFormatRGBA8Uint:
273 case MTLPixelFormatRGBA8Sint:
274 case MTLPixelFormatRGBA8Unorm:
275 case MTLPixelFormatRGBA8Snorm:
276 case MTLPixelFormatRGBA32Uint:
277 case MTLPixelFormatRGBA32Sint:
278 case MTLPixelFormatRGBA32Float:
279 case MTLPixelFormatRGBA16Uint:
280 case MTLPixelFormatRGBA16Sint:
281 case MTLPixelFormatRGBA16Float:
282 case MTLPixelFormatRGBA16Unorm:
283 case MTLPixelFormatRGBA16Snorm:
284 case MTLPixelFormatRGBA8Unorm_sRGB:
285 case MTLPixelFormatRGB10A2Uint:
286 case MTLPixelFormatRGB10A2Unorm:
287 case MTLPixelFormatBC1_RGBA_sRGB:
288 case MTLPixelFormatBC2_RGBA_sRGB:
289 case MTLPixelFormatBC3_RGBA_sRGB:
290 case MTLPixelFormatBC1_RGBA:
291 case MTLPixelFormatBC2_RGBA:
292 case MTLPixelFormatBC3_RGBA:
295 case MTLPixelFormatRG11B10Float:
298 case MTLPixelFormatRG8Uint:
299 case MTLPixelFormatRG8Sint:
300 case MTLPixelFormatRG8Unorm:
301 case MTLPixelFormatRG32Uint:
302 case MTLPixelFormatRG32Sint:
303 case MTLPixelFormatRG32Float:
304 case MTLPixelFormatRG16Uint:
305 case MTLPixelFormatRG16Sint:
306 case MTLPixelFormatRG16Float:
307 case MTLPixelFormatDepth32Float_Stencil8:
308 case MTLPixelFormatRG16Snorm:
309 case MTLPixelFormatRG16Unorm:
310 case MTLPixelFormatRG8Snorm:
313 case MTLPixelFormatR8Uint:
314 case MTLPixelFormatR8Sint:
315 case MTLPixelFormatR8Unorm:
316 case MTLPixelFormatR8Snorm:
317 case MTLPixelFormatR32Uint:
318 case MTLPixelFormatR32Sint:
319 case MTLPixelFormatR32Float:
320 case MTLPixelFormatR16Uint:
321 case MTLPixelFormatR16Sint:
322 case MTLPixelFormatR16Float:
323 case MTLPixelFormatR16Unorm:
324 case MTLPixelFormatR16Snorm:
325 case MTLPixelFormatDepth32Float:
326 case MTLPixelFormatDepth16Unorm:
327 case MTLPixelFormatDepth24Unorm_Stencil8:
346 case MTLPixelFormatA8Unorm:
347 case MTLPixelFormatR8Uint:
348 case MTLPixelFormatR8Sint:
349 case MTLPixelFormatR16Uint:
350 case MTLPixelFormatR16Sint:
351 case MTLPixelFormatRG32Uint:
352 case MTLPixelFormatRG32Sint:
353 case MTLPixelFormatRGBA8Uint:
354 case MTLPixelFormatRGBA8Sint:
355 case MTLPixelFormatRGBA32Uint:
356 case MTLPixelFormatRGBA32Sint:
357 case MTLPixelFormatDepth16Unorm:
358 case MTLPixelFormatDepth32Float:
359 case MTLPixelFormatInvalid:
360 case MTLPixelFormatBGR10A2Unorm:
361 case MTLPixelFormatRGB10A2Uint:
369 case MTLPixelFormatA8Unorm:
370 case MTLPixelFormatR8Uint:
371 case MTLPixelFormatR8Sint:
372 case MTLPixelFormatR16Uint:
373 case MTLPixelFormatR16Sint:
374 case MTLPixelFormatRG32Uint:
375 case MTLPixelFormatRG32Sint:
376 case MTLPixelFormatRGBA8Uint:
377 case MTLPixelFormatRGBA8Sint:
378 case MTLPixelFormatRGBA32Uint:
379 case MTLPixelFormatRGBA32Sint:
380 case MTLPixelFormatRGBA32Float:
381 case MTLPixelFormatDepth16Unorm:
382 case MTLPixelFormatDepth32Float:
383 case MTLPixelFormatInvalid:
384 case MTLPixelFormatBGR10A2Unorm:
385 case MTLPixelFormatRGB10A2Uint:
399id<MTLComputePipelineState> gpu::MTLTexture::mtl_texture_update_impl(
402 &specialization_cache,
406 id<MTLComputePipelineState> *result = specialization_cache.lookup_ptr(specialization_params);
407 if (result !=
nullptr) {
411 id<MTLComputePipelineState> return_pso = nil;
419 NSString *tex_update_kernel_src = [NSString
423 MTLCompileOptions *
options = [[[MTLCompileOptions alloc]
init] autorelease];
424 options.languageVersion = MTLLanguageVersion2_2;
425 options.preprocessorMacros = @{
427 [NSString stringWithUTF8String:specialization_params.
input_data_type.c_str()],
428 @"OUTPUT_DATA_TYPE" :
429 [NSString stringWithUTF8String:specialization_params.
output_data_type.c_str()],
430 @"COMPONENT_COUNT_INPUT" :
432 @"COMPONENT_COUNT_OUTPUT" :
434 @"TEX_TYPE" : [NSNumber numberWithInt:((
int)(texture_type))],
435 @"IS_TEXTURE_CLEAR" :
436 [NSNumber numberWithInt:((
int)(specialization_params.is_clear ? 1 : 0))]
440 NSError *
error =
nullptr;
441 id<MTLLibrary> temp_lib = [[ctx->device newLibraryWithSource:tex_update_kernel_src
446 if ([[
error localizedDescription] rangeOfString:
@"Compilation succeeded"].location ==
449 NSLog(
@"Compile Error - Metal Shader Library error %@ ",
error);
457 id<MTLFunction> temp_compute_function = [[temp_lib
458 newFunctionWithName:
@"compute_texture_update"] autorelease];
462 id<MTLComputePipelineState> compute_pso = [ctx->device
463 newComputePipelineStateWithFunction:temp_compute_function
465 if (
error || compute_pso == nil) {
466 NSLog(
@"Failed to prepare texture_update MTLComputePipelineState %@",
error);
471 specialization_cache.add_new(specialization_params, compute_pso);
472 return_pso = compute_pso;
479id<MTLComputePipelineState> gpu::MTLTexture::texture_update_1d_get_kernel(
484 return mtl_texture_update_impl(specialization,
485 mtl_context->get_texture_utils().texture_1d_update_compute_psos,
489id<MTLComputePipelineState> gpu::MTLTexture::texture_update_1d_array_get_kernel(
494 return mtl_texture_update_impl(
496 mtl_context->get_texture_utils().texture_1d_array_update_compute_psos,
500id<MTLComputePipelineState> gpu::MTLTexture::texture_update_2d_get_kernel(
505 return mtl_texture_update_impl(specialization,
506 mtl_context->get_texture_utils().texture_2d_update_compute_psos,
510id<MTLComputePipelineState> gpu::MTLTexture::texture_update_2d_array_get_kernel(
515 return mtl_texture_update_impl(
517 mtl_context->get_texture_utils().texture_2d_array_update_compute_psos,
521id<MTLComputePipelineState> gpu::MTLTexture::texture_update_3d_get_kernel(
526 return mtl_texture_update_impl(specialization,
527 mtl_context->get_texture_utils().texture_3d_update_compute_psos,
534GPUShader *gpu::MTLTexture::depth_2d_update_sh_get(
542 GPUShader **result = mtl_context->get_texture_utils().depth_2d_update_shaders.lookup_ptr(
544 if (result !=
nullptr) {
548 const char *depth_2d_info_variant =
nullptr;
551 depth_2d_info_variant =
"depth_2d_update_float";
554 depth_2d_info_variant =
"depth_2d_update_int24";
557 depth_2d_info_variant =
"depth_2d_update_int32";
565 mtl_context->get_texture_utils().depth_2d_update_shaders.add_new(specialization, shader);
569GPUShader *gpu::MTLTexture::fullscreen_blit_sh_get()
573 if (mtl_context->get_texture_utils().fullscreen_blit_shader ==
nullptr) {
576 mtl_context->get_texture_utils().fullscreen_blit_shader = shader;
578 return mtl_context->get_texture_utils().fullscreen_blit_shader;
582void gpu::MTLTexture::update_sub_depth_2d(
583 int mip,
int offset[3],
int extent[3],
eGPUDataFormat type,
const void *data)
615 BLI_assert_msg(
false,
"Unsupported eGPUDataFormat being passed to depth texture update\n");
630 gpu::MTLTexture *mtl_tex =
static_cast<gpu::MTLTexture *
>(
unwrap(r32_tex_tmp));
631 mtl_tex->update_sub(mip, offset, extent, type, data);
637 if (extent[0] == w_ && extent[1] == h_) {
643 GPUShader *depth_2d_update_sh = depth_2d_update_sh_get(specialization);
659 GPU_scissor(offset[0], offset[1], extent[0], extent[1]);
674 if (restore_fb !=
nullptr) {
689id<MTLComputePipelineState> gpu::MTLTexture::mtl_texture_read_impl(
692 &specialization_cache,
696 id<MTLComputePipelineState> *result = specialization_cache.lookup_ptr(specialization_params);
697 if (result !=
nullptr) {
701 id<MTLComputePipelineState> return_pso = nil;
709 NSString *tex_update_kernel_src = [NSString
713 int64_t depth_scale_factor = 1;
720 depth_scale_factor = 1;
724 depth_scale_factor = 0xFFFFFFu;
728 depth_scale_factor = 0xFFFFFFFFu;
737 MTLCompileOptions *
options = [[[MTLCompileOptions alloc]
init] autorelease];
738 options.languageVersion = MTLLanguageVersion2_2;
739 options.preprocessorMacros = @{
741 [NSString stringWithUTF8String:specialization_params.
input_data_type.c_str()],
742 @"OUTPUT_DATA_TYPE" :
743 [NSString stringWithUTF8String:specialization_params.
output_data_type.c_str()],
744 @"COMPONENT_COUNT_INPUT" :
746 @"COMPONENT_COUNT_OUTPUT" :
748 @"WRITE_COMPONENT_COUNT" :
752 [NSNumber numberWithInt:((specialization_params.
depth_format_mode > 0) ? 1 : 0)],
753 @"DEPTH_SCALE_FACTOR" : [NSNumber numberWithLongLong:depth_scale_factor],
754 @"TEX_TYPE" : [NSNumber numberWithInt:((
int)(texture_type))],
755 @"IS_DEPTHSTENCIL_24_8" :
756 [NSNumber numberWithInt:(specialization_params.depth_format_mode == 2) ? 1 : 0]
760 NSError *
error =
nullptr;
761 id<MTLLibrary> temp_lib = [[ctx->device newLibraryWithSource:tex_update_kernel_src
766 if ([[
error localizedDescription] rangeOfString:
@"Compilation succeeded"].location ==
769 NSLog(
@"Compile Error - Metal Shader Library error %@ ",
error);
777 id<MTLFunction> temp_compute_function = [[temp_lib newFunctionWithName:
@"compute_texture_read"]
782 id<MTLComputePipelineState> compute_pso = [ctx->device
783 newComputePipelineStateWithFunction:temp_compute_function
785 if (
error || compute_pso == nil) {
786 NSLog(
@"Failed to prepare texture_read MTLComputePipelineState %@",
error);
792 specialization_cache.add_new(specialization_params, compute_pso);
793 return_pso = compute_pso;
800id<MTLComputePipelineState> gpu::MTLTexture::texture_read_2d_get_kernel(
805 return mtl_texture_read_impl(specialization,
806 mtl_context->get_texture_utils().texture_2d_read_compute_psos,
810id<MTLComputePipelineState> gpu::MTLTexture::texture_read_2d_array_get_kernel(
815 return mtl_texture_read_impl(specialization,
816 mtl_context->get_texture_utils().texture_2d_array_read_compute_psos,
820id<MTLComputePipelineState> gpu::MTLTexture::texture_read_1d_get_kernel(
825 return mtl_texture_read_impl(specialization,
826 mtl_context->get_texture_utils().texture_1d_read_compute_psos,
830id<MTLComputePipelineState> gpu::MTLTexture::texture_read_1d_array_get_kernel(
835 return mtl_texture_read_impl(specialization,
836 mtl_context->get_texture_utils().texture_1d_array_read_compute_psos,
840id<MTLComputePipelineState> gpu::MTLTexture::texture_read_3d_get_kernel(
845 return mtl_texture_read_impl(specialization,
846 mtl_context->get_texture_utils().texture_3d_read_compute_psos,
#define BLI_assert_msg(a, msg)
MINLINE int min_ii(int a, int b)
#define GPU_batch_texture_bind(batch, name, tex)
void GPU_batch_set_shader(blender::gpu::Batch *batch, GPUShader *shader)
void GPU_batch_draw(blender::gpu::Batch *batch)
#define GPU_batch_uniform_2f(batch, name, x, y)
#define GPU_batch_uniform_1i(batch, name, x)
blender::gpu::Batch * GPU_batch_preset_quad()
GPUFrameBuffer * GPU_framebuffer_create(const char *name)
GPUFrameBuffer * GPU_framebuffer_active_get()
void GPU_framebuffer_restore()
void GPU_framebuffer_clear_stencil(GPUFrameBuffer *fb, uint clear_stencil)
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_clear_depth(GPUFrameBuffer *fb, float clear_depth)
void GPU_framebuffer_free(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_texture_attach(GPUFrameBuffer *framebuffer, GPUTexture *texture, int slot, int mip)
GPUShader * GPU_shader_create_from_info_name(const char *info_name)
void GPU_scissor_test(bool enable)
void GPU_depth_mask(bool depth)
eGPUDepthTest GPU_depth_test_get()
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()
uint GPU_stencil_mask_get()
void GPU_depth_test(eGPUDepthTest test)
bool GPU_depth_mask_get()
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_free(GPUTexture *texture)
void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_ATTACHMENT
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
struct GPUShader GPUShader
static MTLCapabilities & get_capabilities()
static MTLContext * get()
additional_info("compositor_sum_float_shared") .push_constant(Type additional_info("compositor_sum_float_shared") .push_constant(Type GPU_RGBA32F
CCL_NAMESPACE_BEGIN struct Options options
DOF_TILES_FLATTEN_GROUP_SIZE coc_tx GPU_R11F_G11F_B10F
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
out_radiance out_gbuf_normal out_gbuf_closure2 GPU_RG16
SHADOW_TILEMAP_RES tiles_buf[] statistics_buf render_view_buf[SHADOW_VIEW_MAX] GPU_R32UI
RAYTRACE_GROUP_SIZE additional_info("eevee_shared", "eevee_gbuffer_data", "eevee_global_ubo", "eevee_sampling_data", "eevee_utility_texture", "eevee_hiz_data", "draw_view") .specialization_constant(Type RAYTRACE_GROUP_SIZE in_sh_0_tx in_sh_2_tx screen_normal_tx GPU_RGBA8
blender::gpu::Batch * quad
static void error(const char *str)
@ MTL_DEPTH_UPDATE_MODE_INT32
@ MTL_DEPTH_UPDATE_MODE_INT24
@ MTL_DEPTH_UPDATE_MODE_FLOAT
char datatoc_compute_texture_update_msl[]
char datatoc_compute_texture_read_msl[]
size_t get_mtl_format_bytesize(MTLPixelFormat tex_format)
static Context * unwrap(GPUContext *ctx)
MTLPixelFormat gpu_texture_format_to_metal(eGPUTextureFormat tex_format)
static GPUContext * wrap(Context *ctx)
constexpr bool validate_data_format(eGPUTextureFormat tex_format, eGPUDataFormat data_format)
int get_mtl_format_num_components(MTLPixelFormat tex_format)
bool mtl_format_supports_blending(MTLPixelFormat 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