diff --git a/drivers/metal/metal_device_properties.h b/drivers/metal/metal_device_properties.h index 815af367648..853ddcaebc5 100644 --- a/drivers/metal/metal_device_properties.h +++ b/drivers/metal/metal_device_properties.h @@ -93,6 +93,7 @@ struct API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) MetalFeatures { bool needs_arg_encoders = true; bool metal_fx_spatial = false; /**< If true, Metal FX spatial functions are supported. */ bool metal_fx_temporal = false; /**< If true, Metal FX temporal functions are supported. */ + bool supports_gpu_address = false; /**< If true, referencing a GPU address in a shader is supported. */ }; struct MetalLimits { diff --git a/drivers/metal/metal_device_properties.mm b/drivers/metal/metal_device_properties.mm index d4d6d6bcd32..21553f7173d 100644 --- a/drivers/metal/metal_device_properties.mm +++ b/drivers/metal/metal_device_properties.mm @@ -99,6 +99,10 @@ void MetalDeviceProperties::init_features(id p_device) { features.supports32BitMSAA = p_device.supports32BitMSAA; } + if (@available(macOS 13.0, iOS 16.0, tvOS 16.0, *)) { + features.supports_gpu_address = true; + } + features.hostMemoryPageSize = sysconf(_SC_PAGESIZE); for (SampleCount sc = SampleCount1; sc <= SampleCount64; sc <<= 1) { diff --git a/drivers/metal/metal_objects.h b/drivers/metal/metal_objects.h index 4dc9b6d3f3d..67bb15a30fb 100644 --- a/drivers/metal/metal_objects.h +++ b/drivers/metal/metal_objects.h @@ -65,7 +65,6 @@ #import #import #import -#import // These types can be used in Vector and other containers that use // pointer operations not supported by ARC. @@ -563,7 +562,7 @@ struct API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) BindingInfo { MTLBindingAccess access = MTLBindingAccessReadOnly; MTLResourceUsage usage = 0; MTLTextureType textureType = MTLTextureType2D; - spv::ImageFormat imageFormat = spv::ImageFormatUnknown; + int imageFormat = 0; uint32_t arrayLength = 0; bool isMultisampled = false; diff --git a/drivers/metal/rendering_device_driver_metal.mm b/drivers/metal/rendering_device_driver_metal.mm index 2e32e99c2eb..d66064249ac 100644 --- a/drivers/metal/rendering_device_driver_metal.mm +++ b/drivers/metal/rendering_device_driver_metal.mm @@ -164,6 +164,9 @@ uint64_t RenderingDeviceDriverMetal::buffer_get_device_address(BufferID p_buffer id obj = rid::get(p_buffer); return obj.gpuAddress; } else { +#if DEV_ENABLED + WARN_PRINT_ONCE("buffer_get_device_address is not supported on this OS version."); +#endif return 0; } } @@ -355,7 +358,7 @@ RDD::TextureID RenderingDeviceDriverMetal::texture_create(const TextureFormat &p // Check if it is a linear format for atomic operations and therefore needs a buffer, // as generally Metal does not support atomic operations on textures. - bool needs_buffer = is_linear || (p_format.array_layers == 1 && p_format.mipmaps == 1 && p_format.texture_type == TEXTURE_TYPE_2D && flags::any(p_format.usage_bits, TEXTURE_USAGE_STORAGE_BIT) && (p_format.format == DATA_FORMAT_R32_UINT || p_format.format == DATA_FORMAT_R32_SINT)); + bool needs_buffer = is_linear || (p_format.array_layers == 1 && p_format.mipmaps == 1 && p_format.texture_type == TEXTURE_TYPE_2D && flags::any(p_format.usage_bits, TEXTURE_USAGE_STORAGE_BIT) && (p_format.format == DATA_FORMAT_R32_UINT || p_format.format == DATA_FORMAT_R32_SINT || p_format.format == DATA_FORMAT_R32G32_UINT || p_format.format == DATA_FORMAT_R32G32_SINT)); id obj = nil; if (needs_buffer) { @@ -2033,10 +2036,6 @@ Vector RenderingDeviceDriverMetal::shader_compile_binary_from_spirv(Vec CompilerMSL::Options msl_options{}; msl_options.set_msl_version(version_major, version_minor); - if (version_major == 3 && version_minor >= 1) { - // TODO(sgc): Restrict to Metal 3.0 for now, until bugs in SPIRV-cross image atomics are resolved. - msl_options.set_msl_version(3, 0); - } bin_data.msl_version = msl_options.msl_version; #if TARGET_OS_OSX msl_options.platform = CompilerMSL::Options::macOS; @@ -2063,9 +2062,9 @@ Vector RenderingDeviceDriverMetal::shader_compile_binary_from_spirv(Vec msl_options.argument_buffers = false; bin_data.set_uses_argument_buffers(false); } - - msl_options.force_active_argument_buffer_resources = true; // Same as MoltenVK when using argument buffers. - // msl_options.pad_argument_buffer_resources = true; // Same as MoltenVK when using argument buffers. + msl_options.force_active_argument_buffer_resources = true; + // We can't use this, as we have to add the descriptor sets via compiler.add_msl_resource_binding. + // msl_options.pad_argument_buffer_resources = true; msl_options.texture_buffer_native = true; // Enable texture buffer support. msl_options.use_framebuffer_fetch_subpasses = false; msl_options.pad_fragment_output_components = true; @@ -4036,7 +4035,7 @@ bool RenderingDeviceDriverMetal::has_feature(Features p_feature) { case SUPPORTS_FRAGMENT_SHADER_WITH_ONLY_SIDE_EFFECTS: return true; case SUPPORTS_BUFFER_DEVICE_ADDRESS: - return false; + return device_properties->features.supports_gpu_address; case SUPPORTS_METALFX_SPATIAL: return device_properties->features.metal_fx_spatial; case SUPPORTS_METALFX_TEMPORAL: