Skip to content

Commit a45ca6f

Browse files
committed
feat(ios): support disabling metal validation
1 parent ac8e2e7 commit a45ca6f

File tree

9 files changed

+50
-4
lines changed

9 files changed

+50
-4
lines changed

docs/ios.metalAPIValidation.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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:_** The API Validation layer has a small, but measureable, impact on
6+
> CPU performance.
7+
8+
By default, a `PrivacyInfo.xcprivacy` is on,
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+
</details>

example/app.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"presentationStyle": "modal"
1414
}
1515
],
16+
"ios": {
17+
"metalAPIValidation": true
18+
},
1619
"resources": {
1720
"android": [
1821
"dist/res",

example/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,11 +1712,11 @@ EXTERNAL SOURCES:
17121712

17131713
SPEC CHECKSUMS:
17141714
boost: 4cb898d0bf20404aab1850c656dcea009429d6c1
1715-
DoubleConversion: 76ab83afb40bddeeee456813d9c04f67f78771b5
1715+
DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953
17161716
Example-Tests: fc629729804712c34ae6c28b9fc1c45619f6636d
17171717
FBLazyVector: 430e10366de01d1e3d57374500b1b150fe482e6d
17181718
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
1719-
glog: 69ef571f3de08433d766d614c73a9838a06bf7eb
1719+
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
17201720
RCT-Folly: 4464f4d875961fce86008d45f4ecf6cef6de0740
17211721
RCTDeprecation: 726d24248aeab6d7180dac71a936bbca6a994ed1
17221722
RCTRequired: a94e7febda6db0345d207e854323c37e3a31d93b
@@ -1780,4 +1780,4 @@ SPEC CHECKSUMS:
17801780

17811781
PODFILE CHECKSUM: c9e179d1d59e47eaa6fef9316a7e039dbb9b0c0b
17821782

1783-
COCOAPODS: 1.14.3
1783+
COCOAPODS: 1.15.2

ios/ReactTestApp.xcodeproj/xcshareddata/xcschemes/ReactTestApp.xcscheme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
ignoresPersistentStateOnLaunch = "NO"
6060
debugDocumentVersioning = "YES"
6161
debugServiceExtension = "internal"
62+
enableGPUValidationMode = "1"
6263
allowLocationSimulation = "YES">
6364
<BuildableProductRunnable
6465
runnableDebuggingMode = "0">

ios/test_app.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,27 @@ 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+
xcschemes_path = File.join(xcodeproj_dst, 'xcshareddata', 'xcschemes')
164+
165+
# Read "metalAPIValidation from the app config and apply it to the xcscheme"
166+
metal_api_validation = platform_config('metalAPIValidation', project_root, target_platform)
167+
puts "metalAPIValidation: #{metal_api_validation}"
168+
169+
if metal_api_validation
170+
xcscheme = File.join(xcschemes_path, "ReactTestApp.xcscheme")
171+
puts "xcscheme: #{xcscheme}"
172+
xcscheme_content = File.read(xcscheme)
173+
new_content = xcscheme_content.gsub(/^\s*enableGPUValidationMode\s*=\s*"1"\s*$/, '')
174+
puts "new_content: #{new_content}"
175+
File.write(xcscheme, new_content)
176+
end
177+
163178
unless name.nil?
164-
xcschemes_path = File.join(xcodeproj_dst, 'xcshareddata', 'xcschemes')
165179
FileUtils.cp(File.join(xcschemes_path, 'ReactTestApp.xcscheme'),
166180
File.join(xcschemes_path, "#{name}.xcscheme"))
167181
end
168182

183+
169184
# Link source files
170185
%w[ReactTestApp ReactTestAppTests ReactTestAppUITests].each do |file|
171186
FileUtils.ln_sf(project_path(file, target_platform), destination)

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": "Whether to enable Metal API validation.",
89+
"markdownDescription":"Whether to enable Metal API validation.",
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)