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:
Austin Eng 2021-09-17 15:36:00 +00:00 committed by Dawn LUCI CQ
parent 4ecfc58777
commit bffc966f17
18 changed files with 272 additions and 74 deletions

View File

@ -20,6 +20,7 @@
"adapter properties": { "adapter properties": {
"category": "structure", "category": "structure",
"extensible": true, "extensible": true,
"output": true,
"members": [ "members": [
{"name": "device ID", "type": "uint32_t"}, {"name": "device ID", "type": "uint32_t"},
{"name": "vendor ID", "type": "uint32_t"}, {"name": "vendor ID", "type": "uint32_t"},
@ -734,6 +735,13 @@
{"name": "userdata", "type": "void", "annotation": "*"} {"name": "userdata", "type": "void", "annotation": "*"}
] ]
}, },
{
"name": "create external texture",
"returns": "external texture",
"args": [
{"name": "external texture descriptor", "type": "external texture descriptor", "annotation": "const*"}
]
},
{ {
"name": "create pipeline layout", "name": "create pipeline layout",
"returns": "pipeline layout", "returns": "pipeline layout",
@ -801,15 +809,15 @@
] ]
}, },
{ {
"name": "get queue", "name": "get limits",
"returns": "queue" "returns": "bool",
"args": [
{"name": "limits", "type": "supported limits", "annotation": "*"}
]
}, },
{ {
"name": "create external texture", "name": "get queue",
"returns": "external texture", "returns": "queue"
"args": [
{"name": "external texture descriptor", "type": "external texture descriptor", "annotation": "const*"}
]
}, },
{ {
"name": "inject error", "name": "inject error",
@ -885,7 +893,7 @@
{"name": "depth clamping", "type": "bool", "default": "false"}, {"name": "depth clamping", "type": "bool", "default": "false"},
{"name": "invalid extension", "type": "bool", "default": "false"}, {"name": "invalid extension", "type": "bool", "default": "false"},
{"name": "dawn internal usages", "type": "bool", "default": "false"}, {"name": "dawn internal usages", "type": "bool", "default": "false"},
{"name": "limits", "type": "limits"} {"name": "limits", "type": "supported limits"}
] ]
}, },
"double": { "double": {
@ -901,7 +909,6 @@
}, },
"limits": { "limits": {
"category": "structure", "category": "structure",
"extensible": true,
"members": [ "members": [
{"name": "max texture dimension 1D", "type": "uint32_t", "default": "WGPU_LIMIT_U32_UNDEFINED"}, {"name": "max texture dimension 1D", "type": "uint32_t", "default": "WGPU_LIMIT_U32_UNDEFINED"},
{"name": "max texture dimension 2D", "type": "uint32_t", "default": "WGPU_LIMIT_U32_UNDEFINED"}, {"name": "max texture dimension 2D", "type": "uint32_t", "default": "WGPU_LIMIT_U32_UNDEFINED"},
@ -931,6 +938,21 @@
{"name": "max compute workgroups per dimension", "type": "uint32_t", "default": "WGPU_LIMIT_U32_UNDEFINED"} {"name": "max compute workgroups per dimension", "type": "uint32_t", "default": "WGPU_LIMIT_U32_UNDEFINED"}
] ]
}, },
"required limits": {
"category": "structure",
"extensible": true,
"members": [
{"name": "limits", "type": "limits"}
]
},
"supported limits": {
"category": "structure",
"extensible": true,
"output": true,
"members": [
{"name": "limits", "type": "limits"}
]
},
"logging callback": { "logging callback": {
"category": "callback", "category": "callback",
"args": [ "args": [

View File

@ -153,6 +153,7 @@
"DeviceCreateBuffer", "DeviceCreateBuffer",
"DeviceCreateComputePipelineAsync", "DeviceCreateComputePipelineAsync",
"DeviceCreateRenderPipelineAsync", "DeviceCreateRenderPipelineAsync",
"DeviceGetLimits",
"DevicePopErrorScope", "DevicePopErrorScope",
"DeviceSetDeviceLostCallback", "DeviceSetDeviceLostCallback",
"DeviceSetUncapturedErrorCallback", "DeviceSetUncapturedErrorCallback",

View File

@ -206,6 +206,7 @@ class StructureType(Record, Type):
Type.__init__(self, name, json_data) Type.__init__(self, name, json_data)
self.chained = json_data.get("chained", False) self.chained = json_data.get("chained", False)
self.extensible = json_data.get("extensible", False) self.extensible = json_data.get("extensible", False)
self.output = json_data.get("output", False)
# Chained structs inherit from wgpu::ChainedStruct, which has # Chained structs inherit from wgpu::ChainedStruct, which has
# nextInChain, so setting both extensible and chained would result in # nextInChain, so setting both extensible and chained would result in
# two nextInChain members. # two nextInChain members.

View File

@ -496,7 +496,7 @@ namespace dawn_wire {
} }
size_t GetChainedStructExtraRequiredSize(const WGPUChainedStruct* chainedStruct); size_t GetChainedStructExtraRequiredSize(const WGPUChainedStruct* chainedStruct);
DAWN_NO_DISCARD WireResult SerializeChainedStruct(WGPUChainedStruct const* chainedStruct, DAWN_NO_DISCARD WireResult SerializeChainedStruct(const WGPUChainedStruct* chainedStruct,
SerializeBuffer* buffer, SerializeBuffer* buffer,
const ObjectIdProvider& provider); const ObjectIdProvider& provider);
WireResult DeserializeChainedStruct(const WGPUChainedStruct** outChainNext, WireResult DeserializeChainedStruct(const WGPUChainedStruct** outChainNext,
@ -504,6 +504,15 @@ namespace dawn_wire {
DeserializeAllocator* allocator, DeserializeAllocator* allocator,
const ObjectIdResolver& resolver); const ObjectIdResolver& resolver);
size_t GetChainedStructExtraRequiredSize(WGPUChainedStructOut* chainedStruct);
DAWN_NO_DISCARD WireResult SerializeChainedStruct(WGPUChainedStructOut* chainedStruct,
SerializeBuffer* buffer,
const ObjectIdProvider& provider);
WireResult DeserializeChainedStruct(WGPUChainedStructOut** outChainNext,
DeserializeBuffer* deserializeBuffer,
DeserializeAllocator* allocator,
const ObjectIdResolver& resolver);
//* Output structure [de]serialization first because it is used by commands. //* Output structure [de]serialization first because it is used by commands.
{% for type in by_category["structure"] %} {% for type in by_category["structure"] %}
{% set name = as_cType(type.name) %} {% set name = as_cType(type.name) %}
@ -513,12 +522,19 @@ namespace dawn_wire {
{% endif %} {% endif %}
{% endfor %} {% endfor %}
size_t GetChainedStructExtraRequiredSize(const WGPUChainedStruct* chainedStruct) { {% macro make_chained_struct_serialization_helpers(out) %}
{% set ChainedStructPtr = "WGPUChainedStructOut*" if out else "const WGPUChainedStruct*" %}
{% set ChainedStruct = "WGPUChainedStructOut" if out else "WGPUChainedStruct" %}
size_t GetChainedStructExtraRequiredSize({{ChainedStructPtr}} chainedStruct) {
ASSERT(chainedStruct != nullptr); ASSERT(chainedStruct != nullptr);
size_t result = 0; size_t result = 0;
while (chainedStruct != nullptr) { while (chainedStruct != nullptr) {
switch (chainedStruct->sType) { switch (chainedStruct->sType) {
{% for sType in types["s type"].values if sType.valid and sType.name.CamelCase() not in client_side_structures %} {% for sType in types["s type"].values if (
sType.valid and
(sType.name.CamelCase() not in client_side_structures) and
(types[sType.name.get()].output == out)
) %}
case {{as_cEnum(types["s type"].name, sType.name)}}: { case {{as_cEnum(types["s type"].name, sType.name)}}: {
const auto& typedStruct = *reinterpret_cast<{{as_cType(sType.name)}} const *>(chainedStruct); const auto& typedStruct = *reinterpret_cast<{{as_cType(sType.name)}} const *>(chainedStruct);
result += sizeof({{as_cType(sType.name)}}Transfer); result += sizeof({{as_cType(sType.name)}}Transfer);
@ -527,6 +543,8 @@ namespace dawn_wire {
break; break;
} }
{% endfor %} {% endfor %}
// Explicitly list the Invalid enum. MSVC complains about no case labels.
case WGPUSType_Invalid:
default: default:
// Invalid enum. Reserve space just for the transfer header (sType and hasNext). // Invalid enum. Reserve space just for the transfer header (sType and hasNext).
result += sizeof(WGPUChainedStructTransfer); result += sizeof(WGPUChainedStructTransfer);
@ -537,14 +555,18 @@ namespace dawn_wire {
return result; return result;
} }
DAWN_NO_DISCARD WireResult SerializeChainedStruct(WGPUChainedStruct const* chainedStruct, DAWN_NO_DISCARD WireResult SerializeChainedStruct({{ChainedStructPtr}} chainedStruct,
SerializeBuffer* buffer, SerializeBuffer* buffer,
const ObjectIdProvider& provider) { const ObjectIdProvider& provider) {
ASSERT(chainedStruct != nullptr); ASSERT(chainedStruct != nullptr);
ASSERT(buffer != nullptr); ASSERT(buffer != nullptr);
do { do {
switch (chainedStruct->sType) { switch (chainedStruct->sType) {
{% for sType in types["s type"].values if sType.valid and sType.name.CamelCase() not in client_side_structures %} {% for sType in types["s type"].values if (
sType.valid and
(sType.name.CamelCase() not in client_side_structures) and
(types[sType.name.get()].output == out)
) %}
{% set CType = as_cType(sType.name) %} {% set CType = as_cType(sType.name) %}
case {{as_cEnum(types["s type"].name, sType.name)}}: { case {{as_cEnum(types["s type"].name, sType.name)}}: {
@ -562,6 +584,8 @@ namespace dawn_wire {
chainedStruct = chainedStruct->next; chainedStruct = chainedStruct->next;
} break; } break;
{% endfor %} {% endfor %}
// Explicitly list the Invalid enum. MSVC complains about no case labels.
case WGPUSType_Invalid:
default: { default: {
// Invalid enum. Serialize just the transfer header with Invalid as the sType. // Invalid enum. Serialize just the transfer header with Invalid as the sType.
// TODO(crbug.com/dawn/369): Unknown sTypes are silently discarded. // TODO(crbug.com/dawn/369): Unknown sTypes are silently discarded.
@ -583,7 +607,7 @@ namespace dawn_wire {
return WireResult::Success; return WireResult::Success;
} }
WireResult DeserializeChainedStruct(const WGPUChainedStruct** outChainNext, WireResult DeserializeChainedStruct({{ChainedStructPtr}}* outChainNext,
DeserializeBuffer* deserializeBuffer, DeserializeBuffer* deserializeBuffer,
DeserializeAllocator* allocator, DeserializeAllocator* allocator,
const ObjectIdResolver& resolver) { const ObjectIdResolver& resolver) {
@ -593,7 +617,11 @@ namespace dawn_wire {
WIRE_TRY(deserializeBuffer->Peek(&header)); WIRE_TRY(deserializeBuffer->Peek(&header));
WGPUSType sType = header->sType; WGPUSType sType = header->sType;
switch (sType) { switch (sType) {
{% for sType in types["s type"].values if sType.valid and sType.name.CamelCase() not in client_side_structures %} {% for sType in types["s type"].values if (
sType.valid and
(sType.name.CamelCase() not in client_side_structures) and
(types[sType.name.get()].output == out)
) %}
{% set CType = as_cType(sType.name) %} {% set CType = as_cType(sType.name) %}
case {{as_cEnum(types["s type"].name, sType.name)}}: { case {{as_cEnum(types["s type"].name, sType.name)}}: {
const volatile {{CType}}Transfer* transfer; const volatile {{CType}}Transfer* transfer;
@ -616,6 +644,8 @@ namespace dawn_wire {
hasNext = transfer->chain.hasNext; hasNext = transfer->chain.hasNext;
} break; } break;
{% endfor %} {% endfor %}
// Explicitly list the Invalid enum. MSVC complains about no case labels.
case WGPUSType_Invalid:
default: { default: {
// Invalid enum. Deserialize just the transfer header with Invalid as the sType. // Invalid enum. Deserialize just the transfer header with Invalid as the sType.
// TODO(crbug.com/dawn/369): Unknown sTypes are silently discarded. // TODO(crbug.com/dawn/369): Unknown sTypes are silently discarded.
@ -626,8 +656,8 @@ namespace dawn_wire {
const volatile WGPUChainedStructTransfer* transfer; const volatile WGPUChainedStructTransfer* transfer;
WIRE_TRY(deserializeBuffer->Read(&transfer)); WIRE_TRY(deserializeBuffer->Read(&transfer));
WGPUChainedStruct* outStruct; {{ChainedStruct}}* outStruct;
WIRE_TRY(GetSpace(allocator, sizeof(WGPUChainedStruct), &outStruct)); WIRE_TRY(GetSpace(allocator, sizeof({{ChainedStruct}}), &outStruct));
outStruct->sType = WGPUSType_Invalid; outStruct->sType = WGPUSType_Invalid;
outStruct->next = nullptr; outStruct->next = nullptr;
@ -642,6 +672,10 @@ namespace dawn_wire {
return WireResult::Success; return WireResult::Success;
} }
{% endmacro %}
{{ make_chained_struct_serialization_helpers(False) }}
{{ make_chained_struct_serialization_helpers(True) }}
//* Output [de]serialization helpers for commands //* Output [de]serialization helpers for commands
{% for command in cmd_records["command"] %} {% for command in cmd_records["command"] %}
@ -730,4 +764,38 @@ namespace dawn_wire {
nullptr, resolver) == WireResult::Success; nullptr, resolver) == WireResult::Success;
} }
size_t SerializedWGPUSupportedLimitsSize(const WGPUSupportedLimits* supportedLimits) {
return sizeof(WGPUSupportedLimits) +
WGPUSupportedLimitsGetExtraRequiredSize(*supportedLimits);
}
void SerializeWGPUSupportedLimits(
const WGPUSupportedLimits* supportedLimits,
char* buffer) {
SerializeBuffer serializeBuffer(buffer, SerializedWGPUSupportedLimitsSize(supportedLimits));
WGPUSupportedLimitsTransfer* transfer;
WireResult result = serializeBuffer.Next(&transfer);
ASSERT(result == WireResult::Success);
ErrorObjectIdProvider provider;
result = WGPUSupportedLimitsSerialize(*supportedLimits, transfer, &serializeBuffer, provider);
ASSERT(result == WireResult::Success);
}
bool DeserializeWGPUSupportedLimits(WGPUSupportedLimits* supportedLimits,
const volatile char* buffer,
size_t size) {
const volatile WGPUSupportedLimitsTransfer* transfer;
DeserializeBuffer deserializeBuffer(buffer, size);
if (deserializeBuffer.Read(&transfer) != WireResult::Success) {
return false;
}
ErrorObjectIdResolver resolver;
return WGPUSupportedLimitsDeserialize(supportedLimits, transfer, &deserializeBuffer,
nullptr, resolver) == WireResult::Success;
}
} // namespace dawn_wire } // namespace dawn_wire

View File

@ -106,13 +106,20 @@ typedef struct WGPUChainedStruct {
WGPUSType sType; WGPUSType sType;
} WGPUChainedStruct; } WGPUChainedStruct;
typedef struct WGPUChainedStructOut {
struct WGPUChainedStructOut * next;
WGPUSType sType;
} WGPUChainedStructOut;
{% for type in by_category["structure"] %} {% for type in by_category["structure"] %}
typedef struct {{as_cType(type.name)}} { typedef struct {{as_cType(type.name)}} {
{% set Out = "Out" if type.output else "" %}
{% set const = "const" if not type.output else "" %}
{% if type.extensible %} {% if type.extensible %}
WGPUChainedStruct const * nextInChain; WGPUChainedStruct{{Out}} {{const}} * nextInChain;
{% endif %} {% endif %}
{% if type.chained %} {% if type.chained %}
WGPUChainedStruct chain; WGPUChainedStruct{{Out}} chain;
{% endif %} {% endif %}
{% for member in type.members %} {% for member in type.members %}
{{as_annotated_cType(member)}}; {{as_annotated_cType(member)}};

View File

@ -206,9 +206,16 @@ namespace wgpu {
SType sType = SType::Invalid; SType sType = SType::Invalid;
}; };
struct ChainedStructOut {
ChainedStruct * nextInChain = nullptr;
SType sType = SType::Invalid;
};
{% for type in by_category["structure"] %} {% for type in by_category["structure"] %}
{% set Out = "Out" if type.output else "" %}
{% set const = "const" if not type.output else "" %}
{% if type.chained %} {% if type.chained %}
struct {{as_cppType(type.name)}} : ChainedStruct { struct {{as_cppType(type.name)}} : ChainedStruct{{Out}} {
{{as_cppType(type.name)}}() { {{as_cppType(type.name)}}() {
sType = SType::{{type.name.CamelCase()}}; sType = SType::{{type.name.CamelCase()}};
} }
@ -216,13 +223,13 @@ namespace wgpu {
struct {{as_cppType(type.name)}} { struct {{as_cppType(type.name)}} {
{% endif %} {% endif %}
{% if type.extensible %} {% if type.extensible %}
ChainedStruct const * nextInChain = nullptr; ChainedStruct{{Out}} {{const}} * nextInChain = nullptr;
{% endif %} {% endif %}
{% for member in type.members %} {% for member in type.members %}
{% set member_declaration = as_annotated_cppType(member) + render_cpp_default_value(member) %} {% set member_declaration = as_annotated_cppType(member) + render_cpp_default_value(member) %}
{% if type.chained and loop.first %} {% if type.chained and loop.first %}
//* Align the first member to ChainedStruct to match the C struct layout. //* Align the first member to ChainedStruct to match the C struct layout.
alignas(ChainedStruct) {{member_declaration}}; alignas(ChainedStruct{{Out}}) {{member_declaration}};
{% else %} {% else %}
{{member_declaration}}; {{member_declaration}};
{% endif %} {% endif %}

View File

@ -20,7 +20,6 @@ namespace dawn_native {
AdapterBase::AdapterBase(InstanceBase* instance, wgpu::BackendType backend) AdapterBase::AdapterBase(InstanceBase* instance, wgpu::BackendType backend)
: mInstance(instance), mBackend(backend) { : mInstance(instance), mBackend(backend) {
mLimits.v1.nextInChain = nullptr;
GetDefaultLimits(&mLimits.v1); GetDefaultLimits(&mLimits.v1);
mSupportedExtensions.EnableExtension(Extension::DawnInternalUsages); mSupportedExtensions.EnableExtension(Extension::DawnInternalUsages);
} }
@ -74,16 +73,16 @@ namespace dawn_native {
// to store them (ex. by calling GetLimits directly instead). Currently, // to store them (ex. by calling GetLimits directly instead). Currently,
// we keep this function as it's only used internally in Chromium to // we keep this function as it's only used internally in Chromium to
// send the adapter properties across the wire. // send the adapter properties across the wire.
GetLimits(reinterpret_cast<wgpu::Limits*>(&adapterProperties.limits)); GetLimits(reinterpret_cast<SupportedLimits*>(&adapterProperties.limits));
return adapterProperties; return adapterProperties;
} }
bool AdapterBase::GetLimits(wgpu::Limits* limits) const { bool AdapterBase::GetLimits(SupportedLimits* limits) const {
ASSERT(limits != nullptr); ASSERT(limits != nullptr);
if (limits->nextInChain != nullptr) { if (limits->nextInChain != nullptr) {
return false; return false;
} }
*limits = mLimits.v1; limits->limits = mLimits.v1;
return true; return true;
} }
@ -125,7 +124,8 @@ namespace dawn_native {
if (descriptor != nullptr && descriptor->requiredLimits != nullptr) { if (descriptor != nullptr && descriptor->requiredLimits != nullptr) {
DAWN_TRY(ValidateLimits( 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) { if (descriptor->requiredLimits->nextInChain != nullptr) {
return DAWN_VALIDATION_ERROR("Unsupported limit extension struct"); return DAWN_VALIDATION_ERROR("Unsupported limit extension struct");

View File

@ -52,7 +52,7 @@ namespace dawn_native {
const std::vector<const char*>& requestedExtensions) const; const std::vector<const char*>& requestedExtensions) const;
WGPUDeviceProperties GetAdapterProperties() const; WGPUDeviceProperties GetAdapterProperties() const;
bool GetLimits(wgpu::Limits* limits) const; bool GetLimits(SupportedLimits* limits) const;
virtual bool SupportsExternalImages() const = 0; virtual bool SupportsExternalImages() const = 0;

View File

@ -106,8 +106,8 @@ namespace dawn_native {
return mImpl->GetAdapterProperties(); return mImpl->GetAdapterProperties();
} }
bool Adapter::GetLimits(WGPULimits* limits) const { bool Adapter::GetLimits(WGPUSupportedLimits* limits) const {
return mImpl->GetLimits(reinterpret_cast<wgpu::Limits*>(limits)); return mImpl->GetLimits(reinterpret_cast<SupportedLimits*>(limits));
} }
bool Adapter::SupportsExternalImages() const { bool Adapter::SupportsExternalImages() const {

View File

@ -175,7 +175,7 @@ namespace dawn_native {
if (descriptor != nullptr && descriptor->requiredLimits != nullptr) { if (descriptor != nullptr && descriptor->requiredLimits != nullptr) {
mLimits.v1 = ReifyDefaultLimits( mLimits.v1 = ReifyDefaultLimits(
*reinterpret_cast<const wgpu::Limits*>(descriptor->requiredLimits)); reinterpret_cast<const RequiredLimits*>(descriptor->requiredLimits)->limits);
} else { } else {
GetDefaultLimits(&mLimits.v1); 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) { void DeviceBase::APIInjectError(wgpu::ErrorType type, const char* message) {
if (ConsumedError(ValidateErrorType(type))) { if (ConsumedError(ValidateErrorType(type))) {
return; return;

View File

@ -209,6 +209,7 @@ namespace dawn_native {
QueueBase* APIGetQueue(); QueueBase* APIGetQueue();
bool APIGetLimits(SupportedLimits* limits);
void APIInjectError(wgpu::ErrorType type, const char* message); void APIInjectError(wgpu::ErrorType type, const char* message);
bool APITick(); bool APITick();

View File

@ -94,15 +94,15 @@ namespace dawn_native {
} // namespace } // namespace
void GetDefaultLimits(wgpu::Limits* limits) { void GetDefaultLimits(Limits* limits) {
ASSERT(limits != nullptr); ASSERT(limits != nullptr);
#define X(Better, limitName, defaultValue) limits->limitName = defaultValue; #define X(Better, limitName, defaultValue) limits->limitName = defaultValue;
LIMITS(X) LIMITS(X)
#undef X #undef X
} }
wgpu::Limits ReifyDefaultLimits(const wgpu::Limits& limits) { Limits ReifyDefaultLimits(const Limits& limits) {
wgpu::Limits out; Limits out;
#define X(Better, limitName, defaultValue) \ #define X(Better, limitName, defaultValue) \
if (!IsLimitUndefined(limits.limitName)) { \ if (!IsLimitUndefined(limits.limitName)) { \
out.limitName = limits.limitName; \ out.limitName = limits.limitName; \
@ -114,8 +114,7 @@ namespace dawn_native {
return out; return out;
} }
MaybeError ValidateLimits(const wgpu::Limits& supportedLimits, MaybeError ValidateLimits(const Limits& supportedLimits, const Limits& requiredLimits) {
const wgpu::Limits& requiredLimits) {
#define X(Better, limitName, defaultValue) \ #define X(Better, limitName, defaultValue) \
if (!IsLimitUndefined(requiredLimits.limitName)) { \ if (!IsLimitUndefined(requiredLimits.limitName)) { \
DAWN_TRY(CheckLimit<LimitBetterDirection::Better>::Invoke(supportedLimits.limitName, \ DAWN_TRY(CheckLimit<LimitBetterDirection::Better>::Invoke(supportedLimits.limitName, \

View File

@ -21,19 +21,18 @@
namespace dawn_native { namespace dawn_native {
struct CombinedLimits { struct CombinedLimits {
wgpu::Limits v1; Limits v1;
}; };
// Populate |limits| with the default limits. // 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 // Returns a copy of |limits| where all undefined values are replaced
// with their defaults. // with their defaults.
wgpu::Limits ReifyDefaultLimits(const wgpu::Limits& limits); Limits ReifyDefaultLimits(const Limits& limits);
// Validate that |requiredLimits| are no better than |supportedLimits|. // Validate that |requiredLimits| are no better than |supportedLimits|.
MaybeError ValidateLimits(const wgpu::Limits& supportedLimits, MaybeError ValidateLimits(const Limits& supportedLimits, const Limits& requiredLimits);
const wgpu::Limits& requiredLimits);
} // namespace dawn_native } // namespace dawn_native

View File

@ -196,6 +196,12 @@ namespace dawn_wire { namespace client {
return Buffer::CreateError(this); return Buffer::CreateError(this);
} }
bool Device::GetLimits(WGPUSupportedLimits* limits) {
// Not implemented in the wire.
UNREACHABLE();
return false;
}
WGPUQueue Device::GetQueue() { WGPUQueue Device::GetQueue() {
// The queue is lazily created because if a Device is created by // The queue is lazily created because if a Device is created by
// Reserve/Inject, we cannot send the GetQueue message until // Reserve/Inject, we cannot send the GetQueue message until

View File

@ -64,6 +64,7 @@ namespace dawn_wire { namespace client {
WGPUCreatePipelineAsyncStatus status, WGPUCreatePipelineAsyncStatus status,
const char* message); const char* message);
bool GetLimits(WGPUSupportedLimits* limits);
WGPUQueue GetQueue(); WGPUQueue GetQueue();
void CancelCallbacksForDisconnect() override; void CancelCallbacksForDisconnect() override;

View File

@ -67,7 +67,7 @@ namespace dawn_native {
std::vector<const char*> forceEnabledToggles; std::vector<const char*> forceEnabledToggles;
std::vector<const char*> forceDisabledToggles; 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 // 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; std::vector<const char*> GetSupportedExtensions() const;
WGPUDeviceProperties GetAdapterProperties() 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 // Check that the Adapter is able to support importing external images. This is necessary
// to implement the swapchain and interop APIs in Chromium. // to implement the swapchain and interop APIs in Chromium.

View File

@ -61,6 +61,16 @@ namespace dawn_wire {
const volatile char* deserializeBuffer, const volatile char* deserializeBuffer,
size_t deserializeBufferSize); 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 } // namespace dawn_wire
#endif // DAWNWIRE_WIRE_H_ #endif // DAWNWIRE_WIRE_H_

View File

@ -29,6 +29,10 @@ class RequestDeviceValidationTest : public ValidationTest {
EXPECT_EQ(status, WGPURequestDeviceStatus_Success); EXPECT_EQ(status, WGPURequestDeviceStatus_Success);
EXPECT_NE(device, nullptr); EXPECT_NE(device, nullptr);
EXPECT_STREQ(message, 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, static void ExpectRequestDeviceError(WGPURequestDeviceStatus status,
@ -40,73 +44,136 @@ class RequestDeviceValidationTest : public ValidationTest {
EXPECT_EQ(device, nullptr); EXPECT_EQ(device, nullptr);
EXPECT_STRNE(message, 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 that requesting a device without specifying limits is valid.
TEST_F(RequestDeviceValidationTest, NoRequiredLimits) { TEST_F(RequestDeviceValidationTest, NoRequiredLimits) {
dawn_native::DeviceDescriptor descriptor; 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 that requesting a device with the default limits is valid.
TEST_F(RequestDeviceValidationTest, DefaultLimits) { TEST_F(RequestDeviceValidationTest, DefaultLimits) {
wgpu::Limits limits = {}; wgpu::RequiredLimits limits = {};
dawn_native::DeviceDescriptor descriptor; dawn_native::DeviceDescriptor descriptor;
descriptor.requiredLimits = reinterpret_cast<const WGPULimits*>(&limits); descriptor.requiredLimits = reinterpret_cast<const WGPURequiredLimits*>(&limits);
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.maxTextureArrayLayers, 256u);
}));
} }
// Test that requesting a device where a required limit is above the maximum value. // Test that requesting a device where a required limit is above the maximum value.
TEST_F(RequestDeviceValidationTest, HigherIsBetter) { TEST_F(RequestDeviceValidationTest, HigherIsBetter) {
wgpu::Limits limits = {}; wgpu::RequiredLimits limits = {};
dawn_native::DeviceDescriptor descriptor; dawn_native::DeviceDescriptor descriptor;
descriptor.requiredLimits = reinterpret_cast<const WGPULimits*>(&limits); descriptor.requiredLimits = reinterpret_cast<const WGPURequiredLimits*>(&limits);
wgpu::Limits supportedLimits; wgpu::SupportedLimits supportedLimits;
EXPECT_TRUE(adapter.GetLimits(reinterpret_cast<WGPULimits*>(&supportedLimits))); EXPECT_TRUE(adapter.GetLimits(reinterpret_cast<WGPUSupportedLimits*>(&supportedLimits)));
// Test below the max. // Test below the max.
limits.maxBindGroups = supportedLimits.maxBindGroups - 1; limits.limits.maxBindGroups = supportedLimits.limits.maxBindGroups - 1;
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess, nullptr); 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. // Test the max.
limits.maxBindGroups = supportedLimits.maxBindGroups; limits.limits.maxBindGroups = supportedLimits.limits.maxBindGroups;
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess, nullptr); 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. // Test above the max.
limits.maxBindGroups = supportedLimits.maxBindGroups + 1; limits.limits.maxBindGroups = supportedLimits.limits.maxBindGroups + 1;
adapter.RequestDevice(&descriptor, ExpectRequestDeviceError, nullptr); adapter.RequestDevice(&descriptor, ExpectRequestDeviceError, nullptr);
} }
// Test that requesting a device where a required limit is below the minimum value. // Test that requesting a device where a required limit is below the minimum value.
TEST_F(RequestDeviceValidationTest, LowerIsBetter) { TEST_F(RequestDeviceValidationTest, LowerIsBetter) {
wgpu::Limits limits = {}; wgpu::RequiredLimits limits = {};
dawn_native::DeviceDescriptor descriptor; dawn_native::DeviceDescriptor descriptor;
descriptor.requiredLimits = reinterpret_cast<const WGPULimits*>(&limits); descriptor.requiredLimits = reinterpret_cast<const WGPURequiredLimits*>(&limits);
wgpu::Limits supportedLimits; wgpu::SupportedLimits supportedLimits;
EXPECT_TRUE(adapter.GetLimits(reinterpret_cast<WGPULimits*>(&supportedLimits))); EXPECT_TRUE(adapter.GetLimits(reinterpret_cast<WGPUSupportedLimits*>(&supportedLimits)));
// Test below the min. // Test below the min.
limits.minUniformBufferOffsetAlignment = supportedLimits.minUniformBufferOffsetAlignment / 2; limits.limits.minUniformBufferOffsetAlignment =
supportedLimits.limits.minUniformBufferOffsetAlignment / 2;
adapter.RequestDevice(&descriptor, ExpectRequestDeviceError, nullptr); adapter.RequestDevice(&descriptor, ExpectRequestDeviceError, nullptr);
// Test the min. // Test the min.
limits.minUniformBufferOffsetAlignment = supportedLimits.minUniformBufferOffsetAlignment; limits.limits.minUniformBufferOffsetAlignment =
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess, nullptr); 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. // Test above the min.
limits.minUniformBufferOffsetAlignment = supportedLimits.minUniformBufferOffsetAlignment * 2; limits.limits.minUniformBufferOffsetAlignment =
adapter.RequestDevice(&descriptor, ExpectRequestDeviceSuccess, nullptr); 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 that it is an error to request limits with an invalid chained struct
TEST_F(RequestDeviceValidationTest, InvalidChainedStruct) { TEST_F(RequestDeviceValidationTest, InvalidChainedStruct) {
wgpu::PrimitiveDepthClampingState depthClamp = {}; wgpu::PrimitiveDepthClampingState depthClamp = {};
wgpu::Limits limits = {}; wgpu::RequiredLimits limits = {};
limits.nextInChain = &depthClamp; limits.nextInChain = &depthClamp;
dawn_native::DeviceDescriptor descriptor; dawn_native::DeviceDescriptor descriptor;
descriptor.requiredLimits = reinterpret_cast<const WGPULimits*>(&limits); descriptor.requiredLimits = reinterpret_cast<const WGPURequiredLimits*>(&limits);
adapter.RequestDevice(&descriptor, ExpectRequestDeviceError, nullptr); adapter.RequestDevice(&descriptor, ExpectRequestDeviceError, nullptr);
} }