-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an example of enumerating device adapters
- Loading branch information
Showing
5 changed files
with
140 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.dub | ||
docs.json | ||
__dummy.html | ||
docs/ | ||
/headless | ||
headless.so | ||
headless.dylib | ||
headless.dll | ||
headless.a | ||
headless.lib | ||
headless-test-* | ||
*.exe | ||
*.o | ||
*.obj | ||
*.lst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "enumerate", | ||
"description": "Enumerate GPU adapters example", | ||
"authors": [ | ||
"Chance Snow" | ||
], | ||
"license": "MIT", | ||
"copyright": "Copyright © 2023, Chance Snow", | ||
"targetType": "executable", | ||
"targetPath": "../../bin", | ||
"dependencies": { | ||
"wgpu-d": { | ||
"path": "../.." | ||
} | ||
}, | ||
"preBuildCommands-osx": [ | ||
"echo Fixing up libwgpu dylib path...", | ||
"rm -f `find $PACKAGE_DIR/../../bin -name '*enumerate'`" | ||
], | ||
"postBuildCommands-osx": [ | ||
"echo Fixing up libwgpu dylib path...", | ||
"install_name_tool -change /Users/runner/work/wgpu-native/wgpu-native/target/x86_64-apple-darwin/debug/deps/libwgpu_native.dylib @executable_path/../lib/libwgpu_native.dylib `find $PACKAGE_DIR/../../bin -name '*enumerate'`" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import std.conv : text, to; | ||
import std.stdio; | ||
import std.string : fromStringz; | ||
|
||
import wgpu.api; | ||
|
||
// Adapted from https://github.com/gfx-rs/wgpu-rs/blob/f6123e4fe89f74754093c07b476099623b76dd08/examples/capture/main.rs | ||
void main() { | ||
writeln("Enumerating Device Adapters Example"); | ||
|
||
auto instance = Instance.create(); | ||
assert(instance.id, "Could not create WebGPU instance."); | ||
|
||
writefln("Preferred backend type? %s", cast(BackendType) instance.report.backendType); | ||
auto adapters = instance.adapters; | ||
writefln("Found %d suitable adapters:", adapters.length); | ||
for (int i = 0; i < adapters.length; i++) { | ||
auto adapter = adapters[i]; | ||
auto props = adapter.properties; | ||
writefln("Adapter %d", i); | ||
writefln("\tvendorID: %u", props.vendorID); | ||
writefln("\tvendorName: %s", props.vendorName.fromStringz.to!string); | ||
writefln("\tarchitecture: %s", props.architecture.fromStringz.to!string); | ||
writefln("\tdeviceID: %u", props.deviceID); | ||
writefln("\tname: %s", props.name.fromStringz.to!string); | ||
writefln("\tdriverDescription: %s", props.driverDescription.fromStringz.to!string); | ||
writefln("\tadapterType: %s", cast(AdapterType) props.adapterType); | ||
writefln("\tbackendType: %s", cast(BackendType) props.backendType); | ||
writeln(); | ||
adapter.destroy(); | ||
} | ||
|
||
auto adapter = instance.requestAdapter(PowerPreference.lowPower, BackendType.d3d12 | BackendType.vulkan); | ||
assert(adapter.ready, "Adapter instance was not initialized: Adapter status: " ~ adapter.status.text); | ||
writefln("Adapter limits:\n%s", adapter.limits.toString); | ||
writeln(); | ||
|
||
auto device = adapter.requestDevice(adapter.limits); | ||
assert(device.ready, "Device is not ready: Device status: " ~ device.status.text); | ||
writefln("Device limits:\n%s", device.limits.toString); | ||
writeln(); | ||
|
||
device.destroy(); | ||
adapter.destroy(); | ||
instance.destroy(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters