You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Metal: enable GPU buffer address support
This commit is contained in:
@@ -93,6 +93,7 @@ struct API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) MetalFeatures {
|
|||||||
bool needs_arg_encoders = true;
|
bool needs_arg_encoders = true;
|
||||||
bool metal_fx_spatial = false; /**< If true, Metal FX spatial functions are supported. */
|
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 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 {
|
struct MetalLimits {
|
||||||
|
|||||||
@@ -99,6 +99,10 @@ void MetalDeviceProperties::init_features(id<MTLDevice> p_device) {
|
|||||||
features.supports32BitMSAA = p_device.supports32BitMSAA;
|
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);
|
features.hostMemoryPageSize = sysconf(_SC_PAGESIZE);
|
||||||
|
|
||||||
for (SampleCount sc = SampleCount1; sc <= SampleCount64; sc <<= 1) {
|
for (SampleCount sc = SampleCount1; sc <= SampleCount64; sc <<= 1) {
|
||||||
|
|||||||
@@ -65,7 +65,6 @@
|
|||||||
#import <zlib.h>
|
#import <zlib.h>
|
||||||
#import <initializer_list>
|
#import <initializer_list>
|
||||||
#import <optional>
|
#import <optional>
|
||||||
#import <spirv.hpp>
|
|
||||||
|
|
||||||
// These types can be used in Vector and other containers that use
|
// These types can be used in Vector and other containers that use
|
||||||
// pointer operations not supported by ARC.
|
// 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;
|
MTLBindingAccess access = MTLBindingAccessReadOnly;
|
||||||
MTLResourceUsage usage = 0;
|
MTLResourceUsage usage = 0;
|
||||||
MTLTextureType textureType = MTLTextureType2D;
|
MTLTextureType textureType = MTLTextureType2D;
|
||||||
spv::ImageFormat imageFormat = spv::ImageFormatUnknown;
|
int imageFormat = 0;
|
||||||
uint32_t arrayLength = 0;
|
uint32_t arrayLength = 0;
|
||||||
bool isMultisampled = false;
|
bool isMultisampled = false;
|
||||||
|
|
||||||
|
|||||||
@@ -164,6 +164,9 @@ uint64_t RenderingDeviceDriverMetal::buffer_get_device_address(BufferID p_buffer
|
|||||||
id<MTLBuffer> obj = rid::get(p_buffer);
|
id<MTLBuffer> obj = rid::get(p_buffer);
|
||||||
return obj.gpuAddress;
|
return obj.gpuAddress;
|
||||||
} else {
|
} else {
|
||||||
|
#if DEV_ENABLED
|
||||||
|
WARN_PRINT_ONCE("buffer_get_device_address is not supported on this OS version.");
|
||||||
|
#endif
|
||||||
return 0;
|
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,
|
// 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.
|
// 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<MTLTexture> obj = nil;
|
id<MTLTexture> obj = nil;
|
||||||
if (needs_buffer) {
|
if (needs_buffer) {
|
||||||
@@ -2033,10 +2036,6 @@ Vector<uint8_t> RenderingDeviceDriverMetal::shader_compile_binary_from_spirv(Vec
|
|||||||
|
|
||||||
CompilerMSL::Options msl_options{};
|
CompilerMSL::Options msl_options{};
|
||||||
msl_options.set_msl_version(version_major, version_minor);
|
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;
|
bin_data.msl_version = msl_options.msl_version;
|
||||||
#if TARGET_OS_OSX
|
#if TARGET_OS_OSX
|
||||||
msl_options.platform = CompilerMSL::Options::macOS;
|
msl_options.platform = CompilerMSL::Options::macOS;
|
||||||
@@ -2063,9 +2062,9 @@ Vector<uint8_t> RenderingDeviceDriverMetal::shader_compile_binary_from_spirv(Vec
|
|||||||
msl_options.argument_buffers = false;
|
msl_options.argument_buffers = false;
|
||||||
bin_data.set_uses_argument_buffers(false);
|
bin_data.set_uses_argument_buffers(false);
|
||||||
}
|
}
|
||||||
|
msl_options.force_active_argument_buffer_resources = true;
|
||||||
msl_options.force_active_argument_buffer_resources = true; // Same as MoltenVK when using argument buffers.
|
// 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; // Same as MoltenVK when using argument buffers.
|
// msl_options.pad_argument_buffer_resources = true;
|
||||||
msl_options.texture_buffer_native = true; // Enable texture buffer support.
|
msl_options.texture_buffer_native = true; // Enable texture buffer support.
|
||||||
msl_options.use_framebuffer_fetch_subpasses = false;
|
msl_options.use_framebuffer_fetch_subpasses = false;
|
||||||
msl_options.pad_fragment_output_components = true;
|
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:
|
case SUPPORTS_FRAGMENT_SHADER_WITH_ONLY_SIDE_EFFECTS:
|
||||||
return true;
|
return true;
|
||||||
case SUPPORTS_BUFFER_DEVICE_ADDRESS:
|
case SUPPORTS_BUFFER_DEVICE_ADDRESS:
|
||||||
return false;
|
return device_properties->features.supports_gpu_address;
|
||||||
case SUPPORTS_METALFX_SPATIAL:
|
case SUPPORTS_METALFX_SPATIAL:
|
||||||
return device_properties->features.metal_fx_spatial;
|
return device_properties->features.metal_fx_spatial;
|
||||||
case SUPPORTS_METALFX_TEMPORAL:
|
case SUPPORTS_METALFX_TEMPORAL:
|
||||||
|
|||||||
Reference in New Issue
Block a user