Remove dummy extension types

Now that we have a real extension type (PrimitiveDepthClampingState),
we can replace the dummy extensions used in the WireExtensionTests
with the real deal.

Change-Id: I43dfa66f2cc909b5fc95b55382d3cb53ce022a0f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/47300
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Brian Ho <hob@chromium.org>
This commit is contained in:
Brian Ho 2021-04-09 18:41:19 +00:00 committed by Commit Bot service account
parent 9b606f7a25
commit 8a2c179239
2 changed files with 200 additions and 242 deletions

View File

@ -1739,13 +1739,6 @@
]
},
"render pipeline descriptor dummy extension": {
"category": "structure",
"chained": true,
"members": [
{"name": "dummy stage", "type": "programmable stage descriptor"}
]
},
"sampler": {
"category": "object"
},
@ -1766,13 +1759,6 @@
{"name": "max anisotropy", "type": "uint16_t", "default": "1"}
]
},
"sampler descriptor dummy anisotropic filtering": {
"category": "structure",
"chained": true,
"members": [
{"name": "max anisotropy", "type": "float"}
]
},
"shader module": {
"category": "object",
"methods": [
@ -1926,9 +1912,7 @@
{"value": 4, "name": "surface descriptor from canvas HTML selector"},
{"value": 5, "name": "shader module SPIRV descriptor"},
{"value": 6, "name": "shader module WGSL descriptor"},
{"value": 7, "name": "sampler descriptor dummy anisotropic filtering"},
{"value": 8, "name": "render pipeline descriptor dummy extension"},
{"value": 9, "name": "primitive depth clamping state"}
{"value": 7, "name": "primitive depth clamping state"}
]
},
"texture": {

View File

@ -26,239 +26,213 @@ class WireExtensionTests : public WireTest {
// Serialize/Deserializes a chained struct correctly.
TEST_F(WireExtensionTests, ChainedStruct) {
WGPUSamplerDescriptorDummyAnisotropicFiltering clientExt = {};
clientExt.chain.sType = WGPUSType_SamplerDescriptorDummyAnisotropicFiltering;
clientExt.chain.next = nullptr;
clientExt.maxAnisotropy = 3.14;
WGPUSamplerDescriptor clientDesc = {};
clientDesc.nextInChain = &clientExt.chain;
clientDesc.label = "sampler with anisotropic filtering";
wgpuDeviceCreateSampler(device, &clientDesc);
EXPECT_CALL(api, DeviceCreateSampler(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused, const WGPUSamplerDescriptor* serverDesc) -> WGPUSampler {
EXPECT_STREQ(serverDesc->label, clientDesc.label);
const auto* ext =
reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
serverDesc->nextInChain);
EXPECT_EQ(ext->chain.sType, clientExt.chain.sType);
EXPECT_EQ(ext->maxAnisotropy, clientExt.maxAnisotropy);
EXPECT_EQ(ext->chain.next, nullptr);
return api.GetNewSampler();
}));
FlushClient();
}
// Serialize/Deserializes multiple chained structs correctly.
TEST_F(WireExtensionTests, MutlipleChainedStructs) {
WGPUSamplerDescriptorDummyAnisotropicFiltering clientExt2 = {};
clientExt2.chain.sType = WGPUSType_SamplerDescriptorDummyAnisotropicFiltering;
clientExt2.chain.next = nullptr;
clientExt2.maxAnisotropy = 2.71828;
WGPUSamplerDescriptorDummyAnisotropicFiltering clientExt1 = {};
clientExt1.chain.sType = WGPUSType_SamplerDescriptorDummyAnisotropicFiltering;
clientExt1.chain.next = &clientExt2.chain;
clientExt1.maxAnisotropy = 3.14;
WGPUSamplerDescriptor clientDesc = {};
clientDesc.nextInChain = &clientExt1.chain;
clientDesc.label = "sampler with anisotropic filtering";
wgpuDeviceCreateSampler(device, &clientDesc);
EXPECT_CALL(api, DeviceCreateSampler(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused, const WGPUSamplerDescriptor* serverDesc) -> WGPUSampler {
EXPECT_STREQ(serverDesc->label, clientDesc.label);
const auto* ext1 =
reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
serverDesc->nextInChain);
EXPECT_EQ(ext1->chain.sType, clientExt1.chain.sType);
EXPECT_EQ(ext1->maxAnisotropy, clientExt1.maxAnisotropy);
const auto* ext2 =
reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
ext1->chain.next);
EXPECT_EQ(ext2->chain.sType, clientExt2.chain.sType);
EXPECT_EQ(ext2->maxAnisotropy, clientExt2.maxAnisotropy);
EXPECT_EQ(ext2->chain.next, nullptr);
return api.GetNewSampler();
}));
FlushClient();
// Swap the order of the chained structs.
clientDesc.nextInChain = &clientExt2.chain;
clientExt2.chain.next = &clientExt1.chain;
clientExt1.chain.next = nullptr;
wgpuDeviceCreateSampler(device, &clientDesc);
EXPECT_CALL(api, DeviceCreateSampler(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused, const WGPUSamplerDescriptor* serverDesc) -> WGPUSampler {
EXPECT_STREQ(serverDesc->label, clientDesc.label);
const auto* ext2 =
reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
serverDesc->nextInChain);
EXPECT_EQ(ext2->chain.sType, clientExt2.chain.sType);
EXPECT_EQ(ext2->maxAnisotropy, clientExt2.maxAnisotropy);
const auto* ext1 =
reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
ext2->chain.next);
EXPECT_EQ(ext1->chain.sType, clientExt1.chain.sType);
EXPECT_EQ(ext1->maxAnisotropy, clientExt1.maxAnisotropy);
EXPECT_EQ(ext1->chain.next, nullptr);
return api.GetNewSampler();
}));
FlushClient();
}
// Test that a chained struct with Invalid sType passes through as Invalid.
TEST_F(WireExtensionTests, InvalidSType) {
WGPUSamplerDescriptorDummyAnisotropicFiltering clientExt = {};
clientExt.chain.sType = WGPUSType_Invalid;
clientExt.chain.next = nullptr;
WGPUSamplerDescriptor clientDesc = {};
clientDesc.nextInChain = &clientExt.chain;
clientDesc.label = "sampler with anisotropic filtering";
wgpuDeviceCreateSampler(device, &clientDesc);
EXPECT_CALL(api, DeviceCreateSampler(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused, const WGPUSamplerDescriptor* desc) -> WGPUSampler {
EXPECT_EQ(desc->nextInChain->sType, WGPUSType_Invalid);
EXPECT_EQ(desc->nextInChain->next, nullptr);
return api.GetNewSampler();
}));
FlushClient();
}
// Test that a chained struct with unknown sType passes through as Invalid.
TEST_F(WireExtensionTests, UnknownSType) {
WGPUSamplerDescriptorDummyAnisotropicFiltering clientExt = {};
clientExt.chain.sType = static_cast<WGPUSType>(-1);
clientExt.chain.next = nullptr;
WGPUSamplerDescriptor clientDesc = {};
clientDesc.nextInChain = &clientExt.chain;
clientDesc.label = "sampler with anisotropic filtering";
wgpuDeviceCreateSampler(device, &clientDesc);
EXPECT_CALL(api, DeviceCreateSampler(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused, const WGPUSamplerDescriptor* desc) -> WGPUSampler {
EXPECT_EQ(desc->nextInChain->sType, WGPUSType_Invalid);
EXPECT_EQ(desc->nextInChain->next, nullptr);
return api.GetNewSampler();
}));
FlushClient();
}
// Test that if both an invalid and valid stype are passed on the chain, it is an error.
TEST_F(WireExtensionTests, ValidAndInvalidSTypeInChain) {
WGPUSamplerDescriptorDummyAnisotropicFiltering clientExt2 = {};
clientExt2.chain.sType = WGPUSType_Invalid;
clientExt2.chain.next = nullptr;
clientExt2.maxAnisotropy = 2.71828;
WGPUSamplerDescriptorDummyAnisotropicFiltering clientExt1 = {};
clientExt1.chain.sType = WGPUSType_SamplerDescriptorDummyAnisotropicFiltering;
clientExt1.chain.next = &clientExt2.chain;
clientExt1.maxAnisotropy = 3.14;
WGPUSamplerDescriptor clientDesc = {};
clientDesc.nextInChain = &clientExt1.chain;
clientDesc.label = "sampler with anisotropic filtering";
wgpuDeviceCreateSampler(device, &clientDesc);
EXPECT_CALL(api, DeviceCreateSampler(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused, const WGPUSamplerDescriptor* desc) -> WGPUSampler {
const auto* ext =
reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
desc->nextInChain);
EXPECT_EQ(ext->chain.sType, WGPUSType_SamplerDescriptorDummyAnisotropicFiltering);
EXPECT_EQ(ext->maxAnisotropy, clientExt1.maxAnisotropy);
EXPECT_EQ(ext->chain.next->sType, WGPUSType_Invalid);
EXPECT_EQ(ext->chain.next->next, nullptr);
return api.GetNewSampler();
}));
FlushClient();
// Swap the order of the chained structs.
clientDesc.nextInChain = &clientExt2.chain;
clientExt2.chain.next = &clientExt1.chain;
clientExt1.chain.next = nullptr;
wgpuDeviceCreateSampler(device, &clientDesc);
EXPECT_CALL(api, DeviceCreateSampler(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused, const WGPUSamplerDescriptor* desc) -> WGPUSampler {
EXPECT_EQ(desc->nextInChain->sType, WGPUSType_Invalid);
const auto* ext =
reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
desc->nextInChain->next);
EXPECT_EQ(ext->chain.sType, WGPUSType_SamplerDescriptorDummyAnisotropicFiltering);
EXPECT_EQ(ext->maxAnisotropy, clientExt1.maxAnisotropy);
EXPECT_EQ(ext->chain.next, nullptr);
return api.GetNewSampler();
}));
FlushClient();
}
// Test that (de)?serializing a chained struct with subdescriptors works.
TEST_F(WireExtensionTests, ChainedStructWithSubdescriptor) {
WGPUShaderModuleDescriptor shaderModuleDesc = {};
WGPUShaderModule apiShaderModule1 = api.GetNewShaderModule();
WGPUShaderModule shaderModule1 = wgpuDeviceCreateShaderModule(device, &shaderModuleDesc);
EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiShaderModule1));
WGPUShaderModule apiShaderModule = api.GetNewShaderModule();
WGPUShaderModule shaderModule = wgpuDeviceCreateShaderModule(device, &shaderModuleDesc);
EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiShaderModule));
FlushClient();
WGPUShaderModule apiShaderModule2 = api.GetNewShaderModule();
WGPUShaderModule shaderModule2 = wgpuDeviceCreateShaderModule(device, &shaderModuleDesc);
EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiShaderModule2));
FlushClient();
WGPUProgrammableStageDescriptor extraStageDesc = {};
extraStageDesc.module = shaderModule1;
extraStageDesc.entryPoint = "my other module";
WGPURenderPipelineDescriptorDummyExtension clientExt = {};
clientExt.chain.sType = WGPUSType_RenderPipelineDescriptorDummyExtension;
WGPUPrimitiveDepthClampingState clientExt = {};
clientExt.chain.sType = WGPUSType_PrimitiveDepthClampingState;
clientExt.chain.next = nullptr;
clientExt.dummyStage = extraStageDesc;
clientExt.clampDepth = true;
WGPURenderPipelineDescriptor renderPipelineDesc = {};
renderPipelineDesc.nextInChain = &clientExt.chain;
renderPipelineDesc.vertexStage.module = shaderModule2;
renderPipelineDesc.vertexStage.entryPoint = "my vertex module";
WGPURenderPipelineDescriptor2 renderPipelineDesc = {};
renderPipelineDesc.vertex.module = shaderModule;
renderPipelineDesc.vertex.entryPoint = "main";
renderPipelineDesc.primitive.nextInChain = &clientExt.chain;
wgpuDeviceCreateRenderPipeline(device, &renderPipelineDesc);
EXPECT_CALL(api, DeviceCreateRenderPipeline(apiDevice, NotNull()))
wgpuDeviceCreateRenderPipeline2(device, &renderPipelineDesc);
EXPECT_CALL(api, DeviceCreateRenderPipeline2(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused,
const WGPURenderPipelineDescriptor* serverDesc) -> WGPURenderPipeline {
EXPECT_EQ(serverDesc->vertexStage.module, apiShaderModule2);
EXPECT_STREQ(serverDesc->vertexStage.entryPoint,
renderPipelineDesc.vertexStage.entryPoint);
const auto* ext = reinterpret_cast<const WGPURenderPipelineDescriptorDummyExtension*>(
serverDesc->nextInChain);
const WGPURenderPipelineDescriptor2* serverDesc) -> WGPURenderPipeline {
const auto* ext = reinterpret_cast<const WGPUPrimitiveDepthClampingState*>(
serverDesc->primitive.nextInChain);
EXPECT_EQ(ext->chain.sType, clientExt.chain.sType);
EXPECT_EQ(ext->dummyStage.module, apiShaderModule1);
EXPECT_STREQ(ext->dummyStage.entryPoint, extraStageDesc.entryPoint);
EXPECT_EQ(ext->clampDepth, true);
EXPECT_EQ(ext->chain.next, nullptr);
return api.GetNewRenderPipeline();
}));
FlushClient();
}
// Serialize/Deserializes multiple chained structs correctly.
TEST_F(WireExtensionTests, MutlipleChainedStructs) {
WGPUShaderModuleDescriptor shaderModuleDesc = {};
WGPUShaderModule apiShaderModule = api.GetNewShaderModule();
WGPUShaderModule shaderModule = wgpuDeviceCreateShaderModule(device, &shaderModuleDesc);
EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiShaderModule));
FlushClient();
WGPUPrimitiveDepthClampingState clientExt2 = {};
clientExt2.chain.sType = WGPUSType_PrimitiveDepthClampingState;
clientExt2.chain.next = nullptr;
clientExt2.clampDepth = false;
WGPUPrimitiveDepthClampingState clientExt1 = {};
clientExt1.chain.sType = WGPUSType_PrimitiveDepthClampingState;
clientExt1.chain.next = &clientExt2.chain;
clientExt1.clampDepth = true;
WGPURenderPipelineDescriptor2 renderPipelineDesc = {};
renderPipelineDesc.vertex.module = shaderModule;
renderPipelineDesc.vertex.entryPoint = "main";
renderPipelineDesc.primitive.nextInChain = &clientExt1.chain;
wgpuDeviceCreateRenderPipeline2(device, &renderPipelineDesc);
EXPECT_CALL(api, DeviceCreateRenderPipeline2(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused,
const WGPURenderPipelineDescriptor2* serverDesc) -> WGPURenderPipeline {
const auto* ext1 = reinterpret_cast<const WGPUPrimitiveDepthClampingState*>(
serverDesc->primitive.nextInChain);
EXPECT_EQ(ext1->chain.sType, clientExt1.chain.sType);
EXPECT_EQ(ext1->clampDepth, true);
const auto* ext2 = reinterpret_cast<const WGPUPrimitiveDepthClampingState*>(
ext1->chain.next);
EXPECT_EQ(ext2->chain.sType, clientExt2.chain.sType);
EXPECT_EQ(ext2->clampDepth, false);
EXPECT_EQ(ext2->chain.next, nullptr);
return api.GetNewRenderPipeline();
}));
FlushClient();
// Swap the order of the chained structs.
renderPipelineDesc.primitive.nextInChain = &clientExt2.chain;
clientExt2.chain.next = &clientExt1.chain;
clientExt1.chain.next = nullptr;
wgpuDeviceCreateRenderPipeline2(device, &renderPipelineDesc);
EXPECT_CALL(api, DeviceCreateRenderPipeline2(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused,
const WGPURenderPipelineDescriptor2* serverDesc) -> WGPURenderPipeline {
const auto* ext2 = reinterpret_cast<const WGPUPrimitiveDepthClampingState*>(
serverDesc->primitive.nextInChain);
EXPECT_EQ(ext2->chain.sType, clientExt2.chain.sType);
EXPECT_EQ(ext2->clampDepth, false);
const auto* ext1 = reinterpret_cast<const WGPUPrimitiveDepthClampingState*>(
ext2->chain.next);
EXPECT_EQ(ext1->chain.sType, clientExt1.chain.sType);
EXPECT_EQ(ext1->clampDepth, true);
EXPECT_EQ(ext1->chain.next, nullptr);
return api.GetNewRenderPipeline();
}));
FlushClient();
}
// Test that a chained struct with Invalid sType passes through as Invalid.
TEST_F(WireExtensionTests, InvalidSType) {
WGPUShaderModuleDescriptor shaderModuleDesc = {};
WGPUShaderModule apiShaderModule = api.GetNewShaderModule();
WGPUShaderModule shaderModule = wgpuDeviceCreateShaderModule(device, &shaderModuleDesc);
EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiShaderModule));
FlushClient();
WGPUPrimitiveDepthClampingState clientExt = {};
clientExt.chain.sType = WGPUSType_Invalid;
clientExt.chain.next = nullptr;
WGPURenderPipelineDescriptor2 renderPipelineDesc = {};
renderPipelineDesc.vertex.module = shaderModule;
renderPipelineDesc.vertex.entryPoint = "main";
renderPipelineDesc.primitive.nextInChain = &clientExt.chain;
wgpuDeviceCreateRenderPipeline2(device, &renderPipelineDesc);
EXPECT_CALL(api, DeviceCreateRenderPipeline2(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused,
const WGPURenderPipelineDescriptor2* serverDesc) -> WGPURenderPipeline {
EXPECT_EQ(serverDesc->primitive.nextInChain->sType, WGPUSType_Invalid);
EXPECT_EQ(serverDesc->primitive.nextInChain->next, nullptr);
return api.GetNewRenderPipeline();
}));
FlushClient();
}
// Test that a chained struct with unknown sType passes through as Invalid.
TEST_F(WireExtensionTests, UnknownSType) {
WGPUShaderModuleDescriptor shaderModuleDesc = {};
WGPUShaderModule apiShaderModule = api.GetNewShaderModule();
WGPUShaderModule shaderModule = wgpuDeviceCreateShaderModule(device, &shaderModuleDesc);
EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiShaderModule));
FlushClient();
WGPUPrimitiveDepthClampingState clientExt = {};
clientExt.chain.sType = static_cast<WGPUSType>(-1);
clientExt.chain.next = nullptr;
WGPURenderPipelineDescriptor2 renderPipelineDesc = {};
renderPipelineDesc.vertex.module = shaderModule;
renderPipelineDesc.vertex.entryPoint = "main";
renderPipelineDesc.primitive.nextInChain = &clientExt.chain;
wgpuDeviceCreateRenderPipeline2(device, &renderPipelineDesc);
EXPECT_CALL(api, DeviceCreateRenderPipeline2(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused,
const WGPURenderPipelineDescriptor2* serverDesc) -> WGPURenderPipeline {
EXPECT_EQ(serverDesc->primitive.nextInChain->sType, WGPUSType_Invalid);
EXPECT_EQ(serverDesc->primitive.nextInChain->next, nullptr);
return api.GetNewRenderPipeline();
}));
FlushClient();
}
// Test that if both an invalid and valid stype are passed on the chain, only the invalid
// sType passes through as Invalid.
TEST_F(WireExtensionTests, ValidAndInvalidSTypeInChain) {
WGPUShaderModuleDescriptor shaderModuleDesc = {};
WGPUShaderModule apiShaderModule = api.GetNewShaderModule();
WGPUShaderModule shaderModule = wgpuDeviceCreateShaderModule(device, &shaderModuleDesc);
EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiShaderModule));
FlushClient();
WGPUPrimitiveDepthClampingState clientExt2 = {};
clientExt2.chain.sType = WGPUSType_Invalid;
clientExt2.chain.next = nullptr;
WGPUPrimitiveDepthClampingState clientExt1 = {};
clientExt1.chain.sType = WGPUSType_PrimitiveDepthClampingState;
clientExt1.chain.next = &clientExt2.chain;
clientExt1.clampDepth = true;
WGPURenderPipelineDescriptor2 renderPipelineDesc = {};
renderPipelineDesc.vertex.module = shaderModule;
renderPipelineDesc.vertex.entryPoint = "main";
renderPipelineDesc.primitive.nextInChain = &clientExt1.chain;
wgpuDeviceCreateRenderPipeline2(device, &renderPipelineDesc);
EXPECT_CALL(api, DeviceCreateRenderPipeline2(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused,
const WGPURenderPipelineDescriptor2* serverDesc) -> WGPURenderPipeline {
const auto* ext = reinterpret_cast<const WGPUPrimitiveDepthClampingState*>(
serverDesc->primitive.nextInChain);
EXPECT_EQ(ext->chain.sType, clientExt1.chain.sType);
EXPECT_EQ(ext->clampDepth, true);
EXPECT_EQ(ext->chain.next->sType, WGPUSType_Invalid);
EXPECT_EQ(ext->chain.next->next, nullptr);
return api.GetNewRenderPipeline();
}));
FlushClient();
// Swap the order of the chained structs.
renderPipelineDesc.primitive.nextInChain = &clientExt2.chain;
clientExt2.chain.next = &clientExt1.chain;
clientExt1.chain.next = nullptr;
wgpuDeviceCreateRenderPipeline2(device, &renderPipelineDesc);
EXPECT_CALL(api, DeviceCreateRenderPipeline2(apiDevice, NotNull()))
.WillOnce(Invoke([&](Unused,
const WGPURenderPipelineDescriptor2* serverDesc) -> WGPURenderPipeline {
EXPECT_EQ(serverDesc->primitive.nextInChain->sType, WGPUSType_Invalid);
const auto* ext = reinterpret_cast<const WGPUPrimitiveDepthClampingState*>(
serverDesc->primitive.nextInChain->next);
EXPECT_EQ(ext->chain.sType, clientExt1.chain.sType);
EXPECT_EQ(ext->clampDepth, true);
EXPECT_EQ(ext->chain.next, nullptr);
return api.GetNewRenderPipeline();