载入中...
搜索中...
未找到
Capabilities.cpp
浏览该文件的文档.
2
3#include <algorithm>
4
5namespace eve::graphics::webgpu {
6
7namespace {
8constexpr uint32_t kDefaultSampleCount = 4;
9} // namespace
10
11WGPUTextureFormat Capabilities::querySurfaceFormat(wgpu::Adapter &adapter,
12 wgpu::Surface &surface,
13 WGPUTextureFormat defaultFormat) {
14 if (!surface || !adapter) return defaultFormat;
15 WGPUSurfaceCapabilities caps{};
16 if (wgpuSurfaceGetCapabilities(surface.Get(), adapter.Get(), &caps) == WGPUStatus_Success &&
17 caps.formatCount > 0) {
18 WGPUTextureFormat fmt = caps.formats[0];
19 wgpuSurfaceCapabilitiesFreeMembers(caps);
20 return fmt;
21 }
22 wgpuSurfaceCapabilitiesFreeMembers(caps);
23 return defaultFormat;
24}
25
26void Capabilities::capture(wgpu::Adapter &adapter, wgpu::Device &device) {
27 // Device limits give the authoritative budget for the feature gates the
28 // backend actually uses (sample count, bind groups, dynamic uniform
29 // buffers, texture dimension). Fall back to the adapter limits when the
30 // device has not been created yet.
31 wgpu::Limits limits{};
32 bool ok = false;
33 if (device) {
34 ok = (device.GetLimits(&limits) == wgpu::Status::Success);
35 } else if (adapter) {
36 ok = (adapter.GetLimits(&limits) == wgpu::Status::Success);
37 }
38 if (ok) {
39 if (limits.maxTextureDimension2D != wgpu::kLimitU32Undefined)
40 maxTextureDim2D_ = limits.maxTextureDimension2D;
41 if (limits.maxBindGroups != wgpu::kLimitU32Undefined)
42 maxBindGroups_ = limits.maxBindGroups;
43 if (limits.maxDynamicUniformBuffersPerPipelineLayout != wgpu::kLimitU32Undefined)
44 maxDynamicUniformBuffers_ = limits.maxDynamicUniformBuffersPerPipelineLayout;
45 if (limits.maxSampledTexturesPerShaderStage != wgpu::kLimitU32Undefined)
46 maxSampledTexturesPerShaderStage_ = limits.maxSampledTexturesPerShaderStage;
47 if (limits.maxSamplersPerShaderStage != wgpu::kLimitU32Undefined)
48 maxSamplersPerShaderStage_ = limits.maxSamplersPerShaderStage;
49 // Max sample count is not a single limit; cap conservatively at 4.
50 maxSampleCount_ = std::min<uint32_t>(maxSampleCount_, 4u);
51 }
52 captured_ = true;
53}
54
56 if (!captured_) return count <= kDefaultSampleCount;
57 if (count <= 1) return true;
58 return count <= maxSampleCount_;
59}
60
61bool Capabilities::supportsFormat(WGPUTextureFormat format) const {
62 // The formats the backend creates are core WebGPU renderable formats that
63 // the fixed pipelines require; report them as supported.
64 switch (format) {
65 case WGPUTextureFormat_RGBA8Unorm:
66 case WGPUTextureFormat_Depth32Float:
67 return true;
68 default:
69 return false;
70 }
71}
72
73} // namespace eve::graphics::webgpu
vkb::Device & device
std::uint32_t count
std::string_view adapter
int caps
Definition TreeMesh.cpp:162
const AssetImportLimits & limits
void capture(wgpu::Adapter &adapter, wgpu::Device &device)
Populate the snapshot from an adapter and device. Call once, right after device creation; keep the re...
bool supportsSampleCount(uint32_t count) const
True when the device supports the given render-target sample count.
static WGPUTextureFormat querySurfaceFormat(wgpu::Adapter &adapter, wgpu::Surface &surface, WGPUTextureFormat defaultFormat)
Query the surface's preferred format from the adapter. Falls back to defaultFormat when the surface r...
bool supportsFormat(WGPUTextureFormat format) const
True when the device advertises the given texture format.