Skip to content

Commit 5dbcab9

Browse files
authored
feat(apple): support disabling metal validation (#2373)
To disable Metal API validation, add the following to your `app.json`: ```js "ios": { "metalAPIValidation": false }, ``` Read more about it here: https://github.com/microsoft/react-native-test-app/wiki/Manifest-(app.json)#ios.metalAPIValidation
1 parent 281bc8c commit 5dbcab9

File tree

7 files changed

+57
-5
lines changed

7 files changed

+57
-5
lines changed

docs/ios.metalAPIValidation.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The API Validation layer checks for code that calls the Metal API incorrectly,
2+
including errors in creating resources, encoding Metal commands, and performing
3+
other common tasks.
4+
5+
> [!NOTE]
6+
>
7+
> The API validation layer has a small, but measureable, impact on CPU
8+
> performance.
9+
10+
For more details, read Apple's documentation on
11+
[Validating your app’s Metal API usage](https://developer.apple.com/documentation/xcode/validating-your-apps-metal-api-usage/).
12+
13+
<details>
14+
<summary>History</summary>
15+
16+
- [[4.1.0](https://github.com/microsoft/react-native-test-app/releases/tag/4.1.0)]
17+
Added
18+
19+
</details>

ios/test_app.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,8 @@ def make_project!(xcodeproj, project_root, target_platform, options)
160160
FileUtils.mkdir_p(destination)
161161
FileUtils.cp_r(xcodeproj_src, destination)
162162
name, display_name, version, single_app = app_config(project_root)
163-
unless name.nil?
164-
xcschemes_path = File.join(xcodeproj_dst, 'xcshareddata', 'xcschemes')
165-
FileUtils.cp(File.join(xcschemes_path, 'ReactTestApp.xcscheme'),
166-
File.join(xcschemes_path, "#{name}.xcscheme"))
167-
end
163+
xcschemes_path = File.join(xcodeproj_dst, 'xcshareddata', 'xcschemes')
164+
configure_xcschemes!(xcschemes_path, project_root, target_platform, name)
168165

169166
# Link source files
170167
%w[ReactTestApp ReactTestAppTests ReactTestAppUITests].each do |file|

ios/xcode.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'rexml/document'
2+
13
IPHONEOS_DEPLOYMENT_TARGET = 'IPHONEOS_DEPLOYMENT_TARGET'.freeze
24
MACOSX_DEPLOYMENT_TARGET = 'MACOSX_DEPLOYMENT_TARGET'.freeze
35
XROS_DEPLOYMENT_TARGET = 'XROS_DEPLOYMENT_TARGET'.freeze
@@ -20,3 +22,25 @@ def override_build_settings!(build_settings, overrides)
2022
build_settings[setting] = value
2123
end
2224
end
25+
26+
def configure_xcschemes!(xcschemes_path, project_root, target_platform, name)
27+
xcscheme = File.join(xcschemes_path, 'ReactTestApp.xcscheme')
28+
metal_api_validation = platform_config('metalAPIValidation', project_root, target_platform)
29+
30+
# Oddly enough, to disable Metal API validation, we need to add `enableGPUValidationMode = "1"`
31+
# to the xcscheme Launch Action.
32+
if metal_api_validation == false
33+
xcscheme_content = File.read(xcscheme)
34+
doc = REXML::Document.new(xcscheme_content)
35+
doc.root.elements['LaunchAction'].attributes['enableGPUValidationMode'] = '1'
36+
37+
File.open(xcscheme, 'w') do |file|
38+
doc.write(file, 3)
39+
end
40+
end
41+
42+
return if name.nil?
43+
44+
# Make a copy of the ReactTestApp.xcscheme file with the app name for convenience.
45+
FileUtils.cp(xcscheme, File.join(xcschemes_path, "#{name}.xcscheme"))
46+
end

schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@
8484
"markdownDescription": "Sets the\n<a href='https://help.apple.com/xcode/mac/current/#/dev23aab79b4'>development\nteam</a> that the app should be assigned to.\n\nThis is the same as setting `DEVELOPMENT_TEAM` in Xcode.\n\n<details>\n<summary>History</summary>\n\n- [[0.9.7](https://github.com/microsoft/react-native-test-app/releases/tag/0.9.7)]\n Added\n\n</details>",
8585
"type": "string"
8686
},
87+
"metalAPIValidation": {
88+
"description": "The API Validation layer checks for code that calls the Metal API incorrectly, including errors in creating resources, encoding Metal commands, and performing other common tasks.",
89+
"markdownDescription": "The API Validation layer checks for code that calls the Metal API incorrectly,\nincluding errors in creating resources, encoding Metal commands, and performing\nother common tasks.\n\n> [!NOTE]\n>\n> The API validation layer has a small, but measureable, impact on CPU\n> performance.\n\nFor more details, read Apple's documentation on\n[Validating your app’s Metal API usage](https://developer.apple.com/documentation/xcode/validating-your-apps-metal-api-usage/).\n\n<details>\n<summary>History</summary>\n\n- [[4.1.0](https://github.com/microsoft/react-native-test-app/releases/tag/4.1.0)]\n Added\n\n</details>",
90+
"type": "boolean"
91+
},
8792
"privacyManifest": {
8893
"description": "The privacy manifest is a property list that records the information regarding the types of data collected and the required reasons APIs your app or third-party SDK use.",
8994
"markdownDescription": "The privacy manifest is a property list that records the information regarding\nthe types of data collected and the required reasons APIs your app or\nthird-party SDK use.\n\n- The types of data collected by your app or third-party SDK must be provided on\n all platforms.\n- The required reasons APIs your app or third-party SDK uses must be provided on\n iOS, iPadOS, tvOS, visionOS, and watchOS.\n\nBy default, a `PrivacyInfo.xcprivacy` is always generated with the following\nvalues:\n\n<!-- prettier-ignore-start -->\n```json\n{\n \"NSPrivacyTracking\": false,\n \"NSPrivacyTrackingDomains\": [],\n \"NSPrivacyCollectedDataTypes\": [],\n \"NSPrivacyAccessedAPITypes\": [\n {\n \"NSPrivacyAccessedAPIType\":\n \"NSPrivacyAccessedAPICategoryFileTimestamp\",\n \"NSPrivacyAccessedAPITypeReasons\": [\"C617.1\"]\n },\n {\n \"NSPrivacyAccessedAPIType\":\n \"NSPrivacyAccessedAPICategorySystemBootTime\",\n \"NSPrivacyAccessedAPITypeReasons\": [\"35F9.1\"]\n },\n {\n \"NSPrivacyAccessedAPIType\":\n \"NSPrivacyAccessedAPICategoryUserDefaults\",\n \"NSPrivacyAccessedAPITypeReasons\": [\"CA92.1\"]\n }\n ]\n}\n```\n<!-- prettier-ignore-end -->\n\nFor more details, read Apple's documentation on\n[Privacy manifest files](https://developer.apple.com/documentation/bundleresources/privacy_manifest_files).\n\n<details>\n<summary>History</summary>\n\n- [[3.6.0](https://github.com/microsoft/react-native-test-app/releases/tag/3.6.0)]\n Added\n\n</details>",

scripts/internal/generate-schema.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export async function readDocumentation(): Promise<Partial<Docs>> {
5252
"ios.icons",
5353
"ios.icons.primaryIcon",
5454
"ios.icons.alternateIcons",
55+
"ios.metalAPIValidation",
5556
"ios.privacyManifest",
5657
"macos.applicationCategoryType",
5758
"macos.humanReadableCopyright",

scripts/schema.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ export function generateSchema(docs = {}) {
9393
markdownDescription: docs["ios.developmentTeam"],
9494
type: "string",
9595
},
96+
metalAPIValidation: {
97+
description: extractBrief(docs["ios.metalAPIValidation"]),
98+
markdownDescription: docs["ios.metalAPIValidation"],
99+
type: "boolean",
100+
},
96101
privacyManifest: {
97102
description: extractBrief(docs["ios.privacyManifest"]),
98103
markdownDescription: docs["ios.privacyManifest"],

scripts/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export type Docs = {
217217
"ios.icons": string;
218218
"ios.icons.primaryIcon": string;
219219
"ios.icons.alternateIcons": string;
220+
"ios.metalAPIValidation": string;
220221
"ios.privacyManifest": string;
221222
"macos.applicationCategoryType": string;
222223
"macos.humanReadableCopyright": string;

0 commit comments

Comments
 (0)