mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
Add wgpuDeviceGetLimits. Split Required/Supported limit structs
Bug: dawn:685 Change-Id: Ibb5dd0479f5e887d4b2ca864c014ebaafb674dba Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/64443 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
@@ -20,7 +20,6 @@ namespace dawn_native {
|
||||
|
||||
AdapterBase::AdapterBase(InstanceBase* instance, wgpu::BackendType backend)
|
||||
: mInstance(instance), mBackend(backend) {
|
||||
mLimits.v1.nextInChain = nullptr;
|
||||
GetDefaultLimits(&mLimits.v1);
|
||||
mSupportedExtensions.EnableExtension(Extension::DawnInternalUsages);
|
||||
}
|
||||
@@ -74,16 +73,16 @@ namespace dawn_native {
|
||||
// to store them (ex. by calling GetLimits directly instead). Currently,
|
||||
// we keep this function as it's only used internally in Chromium to
|
||||
// send the adapter properties across the wire.
|
||||
GetLimits(reinterpret_cast<wgpu::Limits*>(&adapterProperties.limits));
|
||||
GetLimits(reinterpret_cast<SupportedLimits*>(&adapterProperties.limits));
|
||||
return adapterProperties;
|
||||
}
|
||||
|
||||
bool AdapterBase::GetLimits(wgpu::Limits* limits) const {
|
||||
bool AdapterBase::GetLimits(SupportedLimits* limits) const {
|
||||
ASSERT(limits != nullptr);
|
||||
if (limits->nextInChain != nullptr) {
|
||||
return false;
|
||||
}
|
||||
*limits = mLimits.v1;
|
||||
limits->limits = mLimits.v1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -125,7 +124,8 @@ namespace dawn_native {
|
||||
|
||||
if (descriptor != nullptr && descriptor->requiredLimits != nullptr) {
|
||||
DAWN_TRY(ValidateLimits(
|
||||
mLimits.v1, *reinterpret_cast<const wgpu::Limits*>(descriptor->requiredLimits)));
|
||||
mLimits.v1,
|
||||
reinterpret_cast<const RequiredLimits*>(descriptor->requiredLimits)->limits));
|
||||
|
||||
if (descriptor->requiredLimits->nextInChain != nullptr) {
|
||||
return DAWN_VALIDATION_ERROR("Unsupported limit extension struct");
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace dawn_native {
|
||||
const std::vector<const char*>& requestedExtensions) const;
|
||||
WGPUDeviceProperties GetAdapterProperties() const;
|
||||
|
||||
bool GetLimits(wgpu::Limits* limits) const;
|
||||
bool GetLimits(SupportedLimits* limits) const;
|
||||
|
||||
virtual bool SupportsExternalImages() const = 0;
|
||||
|
||||
|
||||
@@ -106,8 +106,8 @@ namespace dawn_native {
|
||||
return mImpl->GetAdapterProperties();
|
||||
}
|
||||
|
||||
bool Adapter::GetLimits(WGPULimits* limits) const {
|
||||
return mImpl->GetLimits(reinterpret_cast<wgpu::Limits*>(limits));
|
||||
bool Adapter::GetLimits(WGPUSupportedLimits* limits) const {
|
||||
return mImpl->GetLimits(reinterpret_cast<SupportedLimits*>(limits));
|
||||
}
|
||||
|
||||
bool Adapter::SupportsExternalImages() const {
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace dawn_native {
|
||||
|
||||
if (descriptor != nullptr && descriptor->requiredLimits != nullptr) {
|
||||
mLimits.v1 = ReifyDefaultLimits(
|
||||
*reinterpret_cast<const wgpu::Limits*>(descriptor->requiredLimits));
|
||||
reinterpret_cast<const RequiredLimits*>(descriptor->requiredLimits)->limits);
|
||||
} else {
|
||||
GetDefaultLimits(&mLimits.v1);
|
||||
}
|
||||
@@ -1093,6 +1093,15 @@ namespace dawn_native {
|
||||
}
|
||||
}
|
||||
|
||||
bool DeviceBase::APIGetLimits(SupportedLimits* limits) {
|
||||
ASSERT(limits != nullptr);
|
||||
if (limits->nextInChain != nullptr) {
|
||||
return false;
|
||||
}
|
||||
limits->limits = mLimits.v1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeviceBase::APIInjectError(wgpu::ErrorType type, const char* message) {
|
||||
if (ConsumedError(ValidateErrorType(type))) {
|
||||
return;
|
||||
|
||||
@@ -209,6 +209,7 @@ namespace dawn_native {
|
||||
|
||||
QueueBase* APIGetQueue();
|
||||
|
||||
bool APIGetLimits(SupportedLimits* limits);
|
||||
void APIInjectError(wgpu::ErrorType type, const char* message);
|
||||
bool APITick();
|
||||
|
||||
|
||||
@@ -94,15 +94,15 @@ namespace dawn_native {
|
||||
|
||||
} // namespace
|
||||
|
||||
void GetDefaultLimits(wgpu::Limits* limits) {
|
||||
void GetDefaultLimits(Limits* limits) {
|
||||
ASSERT(limits != nullptr);
|
||||
#define X(Better, limitName, defaultValue) limits->limitName = defaultValue;
|
||||
LIMITS(X)
|
||||
#undef X
|
||||
}
|
||||
|
||||
wgpu::Limits ReifyDefaultLimits(const wgpu::Limits& limits) {
|
||||
wgpu::Limits out;
|
||||
Limits ReifyDefaultLimits(const Limits& limits) {
|
||||
Limits out;
|
||||
#define X(Better, limitName, defaultValue) \
|
||||
if (!IsLimitUndefined(limits.limitName)) { \
|
||||
out.limitName = limits.limitName; \
|
||||
@@ -114,8 +114,7 @@ namespace dawn_native {
|
||||
return out;
|
||||
}
|
||||
|
||||
MaybeError ValidateLimits(const wgpu::Limits& supportedLimits,
|
||||
const wgpu::Limits& requiredLimits) {
|
||||
MaybeError ValidateLimits(const Limits& supportedLimits, const Limits& requiredLimits) {
|
||||
#define X(Better, limitName, defaultValue) \
|
||||
if (!IsLimitUndefined(requiredLimits.limitName)) { \
|
||||
DAWN_TRY(CheckLimit<LimitBetterDirection::Better>::Invoke(supportedLimits.limitName, \
|
||||
|
||||
@@ -21,19 +21,18 @@
|
||||
namespace dawn_native {
|
||||
|
||||
struct CombinedLimits {
|
||||
wgpu::Limits v1;
|
||||
Limits v1;
|
||||
};
|
||||
|
||||
// Populate |limits| with the default limits.
|
||||
void GetDefaultLimits(wgpu::Limits* limits);
|
||||
void GetDefaultLimits(Limits* limits);
|
||||
|
||||
// Returns a copy of |limits| where all undefined values are replaced
|
||||
// with their defaults.
|
||||
wgpu::Limits ReifyDefaultLimits(const wgpu::Limits& limits);
|
||||
Limits ReifyDefaultLimits(const Limits& limits);
|
||||
|
||||
// Validate that |requiredLimits| are no better than |supportedLimits|.
|
||||
MaybeError ValidateLimits(const wgpu::Limits& supportedLimits,
|
||||
const wgpu::Limits& requiredLimits);
|
||||
MaybeError ValidateLimits(const Limits& supportedLimits, const Limits& requiredLimits);
|
||||
|
||||
} // namespace dawn_native
|
||||
|
||||
|
||||
@@ -196,6 +196,12 @@ namespace dawn_wire { namespace client {
|
||||
return Buffer::CreateError(this);
|
||||
}
|
||||
|
||||
bool Device::GetLimits(WGPUSupportedLimits* limits) {
|
||||
// Not implemented in the wire.
|
||||
UNREACHABLE();
|
||||
return false;
|
||||
}
|
||||
|
||||
WGPUQueue Device::GetQueue() {
|
||||
// The queue is lazily created because if a Device is created by
|
||||
// Reserve/Inject, we cannot send the GetQueue message until
|
||||
|
||||
@@ -64,6 +64,7 @@ namespace dawn_wire { namespace client {
|
||||
WGPUCreatePipelineAsyncStatus status,
|
||||
const char* message);
|
||||
|
||||
bool GetLimits(WGPUSupportedLimits* limits);
|
||||
WGPUQueue GetQueue();
|
||||
|
||||
void CancelCallbacksForDisconnect() override;
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace dawn_native {
|
||||
std::vector<const char*> forceEnabledToggles;
|
||||
std::vector<const char*> forceDisabledToggles;
|
||||
|
||||
const WGPULimits* requiredLimits = nullptr;
|
||||
const WGPURequiredLimits* requiredLimits = nullptr;
|
||||
};
|
||||
|
||||
// A struct to record the information of a toggle. A toggle is a code path in Dawn device that
|
||||
@@ -110,7 +110,7 @@ namespace dawn_native {
|
||||
|
||||
std::vector<const char*> GetSupportedExtensions() const;
|
||||
WGPUDeviceProperties GetAdapterProperties() const;
|
||||
bool GetLimits(WGPULimits* limits) const;
|
||||
bool GetLimits(WGPUSupportedLimits* limits) const;
|
||||
|
||||
// Check that the Adapter is able to support importing external images. This is necessary
|
||||
// to implement the swapchain and interop APIs in Chromium.
|
||||
|
||||
@@ -61,6 +61,16 @@ namespace dawn_wire {
|
||||
const volatile char* deserializeBuffer,
|
||||
size_t deserializeBufferSize);
|
||||
|
||||
DAWN_WIRE_EXPORT size_t
|
||||
SerializedWGPUSupportedLimitsSize(const WGPUSupportedLimits* supportedLimits);
|
||||
|
||||
DAWN_WIRE_EXPORT void SerializeWGPUSupportedLimits(const WGPUSupportedLimits* supportedLimits,
|
||||
char* serializeBuffer);
|
||||
|
||||
DAWN_WIRE_EXPORT bool DeserializeWGPUSupportedLimits(WGPUSupportedLimits* supportedLimits,
|
||||
const volatile char* deserializeBuffer,
|
||||
size_t deserializeBufferSize);
|
||||
|
||||
} // namespace dawn_wire
|
||||
|
||||
#endif // DAWNWIRE_WIRE_H_
|
||||
|
||||
@@ -29,6 +29,10 @@ class RequestDeviceValidationTest : public ValidationTest {
|
||||
EXPECT_EQ(status, WGPURequestDeviceStatus_Success);
|
||||
EXPECT_NE(device, nullptr);
|
||||
EXPECT_STREQ(message, nullptr);
|
||||
if (userdata != nullptr) {
|
||||
CallCheckDevice(static_cast<std::function<void(wgpu::Device)>*>(userdata),
|
||||
std::move(device));
|
||||
}
|
||||
}
|
||||
|
||||
static void ExpectRequestDeviceError(WGPURequestDeviceStatus status,
|
||||
@@ -40,73 +44,136 @@ class RequestDeviceValidationTest : public ValidationTest {
|
||||
EXPECT_EQ(device, nullptr);
|
||||
EXPECT_STRNE(message, nullptr);
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
static void* CheckDevice(F&& f) {
|
||||
return new std::function<void(wgpu::Device)>(f);
|
||||
}
|
||||
|
||||
static void CallCheckDevice(std::function<void(wgpu::Device)>* f, wgpu::Device d) {
|
||||
(*f)(std::move(d));
|
||||
delete f;
|
||||
}
|
||||
};
|
||||
|
||||
// Test that requesting a device without specifying limits is valid.
|
||||
TEST_F(RequestDeviceValidationTest, NoRequiredLimits) {
|
||||
dawn_native::DeviceDescriptor descriptor;
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess, nullptr);
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess,
|
||||
CheckDevice([](wgpu::Device device) {
|
||||
// Check one of the default limits.
|
||||
wgpu::SupportedLimits limits;
|
||||
device.GetLimits(&limits);
|
||||
EXPECT_EQ(limits.limits.maxBindGroups, 4u);
|
||||
}));
|
||||
}
|
||||
|
||||
// Test that requesting a device with the default limits is valid.
|
||||
TEST_F(RequestDeviceValidationTest, DefaultLimits) {
|
||||
wgpu::Limits limits = {};
|
||||
wgpu::RequiredLimits limits = {};
|
||||
dawn_native::DeviceDescriptor descriptor;
|
||||
descriptor.requiredLimits = reinterpret_cast<const WGPULimits*>(&limits);
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess, nullptr);
|
||||
descriptor.requiredLimits = reinterpret_cast<const WGPURequiredLimits*>(&limits);
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess,
|
||||
CheckDevice([](wgpu::Device device) {
|
||||
// Check one of the default limits.
|
||||
wgpu::SupportedLimits limits;
|
||||
device.GetLimits(&limits);
|
||||
EXPECT_EQ(limits.limits.maxTextureArrayLayers, 256u);
|
||||
}));
|
||||
}
|
||||
|
||||
// Test that requesting a device where a required limit is above the maximum value.
|
||||
TEST_F(RequestDeviceValidationTest, HigherIsBetter) {
|
||||
wgpu::Limits limits = {};
|
||||
wgpu::RequiredLimits limits = {};
|
||||
dawn_native::DeviceDescriptor descriptor;
|
||||
descriptor.requiredLimits = reinterpret_cast<const WGPULimits*>(&limits);
|
||||
descriptor.requiredLimits = reinterpret_cast<const WGPURequiredLimits*>(&limits);
|
||||
|
||||
wgpu::Limits supportedLimits;
|
||||
EXPECT_TRUE(adapter.GetLimits(reinterpret_cast<WGPULimits*>(&supportedLimits)));
|
||||
wgpu::SupportedLimits supportedLimits;
|
||||
EXPECT_TRUE(adapter.GetLimits(reinterpret_cast<WGPUSupportedLimits*>(&supportedLimits)));
|
||||
|
||||
// Test below the max.
|
||||
limits.maxBindGroups = supportedLimits.maxBindGroups - 1;
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess, nullptr);
|
||||
limits.limits.maxBindGroups = supportedLimits.limits.maxBindGroups - 1;
|
||||
adapter.RequestDevice(
|
||||
&descriptor, ExpectRequestDeviceSuccess, CheckDevice([&](wgpu::Device device) {
|
||||
wgpu::SupportedLimits limits;
|
||||
device.GetLimits(&limits);
|
||||
|
||||
// Check we got exactly the request.
|
||||
EXPECT_EQ(limits.limits.maxBindGroups, supportedLimits.limits.maxBindGroups - 1);
|
||||
// Check another default limit.
|
||||
EXPECT_EQ(limits.limits.maxTextureArrayLayers, 256u);
|
||||
}));
|
||||
|
||||
// Test the max.
|
||||
limits.maxBindGroups = supportedLimits.maxBindGroups;
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess, nullptr);
|
||||
limits.limits.maxBindGroups = supportedLimits.limits.maxBindGroups;
|
||||
adapter.RequestDevice(
|
||||
&descriptor, ExpectRequestDeviceSuccess, CheckDevice([&](wgpu::Device device) {
|
||||
wgpu::SupportedLimits limits;
|
||||
device.GetLimits(&limits);
|
||||
|
||||
// Check we got exactly the request.
|
||||
EXPECT_EQ(limits.limits.maxBindGroups, supportedLimits.limits.maxBindGroups);
|
||||
// Check another default limit.
|
||||
EXPECT_EQ(limits.limits.maxTextureArrayLayers, 256u);
|
||||
}));
|
||||
|
||||
// Test above the max.
|
||||
limits.maxBindGroups = supportedLimits.maxBindGroups + 1;
|
||||
limits.limits.maxBindGroups = supportedLimits.limits.maxBindGroups + 1;
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceError, nullptr);
|
||||
}
|
||||
|
||||
// Test that requesting a device where a required limit is below the minimum value.
|
||||
TEST_F(RequestDeviceValidationTest, LowerIsBetter) {
|
||||
wgpu::Limits limits = {};
|
||||
wgpu::RequiredLimits limits = {};
|
||||
dawn_native::DeviceDescriptor descriptor;
|
||||
descriptor.requiredLimits = reinterpret_cast<const WGPULimits*>(&limits);
|
||||
descriptor.requiredLimits = reinterpret_cast<const WGPURequiredLimits*>(&limits);
|
||||
|
||||
wgpu::Limits supportedLimits;
|
||||
EXPECT_TRUE(adapter.GetLimits(reinterpret_cast<WGPULimits*>(&supportedLimits)));
|
||||
wgpu::SupportedLimits supportedLimits;
|
||||
EXPECT_TRUE(adapter.GetLimits(reinterpret_cast<WGPUSupportedLimits*>(&supportedLimits)));
|
||||
|
||||
// Test below the min.
|
||||
limits.minUniformBufferOffsetAlignment = supportedLimits.minUniformBufferOffsetAlignment / 2;
|
||||
limits.limits.minUniformBufferOffsetAlignment =
|
||||
supportedLimits.limits.minUniformBufferOffsetAlignment / 2;
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceError, nullptr);
|
||||
|
||||
// Test the min.
|
||||
limits.minUniformBufferOffsetAlignment = supportedLimits.minUniformBufferOffsetAlignment;
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess, nullptr);
|
||||
limits.limits.minUniformBufferOffsetAlignment =
|
||||
supportedLimits.limits.minUniformBufferOffsetAlignment;
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess,
|
||||
CheckDevice([&](wgpu::Device device) {
|
||||
wgpu::SupportedLimits limits;
|
||||
device.GetLimits(&limits);
|
||||
|
||||
// Check we got exactly the request.
|
||||
EXPECT_EQ(limits.limits.minUniformBufferOffsetAlignment,
|
||||
supportedLimits.limits.minUniformBufferOffsetAlignment);
|
||||
// Check another default limit.
|
||||
EXPECT_EQ(limits.limits.maxTextureArrayLayers, 256u);
|
||||
}));
|
||||
|
||||
// Test above the min.
|
||||
limits.minUniformBufferOffsetAlignment = supportedLimits.minUniformBufferOffsetAlignment * 2;
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess, nullptr);
|
||||
limits.limits.minUniformBufferOffsetAlignment =
|
||||
supportedLimits.limits.minUniformBufferOffsetAlignment * 2;
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess,
|
||||
CheckDevice([&](wgpu::Device device) {
|
||||
wgpu::SupportedLimits limits;
|
||||
device.GetLimits(&limits);
|
||||
|
||||
// Check we got exactly the request.
|
||||
EXPECT_EQ(limits.limits.minUniformBufferOffsetAlignment,
|
||||
supportedLimits.limits.minUniformBufferOffsetAlignment * 2);
|
||||
// Check another default limit.
|
||||
EXPECT_EQ(limits.limits.maxTextureArrayLayers, 256u);
|
||||
}));
|
||||
}
|
||||
|
||||
// Test that it is an error to request limits with an invalid chained struct
|
||||
TEST_F(RequestDeviceValidationTest, InvalidChainedStruct) {
|
||||
wgpu::PrimitiveDepthClampingState depthClamp = {};
|
||||
wgpu::Limits limits = {};
|
||||
wgpu::RequiredLimits limits = {};
|
||||
limits.nextInChain = &depthClamp;
|
||||
|
||||
dawn_native::DeviceDescriptor descriptor;
|
||||
descriptor.requiredLimits = reinterpret_cast<const WGPULimits*>(&limits);
|
||||
descriptor.requiredLimits = reinterpret_cast<const WGPURequiredLimits*>(&limits);
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceError, nullptr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user