mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-06 22:53:35 +00:00
webgpu.h introduce a base struct for extension structures.
struct WGPUChainedStruct { WGPUChainedStruct const * nextInChain; WGPUSType sType; }; And changes all the nextInChain to point to such structures. This adds more type safety to extension structs and requires less casting to check sTypes and friends. Bug: dawn:269 Change-Id: I443f363cdb55dbec7c7f6e897245d4a7ea0ebe70 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15080 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
parent
7f078e7ebe
commit
2b24c3d92d
@ -1298,6 +1298,12 @@
|
|||||||
{"name": "implementation", "type": "uint64_t"}
|
{"name": "implementation", "type": "uint64_t"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"s type": {
|
||||||
|
"category": "enum",
|
||||||
|
"values": [
|
||||||
|
{"value": 0, "name": "invalid"}
|
||||||
|
]
|
||||||
|
},
|
||||||
"texture": {
|
"texture": {
|
||||||
"category": "object",
|
"category": "object",
|
||||||
"methods": [
|
"methods": [
|
||||||
|
@ -140,7 +140,11 @@ class StructureType(Record, Type):
|
|||||||
def __init__(self, name, json_data):
|
def __init__(self, name, json_data):
|
||||||
Record.__init__(self, name)
|
Record.__init__(self, name)
|
||||||
Type.__init__(self, name, json_data)
|
Type.__init__(self, name, json_data)
|
||||||
|
self.chained = json_data.get("chained", False)
|
||||||
self.extensible = json_data.get("extensible", False)
|
self.extensible = json_data.get("extensible", False)
|
||||||
|
# Chained structs inherit from wgpu::ChainedStruct which has nextInChain so setting
|
||||||
|
# both extensible and chained would result in two nextInChain members.
|
||||||
|
assert(not (self.extensible and self.chained))
|
||||||
|
|
||||||
class Command(Record):
|
class Command(Record):
|
||||||
def __init__(self, name, members=None):
|
def __init__(self, name, members=None):
|
||||||
|
@ -16,6 +16,15 @@
|
|||||||
|
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
|
|
||||||
|
static_assert(sizeof(ChainedStruct) == sizeof(WGPUChainedStruct),
|
||||||
|
"sizeof mismatch for ChainedStruct");
|
||||||
|
static_assert(alignof(ChainedStruct) == alignof(WGPUChainedStruct),
|
||||||
|
"alignof mismatch for ChainedStruct");
|
||||||
|
static_assert(offsetof(ChainedStruct, nextInChain) == offsetof(WGPUChainedStruct, nextInChain),
|
||||||
|
"offsetof mismatch for ChainedStruct::nextInChain");
|
||||||
|
static_assert(offsetof(ChainedStruct, sType) == offsetof(WGPUChainedStruct, sType),
|
||||||
|
"offsetof mismatch for ChainedStruct::sType");
|
||||||
|
|
||||||
{% for type in by_category["structure"] %}
|
{% for type in by_category["structure"] %}
|
||||||
{% set CppType = as_cppType(type.name) %}
|
{% set CppType = as_cppType(type.name) %}
|
||||||
{% set CType = as_cType(type.name) %}
|
{% set CType = as_cType(type.name) %}
|
||||||
|
@ -32,13 +32,25 @@ namespace dawn_native {
|
|||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
|
||||||
|
struct ChainedStruct {
|
||||||
|
ChainedStruct const * nextInChain = nullptr;
|
||||||
|
wgpu::SType sType = wgpu::SType::Invalid;
|
||||||
|
};
|
||||||
|
|
||||||
{% for type in by_category["structure"] %}
|
{% for type in by_category["structure"] %}
|
||||||
struct {{as_cppType(type.name)}} {
|
{% if type.chained %}
|
||||||
|
struct {{as_cppType(type.name)}} : ChainedStruct {
|
||||||
|
{{as_cppType(type.name)}}() {
|
||||||
|
sType = wgpu::SType::{{type.name.CamelCase()}};
|
||||||
|
}
|
||||||
|
{% else %}
|
||||||
|
struct {{as_cppType(type.name)}} {
|
||||||
|
{% endif %}
|
||||||
{% if type.extensible %}
|
{% if type.extensible %}
|
||||||
const void* nextInChain = nullptr;
|
ChainedStruct const * nextInChain = nullptr;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for member in type.members %}
|
{% for member in type.members %}
|
||||||
{{as_annotated_frontendType(member)}} {{render_cpp_default_value(member)}};
|
{{as_annotated_frontendType(member)}} {{render_cpp_default_value(member)}};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,10 +73,19 @@ typedef uint32_t WGPUFlags;
|
|||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
typedef struct WGPUChainedStruct {
|
||||||
|
struct WGPUChainedStruct const * nextInChain;
|
||||||
|
WGPUSType sType;
|
||||||
|
} WGPUChainedStruct;
|
||||||
|
|
||||||
{% for type in by_category["structure"] %}
|
{% for type in by_category["structure"] %}
|
||||||
typedef struct {{as_cType(type.name)}} {
|
typedef struct {{as_cType(type.name)}} {
|
||||||
{% if type.extensible %}
|
{% if type.extensible %}
|
||||||
void const * nextInChain;
|
WGPUChainedStruct const * nextInChain;
|
||||||
|
{% endif %}
|
||||||
|
{% if type.chained %}
|
||||||
|
WGPUChainedStruct const * nextInChain;
|
||||||
|
WGPUSType sType;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for member in type.members %}
|
{% for member in type.members %}
|
||||||
{{as_annotated_cType(member)}};
|
{{as_annotated_cType(member)}};
|
||||||
|
@ -42,6 +42,15 @@ namespace wgpu {
|
|||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
static_assert(sizeof(ChainedStruct) == sizeof(WGPUChainedStruct),
|
||||||
|
"sizeof mismatch for ChainedStruct");
|
||||||
|
static_assert(alignof(ChainedStruct) == alignof(WGPUChainedStruct),
|
||||||
|
"alignof mismatch for ChainedStruct");
|
||||||
|
static_assert(offsetof(ChainedStruct, nextInChain) == offsetof(WGPUChainedStruct, nextInChain),
|
||||||
|
"offsetof mismatch for ChainedStruct::nextInChain");
|
||||||
|
static_assert(offsetof(ChainedStruct, sType) == offsetof(WGPUChainedStruct, sType),
|
||||||
|
"offsetof mismatch for ChainedStruct::sType");
|
||||||
|
|
||||||
{% for type in by_category["structure"] %}
|
{% for type in by_category["structure"] %}
|
||||||
{% set CppType = as_cppType(type.name) %}
|
{% set CppType = as_cppType(type.name) %}
|
||||||
{% set CType = as_cType(type.name) %}
|
{% set CType = as_cType(type.name) %}
|
||||||
|
@ -186,10 +186,22 @@ namespace wgpu {
|
|||||||
Instance CreateInstance(InstanceDescriptor const * descriptor = nullptr);
|
Instance CreateInstance(InstanceDescriptor const * descriptor = nullptr);
|
||||||
Proc GetProcAddress(Device const& device, const char* procName);
|
Proc GetProcAddress(Device const& device, const char* procName);
|
||||||
|
|
||||||
|
struct ChainedStruct {
|
||||||
|
ChainedStruct const * nextInChain = nullptr;
|
||||||
|
SType sType = SType::Invalid;
|
||||||
|
};
|
||||||
|
|
||||||
{% for type in by_category["structure"] %}
|
{% for type in by_category["structure"] %}
|
||||||
struct {{as_cppType(type.name)}} {
|
{% if type.chained %}
|
||||||
|
struct {{as_cppType(type.name)}} : ChainedStruct {
|
||||||
|
{{as_cppType(type.name)}}() {
|
||||||
|
sType = SType::{{type.name.CamelCase()}};
|
||||||
|
}
|
||||||
|
{% else %}
|
||||||
|
struct {{as_cppType(type.name)}} {
|
||||||
|
{% endif %}
|
||||||
{% if type.extensible %}
|
{% if type.extensible %}
|
||||||
const void* nextInChain = nullptr;
|
ChainedStruct const * nextInChain = nullptr;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for member in type.members %}
|
{% for member in type.members %}
|
||||||
{{as_annotated_cppType(member)}}{{render_cpp_default_value(member)}};
|
{{as_annotated_cppType(member)}}{{render_cpp_default_value(member)}};
|
||||||
|
@ -144,7 +144,9 @@ TEST_P(D3D12SharedHandleValidation, Success) {
|
|||||||
// Test an error occurs if the texture descriptor is invalid
|
// Test an error occurs if the texture descriptor is invalid
|
||||||
TEST_P(D3D12SharedHandleValidation, InvalidTextureDescriptor) {
|
TEST_P(D3D12SharedHandleValidation, InvalidTextureDescriptor) {
|
||||||
DAWN_SKIP_TEST_IF(UsesWire());
|
DAWN_SKIP_TEST_IF(UsesWire());
|
||||||
dawnDescriptor.nextInChain = this;
|
|
||||||
|
wgpu::ChainedStruct chainedDescriptor;
|
||||||
|
dawnDescriptor.nextInChain = &chainedDescriptor;
|
||||||
|
|
||||||
wgpu::Texture texture;
|
wgpu::Texture texture;
|
||||||
ComPtr<ID3D11Texture2D> d3d11Texture;
|
ComPtr<ID3D11Texture2D> d3d11Texture;
|
||||||
|
@ -136,7 +136,9 @@ TEST_P(IOSurfaceValidationTests, Success) {
|
|||||||
// Test an error occurs if the texture descriptor is invalid
|
// Test an error occurs if the texture descriptor is invalid
|
||||||
TEST_P(IOSurfaceValidationTests, InvalidTextureDescriptor) {
|
TEST_P(IOSurfaceValidationTests, InvalidTextureDescriptor) {
|
||||||
DAWN_SKIP_TEST_IF(UsesWire());
|
DAWN_SKIP_TEST_IF(UsesWire());
|
||||||
descriptor.nextInChain = this;
|
|
||||||
|
wgpu::ChainedStruct chainedDescriptor;
|
||||||
|
descriptor.nextInChain = &chainedDescriptor;
|
||||||
|
|
||||||
ASSERT_DEVICE_ERROR(wgpu::Texture texture =
|
ASSERT_DEVICE_ERROR(wgpu::Texture texture =
|
||||||
WrapIOSurface(&descriptor, defaultIOSurface.get(), 0));
|
WrapIOSurface(&descriptor, defaultIOSurface.get(), 0));
|
||||||
|
@ -75,7 +75,8 @@ TEST_F(BindGroupValidationTest, NextInChainNullptr) {
|
|||||||
device.CreateBindGroup(&descriptor);
|
device.CreateBindGroup(&descriptor);
|
||||||
|
|
||||||
// Check that nextInChain != nullptr is an error.
|
// Check that nextInChain != nullptr is an error.
|
||||||
descriptor.nextInChain = static_cast<void*>(&descriptor);
|
wgpu::ChainedStruct chainedDescriptor;
|
||||||
|
descriptor.nextInChain = &chainedDescriptor;
|
||||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +256,8 @@ TEST_P(VulkanImageWrappingValidationTests, MissingTextureDescriptor) {
|
|||||||
// Test an error occurs if the texture descriptor is invalid
|
// Test an error occurs if the texture descriptor is invalid
|
||||||
TEST_P(VulkanImageWrappingValidationTests, InvalidTextureDescriptor) {
|
TEST_P(VulkanImageWrappingValidationTests, InvalidTextureDescriptor) {
|
||||||
DAWN_SKIP_TEST_IF(UsesWire());
|
DAWN_SKIP_TEST_IF(UsesWire());
|
||||||
defaultDescriptor.nextInChain = this;
|
wgpu::ChainedStruct chainedDescriptor;
|
||||||
|
defaultDescriptor.nextInChain = &chainedDescriptor;
|
||||||
|
|
||||||
ASSERT_DEVICE_ERROR(wgpu::Texture texture = WrapVulkanImage(
|
ASSERT_DEVICE_ERROR(wgpu::Texture texture = WrapVulkanImage(
|
||||||
device, &defaultDescriptor, defaultFd, defaultAllocationSize,
|
device, &defaultDescriptor, defaultFd, defaultAllocationSize,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user