Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 1 | // Copyright 2019 The Dawn Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "tests/unittests/wire/WireTest.h" |
| 16 | |
| 17 | #include "common/Constants.h" |
| 18 | |
Corentin Wallez | 8dfc593 | 2019-05-29 13:16:06 +0000 | [diff] [blame] | 19 | #include <array> |
| 20 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 21 | using namespace testing; |
| 22 | using namespace dawn_wire; |
| 23 | |
| 24 | class WireArgumentTests : public WireTest { |
| 25 | public: |
Corentin Wallez | 0ae00a1 | 2019-03-28 17:12:47 +0000 | [diff] [blame] | 26 | WireArgumentTests() { |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 27 | } |
| 28 | ~WireArgumentTests() override = default; |
| 29 | }; |
| 30 | |
| 31 | // Test that the wire is able to send numerical values |
| 32 | TEST_F(WireArgumentTests, ValueArgument) { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 33 | WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(device, nullptr); |
| 34 | WGPUComputePassEncoder pass = wgpuCommandEncoderBeginComputePass(encoder, nullptr); |
| 35 | wgpuComputePassEncoderDispatch(pass, 1, 2, 3); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 36 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 37 | WGPUCommandEncoder apiEncoder = api.GetNewCommandEncoder(); |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 38 | EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice, nullptr)).WillOnce(Return(apiEncoder)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 39 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 40 | WGPUComputePassEncoder apiPass = api.GetNewComputePassEncoder(); |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 41 | EXPECT_CALL(api, CommandEncoderBeginComputePass(apiEncoder, nullptr)).WillOnce(Return(apiPass)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 42 | |
| 43 | EXPECT_CALL(api, ComputePassEncoderDispatch(apiPass, 1, 2, 3)).Times(1); |
| 44 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 45 | FlushClient(); |
| 46 | } |
| 47 | |
| 48 | // Test that the wire is able to send arrays of numerical values |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 49 | TEST_F(WireArgumentTests, ValueArrayArgument) { |
Corentin Wallez | 8dfc593 | 2019-05-29 13:16:06 +0000 | [diff] [blame] | 50 | // Create a bindgroup. |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 51 | WGPUBindGroupLayoutDescriptor bglDescriptor = {}; |
Corentin Wallez | 3966eb1 | 2020-04-21 07:36:30 +0000 | [diff] [blame] | 52 | bglDescriptor.entryCount = 0; |
| 53 | bglDescriptor.entries = nullptr; |
Corentin Wallez | 8dfc593 | 2019-05-29 13:16:06 +0000 | [diff] [blame] | 54 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 55 | WGPUBindGroupLayout bgl = wgpuDeviceCreateBindGroupLayout(device, &bglDescriptor); |
| 56 | WGPUBindGroupLayout apiBgl = api.GetNewBindGroupLayout(); |
Corentin Wallez | 8dfc593 | 2019-05-29 13:16:06 +0000 | [diff] [blame] | 57 | EXPECT_CALL(api, DeviceCreateBindGroupLayout(apiDevice, _)).WillOnce(Return(apiBgl)); |
| 58 | |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 59 | WGPUBindGroupDescriptor bindGroupDescriptor = {}; |
Corentin Wallez | 8dfc593 | 2019-05-29 13:16:06 +0000 | [diff] [blame] | 60 | bindGroupDescriptor.layout = bgl; |
Corentin Wallez | 3966eb1 | 2020-04-21 07:36:30 +0000 | [diff] [blame] | 61 | bindGroupDescriptor.entryCount = 0; |
| 62 | bindGroupDescriptor.entries = nullptr; |
Corentin Wallez | 8dfc593 | 2019-05-29 13:16:06 +0000 | [diff] [blame] | 63 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 64 | WGPUBindGroup bindGroup = wgpuDeviceCreateBindGroup(device, &bindGroupDescriptor); |
| 65 | WGPUBindGroup apiBindGroup = api.GetNewBindGroup(); |
Corentin Wallez | 8dfc593 | 2019-05-29 13:16:06 +0000 | [diff] [blame] | 66 | EXPECT_CALL(api, DeviceCreateBindGroup(apiDevice, _)).WillOnce(Return(apiBindGroup)); |
| 67 | |
| 68 | // Use the bindgroup in SetBindGroup that takes an array of value offsets. |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 69 | WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(device, nullptr); |
| 70 | WGPUComputePassEncoder pass = wgpuCommandEncoderBeginComputePass(encoder, nullptr); |
Corentin Wallez | 8dfc593 | 2019-05-29 13:16:06 +0000 | [diff] [blame] | 71 | |
Austin Eng | 314fd35 | 2019-11-01 15:51:01 +0000 | [diff] [blame] | 72 | std::array<uint32_t, 4> testOffsets = {0, 42, 0xDEAD'BEEFu, 0xFFFF'FFFFu}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 73 | wgpuComputePassEncoderSetBindGroup(pass, 0, bindGroup, testOffsets.size(), testOffsets.data()); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 74 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 75 | WGPUCommandEncoder apiEncoder = api.GetNewCommandEncoder(); |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 76 | EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice, nullptr)).WillOnce(Return(apiEncoder)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 77 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 78 | WGPUComputePassEncoder apiPass = api.GetNewComputePassEncoder(); |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 79 | EXPECT_CALL(api, CommandEncoderBeginComputePass(apiEncoder, nullptr)).WillOnce(Return(apiPass)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 80 | |
Corentin Wallez | 8dfc593 | 2019-05-29 13:16:06 +0000 | [diff] [blame] | 81 | EXPECT_CALL(api, ComputePassEncoderSetBindGroup( |
| 82 | apiPass, 0, apiBindGroup, testOffsets.size(), |
Austin Eng | 314fd35 | 2019-11-01 15:51:01 +0000 | [diff] [blame] | 83 | MatchesLambda([testOffsets](const uint32_t* offsets) -> bool { |
Corentin Wallez | 8dfc593 | 2019-05-29 13:16:06 +0000 | [diff] [blame] | 84 | for (size_t i = 0; i < testOffsets.size(); i++) { |
| 85 | if (offsets[i] != testOffsets[i]) { |
| 86 | return false; |
| 87 | } |
| 88 | } |
| 89 | return true; |
| 90 | }))); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 91 | |
| 92 | FlushClient(); |
| 93 | } |
| 94 | |
| 95 | // Test that the wire is able to send C strings |
| 96 | TEST_F(WireArgumentTests, CStringArgument) { |
| 97 | // Create shader module |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 98 | WGPUShaderModuleDescriptor vertexDescriptor = {}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 99 | WGPUShaderModule vsModule = wgpuDeviceCreateShaderModule(device, &vertexDescriptor); |
| 100 | WGPUShaderModule apiVsModule = api.GetNewShaderModule(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 101 | EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiVsModule)); |
| 102 | |
Yunchao He | 108bcbd | 2019-02-15 02:20:57 +0000 | [diff] [blame] | 103 | // Create the color state descriptor |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 104 | WGPUBlendDescriptor blendDescriptor = {}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 105 | blendDescriptor.operation = WGPUBlendOperation_Add; |
| 106 | blendDescriptor.srcFactor = WGPUBlendFactor_One; |
| 107 | blendDescriptor.dstFactor = WGPUBlendFactor_One; |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 108 | WGPUColorStateDescriptor colorStateDescriptor = {}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 109 | colorStateDescriptor.format = WGPUTextureFormat_RGBA8Unorm; |
Yunchao He | 108bcbd | 2019-02-15 02:20:57 +0000 | [diff] [blame] | 110 | colorStateDescriptor.alphaBlend = blendDescriptor; |
| 111 | colorStateDescriptor.colorBlend = blendDescriptor; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 112 | colorStateDescriptor.writeMask = WGPUColorWriteMask_All; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 113 | |
| 114 | // Create the input state |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 115 | WGPUVertexStateDescriptor vertexState = {}; |
Kai Ninomiya | ae1f25f | 2019-11-07 22:23:29 +0000 | [diff] [blame] | 116 | vertexState.indexFormat = WGPUIndexFormat_Uint32; |
| 117 | vertexState.vertexBufferCount = 0; |
| 118 | vertexState.vertexBuffers = nullptr; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 119 | |
Yunchao He | c33a8c1 | 2019-04-11 18:46:54 +0000 | [diff] [blame] | 120 | // Create the rasterization state |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 121 | WGPURasterizationStateDescriptor rasterizationState = {}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 122 | rasterizationState.frontFace = WGPUFrontFace_CCW; |
| 123 | rasterizationState.cullMode = WGPUCullMode_None; |
Yunchao He | c33a8c1 | 2019-04-11 18:46:54 +0000 | [diff] [blame] | 124 | rasterizationState.depthBias = 0; |
| 125 | rasterizationState.depthBiasSlopeScale = 0.0; |
| 126 | rasterizationState.depthBiasClamp = 0.0; |
| 127 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 128 | // Create the depth-stencil state |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 129 | WGPUStencilStateFaceDescriptor stencilFace = {}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 130 | stencilFace.compare = WGPUCompareFunction_Always; |
| 131 | stencilFace.failOp = WGPUStencilOperation_Keep; |
| 132 | stencilFace.depthFailOp = WGPUStencilOperation_Keep; |
| 133 | stencilFace.passOp = WGPUStencilOperation_Keep; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 134 | |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 135 | WGPUDepthStencilStateDescriptor depthStencilState = {}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 136 | depthStencilState.format = WGPUTextureFormat_Depth24PlusStencil8; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 137 | depthStencilState.depthWriteEnabled = false; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 138 | depthStencilState.depthCompare = WGPUCompareFunction_Always; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 139 | depthStencilState.stencilBack = stencilFace; |
| 140 | depthStencilState.stencilFront = stencilFace; |
| 141 | depthStencilState.stencilReadMask = 0xff; |
| 142 | depthStencilState.stencilWriteMask = 0xff; |
| 143 | |
| 144 | // Create the pipeline layout |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 145 | WGPUPipelineLayoutDescriptor layoutDescriptor = {}; |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 146 | layoutDescriptor.bindGroupLayoutCount = 0; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 147 | layoutDescriptor.bindGroupLayouts = nullptr; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 148 | WGPUPipelineLayout layout = wgpuDeviceCreatePipelineLayout(device, &layoutDescriptor); |
| 149 | WGPUPipelineLayout apiLayout = api.GetNewPipelineLayout(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 150 | EXPECT_CALL(api, DeviceCreatePipelineLayout(apiDevice, _)).WillOnce(Return(apiLayout)); |
| 151 | |
| 152 | // Create pipeline |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 153 | WGPURenderPipelineDescriptor pipelineDescriptor = {}; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 154 | |
Corentin Wallez | c6c7a42 | 2019-09-05 09:35:07 +0000 | [diff] [blame] | 155 | pipelineDescriptor.vertexStage.module = vsModule; |
| 156 | pipelineDescriptor.vertexStage.entryPoint = "main"; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 157 | |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 158 | WGPUProgrammableStageDescriptor fragmentStage = {}; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 159 | fragmentStage.module = vsModule; |
| 160 | fragmentStage.entryPoint = "main"; |
| 161 | pipelineDescriptor.fragmentStage = &fragmentStage; |
| 162 | |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 163 | pipelineDescriptor.colorStateCount = 1; |
Corentin Wallez | c81a717 | 2019-09-20 23:22:27 +0000 | [diff] [blame] | 164 | pipelineDescriptor.colorStates = &colorStateDescriptor; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 165 | |
| 166 | pipelineDescriptor.sampleCount = 1; |
Corentin Wallez | f07e85c | 2019-07-15 20:47:56 +0000 | [diff] [blame] | 167 | pipelineDescriptor.sampleMask = 0xFFFFFFFF; |
| 168 | pipelineDescriptor.alphaToCoverageEnabled = false; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 169 | pipelineDescriptor.layout = layout; |
Kai Ninomiya | ae1f25f | 2019-11-07 22:23:29 +0000 | [diff] [blame] | 170 | pipelineDescriptor.vertexState = &vertexState; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 171 | pipelineDescriptor.primitiveTopology = WGPUPrimitiveTopology_TriangleList; |
Yunchao He | c33a8c1 | 2019-04-11 18:46:54 +0000 | [diff] [blame] | 172 | pipelineDescriptor.rasterizationState = &rasterizationState; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 173 | pipelineDescriptor.depthStencilState = &depthStencilState; |
| 174 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 175 | wgpuDeviceCreateRenderPipeline(device, &pipelineDescriptor); |
Corentin Wallez | cb2c64f | 2019-04-01 21:04:17 +0000 | [diff] [blame] | 176 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 177 | WGPURenderPipeline apiDummyPipeline = api.GetNewRenderPipeline(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 178 | EXPECT_CALL(api, |
| 179 | DeviceCreateRenderPipeline( |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 180 | apiDevice, MatchesLambda([](const WGPURenderPipelineDescriptor* desc) -> bool { |
Corentin Wallez | c6c7a42 | 2019-09-05 09:35:07 +0000 | [diff] [blame] | 181 | return desc->vertexStage.entryPoint == std::string("main"); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 182 | }))) |
Corentin Wallez | cb2c64f | 2019-04-01 21:04:17 +0000 | [diff] [blame] | 183 | .WillOnce(Return(apiDummyPipeline)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 184 | |
| 185 | FlushClient(); |
| 186 | } |
| 187 | |
| 188 | // Test that the wire is able to send objects as value arguments |
| 189 | TEST_F(WireArgumentTests, ObjectAsValueArgument) { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 190 | WGPUCommandEncoder cmdBufEncoder = wgpuDeviceCreateCommandEncoder(device, nullptr); |
| 191 | WGPUCommandEncoder apiEncoder = api.GetNewCommandEncoder(); |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 192 | EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice, nullptr)).WillOnce(Return(apiEncoder)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 193 | |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 194 | WGPUBufferDescriptor descriptor = {}; |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 195 | descriptor.size = 8; |
Corentin Wallez | 9e9e29f | 2019-08-27 08:21:39 +0000 | [diff] [blame] | 196 | descriptor.usage = |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 197 | static_cast<WGPUBufferUsage>(WGPUBufferUsage_CopySrc | WGPUBufferUsage_CopyDst); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 198 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 199 | WGPUBuffer buffer = wgpuDeviceCreateBuffer(device, &descriptor); |
| 200 | WGPUBuffer apiBuffer = api.GetNewBuffer(); |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 201 | EXPECT_CALL(api, DeviceCreateBuffer(apiDevice, _)) |
| 202 | .WillOnce(Return(apiBuffer)) |
| 203 | .RetiresOnSaturation(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 204 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 205 | wgpuCommandEncoderCopyBufferToBuffer(cmdBufEncoder, buffer, 0, buffer, 4, 4); |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 206 | EXPECT_CALL(api, CommandEncoderCopyBufferToBuffer(apiEncoder, apiBuffer, 0, apiBuffer, 4, 4)); |
| 207 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 208 | FlushClient(); |
| 209 | } |
| 210 | |
| 211 | // Test that the wire is able to send array of objects |
| 212 | TEST_F(WireArgumentTests, ObjectsAsPointerArgument) { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 213 | WGPUCommandBuffer cmdBufs[2]; |
| 214 | WGPUCommandBuffer apiCmdBufs[2]; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 215 | |
| 216 | // Create two command buffers we need to use a GMock sequence otherwise the order of the |
Corentin Wallez | 37b715d | 2019-02-18 09:42:03 +0000 | [diff] [blame] | 217 | // CreateCommandEncoder might be swapped since they are equivalent in term of matchers |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 218 | Sequence s; |
| 219 | for (int i = 0; i < 2; ++i) { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 220 | WGPUCommandEncoder cmdBufEncoder = wgpuDeviceCreateCommandEncoder(device, nullptr); |
| 221 | cmdBufs[i] = wgpuCommandEncoderFinish(cmdBufEncoder, nullptr); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 222 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 223 | WGPUCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder(); |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 224 | EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice, nullptr)) |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 225 | .InSequence(s) |
Corentin Wallez | 37b715d | 2019-02-18 09:42:03 +0000 | [diff] [blame] | 226 | .WillOnce(Return(apiCmdBufEncoder)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 227 | |
| 228 | apiCmdBufs[i] = api.GetNewCommandBuffer(); |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 229 | EXPECT_CALL(api, CommandEncoderFinish(apiCmdBufEncoder, nullptr)) |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 230 | .WillOnce(Return(apiCmdBufs[i])); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 233 | // Submit command buffer and check we got a call with both API-side command buffers |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 234 | wgpuQueueSubmit(queue, 2, cmdBufs); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 235 | |
| 236 | EXPECT_CALL( |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 237 | api, QueueSubmit(apiQueue, 2, MatchesLambda([=](const WGPUCommandBuffer* cmdBufs) -> bool { |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 238 | return cmdBufs[0] == apiCmdBufs[0] && cmdBufs[1] == apiCmdBufs[1]; |
| 239 | }))); |
| 240 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 241 | FlushClient(); |
| 242 | } |
| 243 | |
| 244 | // Test that the wire is able to send structures that contain pure values (non-objects) |
| 245 | TEST_F(WireArgumentTests, StructureOfValuesArgument) { |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 246 | WGPUSamplerDescriptor descriptor = {}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 247 | descriptor.magFilter = WGPUFilterMode_Linear; |
| 248 | descriptor.minFilter = WGPUFilterMode_Nearest; |
| 249 | descriptor.mipmapFilter = WGPUFilterMode_Linear; |
| 250 | descriptor.addressModeU = WGPUAddressMode_ClampToEdge; |
| 251 | descriptor.addressModeV = WGPUAddressMode_Repeat; |
| 252 | descriptor.addressModeW = WGPUAddressMode_MirrorRepeat; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 253 | descriptor.lodMinClamp = kLodMin; |
| 254 | descriptor.lodMaxClamp = kLodMax; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 255 | descriptor.compare = WGPUCompareFunction_Never; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 256 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 257 | wgpuDeviceCreateSampler(device, &descriptor); |
Corentin Wallez | cb2c64f | 2019-04-01 21:04:17 +0000 | [diff] [blame] | 258 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 259 | WGPUSampler apiDummySampler = api.GetNewSampler(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 260 | EXPECT_CALL(api, DeviceCreateSampler( |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 261 | apiDevice, MatchesLambda([](const WGPUSamplerDescriptor* desc) -> bool { |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 262 | return desc->nextInChain == nullptr && |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 263 | desc->magFilter == WGPUFilterMode_Linear && |
| 264 | desc->minFilter == WGPUFilterMode_Nearest && |
| 265 | desc->mipmapFilter == WGPUFilterMode_Linear && |
| 266 | desc->addressModeU == WGPUAddressMode_ClampToEdge && |
| 267 | desc->addressModeV == WGPUAddressMode_Repeat && |
| 268 | desc->addressModeW == WGPUAddressMode_MirrorRepeat && |
| 269 | desc->compare == WGPUCompareFunction_Never && |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 270 | desc->lodMinClamp == kLodMin && desc->lodMaxClamp == kLodMax; |
| 271 | }))) |
Corentin Wallez | cb2c64f | 2019-04-01 21:04:17 +0000 | [diff] [blame] | 272 | .WillOnce(Return(apiDummySampler)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 273 | |
| 274 | FlushClient(); |
| 275 | } |
| 276 | |
| 277 | // Test that the wire is able to send structures that contain objects |
| 278 | TEST_F(WireArgumentTests, StructureOfObjectArrayArgument) { |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 279 | WGPUBindGroupLayoutDescriptor bglDescriptor = {}; |
Corentin Wallez | 3966eb1 | 2020-04-21 07:36:30 +0000 | [diff] [blame] | 280 | bglDescriptor.entryCount = 0; |
| 281 | bglDescriptor.entries = nullptr; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 282 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 283 | WGPUBindGroupLayout bgl = wgpuDeviceCreateBindGroupLayout(device, &bglDescriptor); |
| 284 | WGPUBindGroupLayout apiBgl = api.GetNewBindGroupLayout(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 285 | EXPECT_CALL(api, DeviceCreateBindGroupLayout(apiDevice, _)).WillOnce(Return(apiBgl)); |
| 286 | |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 287 | WGPUPipelineLayoutDescriptor descriptor = {}; |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 288 | descriptor.bindGroupLayoutCount = 1; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 289 | descriptor.bindGroupLayouts = &bgl; |
| 290 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 291 | wgpuDeviceCreatePipelineLayout(device, &descriptor); |
Corentin Wallez | cb2c64f | 2019-04-01 21:04:17 +0000 | [diff] [blame] | 292 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 293 | WGPUPipelineLayout apiDummyLayout = api.GetNewPipelineLayout(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 294 | EXPECT_CALL(api, DeviceCreatePipelineLayout( |
| 295 | apiDevice, |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 296 | MatchesLambda([apiBgl](const WGPUPipelineLayoutDescriptor* desc) -> bool { |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 297 | return desc->nextInChain == nullptr && |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 298 | desc->bindGroupLayoutCount == 1 && |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 299 | desc->bindGroupLayouts[0] == apiBgl; |
| 300 | }))) |
Corentin Wallez | cb2c64f | 2019-04-01 21:04:17 +0000 | [diff] [blame] | 301 | .WillOnce(Return(apiDummyLayout)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 302 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 303 | FlushClient(); |
| 304 | } |
| 305 | |
| 306 | // Test that the wire is able to send structures that contain objects |
| 307 | TEST_F(WireArgumentTests, StructureOfStructureArrayArgument) { |
| 308 | static constexpr int NUM_BINDINGS = 3; |
Corentin Wallez | 3966eb1 | 2020-04-21 07:36:30 +0000 | [diff] [blame] | 309 | WGPUBindGroupLayoutEntry entries[NUM_BINDINGS]{ |
Corentin Wallez | fc441f9 | 2021-01-29 19:08:15 +0000 | [diff] [blame] | 310 | {nullptr, |
| 311 | 0, |
Brandon Jones | 9c52c299 | 2020-12-12 02:09:56 +0000 | [diff] [blame] | 312 | WGPUShaderStage_Vertex, |
| 313 | WGPUBindingType_Sampler, |
| 314 | false, |
| 315 | 0, |
| 316 | WGPUTextureViewDimension_2D, |
| 317 | WGPUTextureComponentType_Float, |
| 318 | WGPUTextureFormat_RGBA8Unorm, |
| 319 | {}, |
| 320 | {}, |
| 321 | {}, |
| 322 | {}}, |
Corentin Wallez | fc441f9 | 2021-01-29 19:08:15 +0000 | [diff] [blame] | 323 | {nullptr, |
| 324 | 1, |
Brandon Jones | 9c52c299 | 2020-12-12 02:09:56 +0000 | [diff] [blame] | 325 | WGPUShaderStage_Vertex, |
| 326 | WGPUBindingType_SampledTexture, |
| 327 | false, |
| 328 | 0, |
| 329 | WGPUTextureViewDimension_2D, |
| 330 | WGPUTextureComponentType_Float, |
| 331 | WGPUTextureFormat_RGBA8Unorm, |
| 332 | {}, |
| 333 | {}, |
| 334 | {}, |
| 335 | {}}, |
Corentin Wallez | fc441f9 | 2021-01-29 19:08:15 +0000 | [diff] [blame] | 336 | {nullptr, |
| 337 | 2, |
Brandon Jones | 9c52c299 | 2020-12-12 02:09:56 +0000 | [diff] [blame] | 338 | static_cast<WGPUShaderStage>(WGPUShaderStage_Vertex | WGPUShaderStage_Fragment), |
| 339 | WGPUBindingType_UniformBuffer, |
| 340 | false, |
| 341 | 0, |
| 342 | WGPUTextureViewDimension_2D, |
| 343 | WGPUTextureComponentType_Float, |
| 344 | WGPUTextureFormat_RGBA8Unorm, |
| 345 | {}, |
| 346 | {}, |
| 347 | {}, |
| 348 | {}}, |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 349 | }; |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 350 | WGPUBindGroupLayoutDescriptor bglDescriptor = {}; |
Corentin Wallez | 3966eb1 | 2020-04-21 07:36:30 +0000 | [diff] [blame] | 351 | bglDescriptor.entryCount = NUM_BINDINGS; |
| 352 | bglDescriptor.entries = entries; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 353 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 354 | wgpuDeviceCreateBindGroupLayout(device, &bglDescriptor); |
| 355 | WGPUBindGroupLayout apiBgl = api.GetNewBindGroupLayout(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 356 | EXPECT_CALL( |
| 357 | api, |
| 358 | DeviceCreateBindGroupLayout( |
Corentin Wallez | 3966eb1 | 2020-04-21 07:36:30 +0000 | [diff] [blame] | 359 | apiDevice, MatchesLambda([entries](const WGPUBindGroupLayoutDescriptor* desc) -> bool { |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 360 | for (int i = 0; i < NUM_BINDINGS; ++i) { |
Corentin Wallez | 3966eb1 | 2020-04-21 07:36:30 +0000 | [diff] [blame] | 361 | const auto& a = desc->entries[i]; |
| 362 | const auto& b = entries[i]; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 363 | if (a.binding != b.binding || a.visibility != b.visibility || |
| 364 | a.type != b.type) { |
| 365 | return false; |
| 366 | } |
| 367 | } |
Corentin Wallez | 3966eb1 | 2020-04-21 07:36:30 +0000 | [diff] [blame] | 368 | return desc->nextInChain == nullptr && desc->entryCount == 3; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 369 | }))) |
| 370 | .WillOnce(Return(apiBgl)); |
| 371 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 372 | FlushClient(); |
| 373 | } |
| 374 | |
| 375 | // Test passing nullptr instead of objects - array of objects version |
| 376 | TEST_F(WireArgumentTests, DISABLED_NullptrInArray) { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 377 | WGPUBindGroupLayout nullBGL = nullptr; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 378 | |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame] | 379 | WGPUPipelineLayoutDescriptor descriptor = {}; |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 380 | descriptor.bindGroupLayoutCount = 1; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 381 | descriptor.bindGroupLayouts = &nullBGL; |
| 382 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 383 | wgpuDeviceCreatePipelineLayout(device, &descriptor); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 384 | EXPECT_CALL(api, |
| 385 | DeviceCreatePipelineLayout( |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 386 | apiDevice, MatchesLambda([](const WGPUPipelineLayoutDescriptor* desc) -> bool { |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 387 | return desc->nextInChain == nullptr && desc->bindGroupLayoutCount == 1 && |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 388 | desc->bindGroupLayouts[0] == nullptr; |
| 389 | }))) |
| 390 | .WillOnce(Return(nullptr)); |
| 391 | |
| 392 | FlushClient(); |
| 393 | } |