-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement wgpuAdapterGetLimits, add test that limit requests are appl…
…ied (#21799) - Implement the wgpuAdapterGetLimits entry point. - Add a test which verifies that limit requests are correctly passed through to requestDevice(), by requesting all of the adapter's max limits, then ensuring that the device has the same limits. This verifies that wgpuAdapterGetLimits and wgpuDeviceGetLimits work, and that limit requests are applied (though it can only verify limits for which the current system supports a value better than the default). Fixes #21798
- Loading branch information
1 parent
c54609c
commit 849342f
Showing
3 changed files
with
153 additions
and
46 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
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,95 @@ | ||
#include <assert.h> | ||
#include <emscripten.h> | ||
#include <stdio.h> | ||
#include <webgpu/webgpu.h> | ||
|
||
WGPUSupportedLimits adapter_supported_limits = { | ||
0, | ||
}; | ||
|
||
void assertLimitsCompatible(WGPULimits required_limits, | ||
WGPULimits supported_limits) { | ||
#define ASSERT_LIMITS_COMPATIBLE(limitName) \ | ||
assert(required_limits.limitName == supported_limits.limitName) | ||
ASSERT_LIMITS_COMPATIBLE(maxTextureDimension1D); | ||
ASSERT_LIMITS_COMPATIBLE(maxTextureDimension2D); | ||
ASSERT_LIMITS_COMPATIBLE(maxTextureDimension3D); | ||
ASSERT_LIMITS_COMPATIBLE(maxTextureArrayLayers); | ||
ASSERT_LIMITS_COMPATIBLE(maxBindGroups); | ||
ASSERT_LIMITS_COMPATIBLE(maxBindGroupsPlusVertexBuffers); | ||
ASSERT_LIMITS_COMPATIBLE(maxBindingsPerBindGroup); | ||
ASSERT_LIMITS_COMPATIBLE(maxDynamicUniformBuffersPerPipelineLayout); | ||
ASSERT_LIMITS_COMPATIBLE(maxDynamicStorageBuffersPerPipelineLayout); | ||
ASSERT_LIMITS_COMPATIBLE(maxSampledTexturesPerShaderStage); | ||
ASSERT_LIMITS_COMPATIBLE(maxSamplersPerShaderStage); | ||
ASSERT_LIMITS_COMPATIBLE(maxStorageBuffersPerShaderStage); | ||
ASSERT_LIMITS_COMPATIBLE(maxStorageTexturesPerShaderStage); | ||
ASSERT_LIMITS_COMPATIBLE(maxUniformBuffersPerShaderStage); | ||
ASSERT_LIMITS_COMPATIBLE(minUniformBufferOffsetAlignment); | ||
ASSERT_LIMITS_COMPATIBLE(minStorageBufferOffsetAlignment); | ||
ASSERT_LIMITS_COMPATIBLE(maxUniformBufferBindingSize); | ||
ASSERT_LIMITS_COMPATIBLE(maxStorageBufferBindingSize); | ||
ASSERT_LIMITS_COMPATIBLE(maxVertexBuffers); | ||
ASSERT_LIMITS_COMPATIBLE(maxBufferSize); | ||
ASSERT_LIMITS_COMPATIBLE(maxVertexAttributes); | ||
ASSERT_LIMITS_COMPATIBLE(maxVertexBufferArrayStride); | ||
ASSERT_LIMITS_COMPATIBLE(maxInterStageShaderComponents); | ||
ASSERT_LIMITS_COMPATIBLE(maxInterStageShaderVariables); | ||
ASSERT_LIMITS_COMPATIBLE(maxColorAttachments); | ||
ASSERT_LIMITS_COMPATIBLE(maxColorAttachmentBytesPerSample); | ||
ASSERT_LIMITS_COMPATIBLE(maxComputeWorkgroupStorageSize); | ||
ASSERT_LIMITS_COMPATIBLE(maxComputeInvocationsPerWorkgroup); | ||
ASSERT_LIMITS_COMPATIBLE(maxComputeWorkgroupSizeX); | ||
ASSERT_LIMITS_COMPATIBLE(maxComputeWorkgroupSizeY); | ||
ASSERT_LIMITS_COMPATIBLE(maxComputeWorkgroupSizeZ); | ||
ASSERT_LIMITS_COMPATIBLE(maxComputeWorkgroupsPerDimension); | ||
#undef ASSERT_LIMITS_COMPATIBLE | ||
} | ||
|
||
void on_device_request_ended(WGPURequestDeviceStatus status, | ||
WGPUDevice device, | ||
char const* message, | ||
void* userdata) { | ||
assert(status == WGPURequestDeviceStatus_Success); | ||
|
||
WGPUSupportedLimits device_supported_limits; | ||
wgpuDeviceGetLimits(device, &device_supported_limits); | ||
|
||
// verify that the obtained device fullfils required limits | ||
assertLimitsCompatible(adapter_supported_limits.limits, | ||
device_supported_limits.limits); | ||
} | ||
|
||
void on_adapter_request_ended(WGPURequestAdapterStatus status, | ||
WGPUAdapter adapter, | ||
char const* message, | ||
void* userdata) { | ||
if (status == WGPURequestAdapterStatus_Unavailable) { | ||
printf("WebGPU unavailable; exiting cleanly\n"); | ||
exit(0); | ||
} | ||
|
||
assert(status == WGPURequestAdapterStatus_Success); | ||
|
||
wgpuAdapterGetLimits(adapter, &adapter_supported_limits); | ||
|
||
// for device limits, require the limits supported by adapter | ||
WGPURequiredLimits device_required_limits = {0,}; | ||
device_required_limits.limits = adapter_supported_limits.limits; | ||
|
||
WGPUDeviceDescriptor device_desc = {0,}; | ||
device_desc.requiredFeatureCount = 0; | ||
device_desc.requiredLimits = &device_required_limits; | ||
wgpuAdapterRequestDevice(adapter, &device_desc, on_device_request_ended, NULL); | ||
} | ||
|
||
int main() { | ||
const WGPUInstance instance = wgpuCreateInstance(NULL); | ||
|
||
WGPURequestAdapterOptions adapter_options = {0,}; | ||
wgpuInstanceRequestAdapter(instance, &adapter_options, on_adapter_request_ended, NULL); | ||
|
||
// This code is returned when the runtime exits unless something else sets | ||
// it, like exit(0). | ||
return 99; | ||
} |