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 | 8dfc593 | 2019-05-29 13:16:06 +0000 | [diff] [blame] | 52 | bglDescriptor.bindingCount = 0; |
| 53 | bglDescriptor.bindings = nullptr; |
| 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; |
| 61 | bindGroupDescriptor.bindingCount = 0; |
| 62 | bindGroupDescriptor.bindings = nullptr; |
| 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 = {}; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 99 | vertexDescriptor.codeSize = 0; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 100 | WGPUShaderModule vsModule = wgpuDeviceCreateShaderModule(device, &vertexDescriptor); |
| 101 | WGPUShaderModule apiVsModule = api.GetNewShaderModule(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 102 | EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiVsModule)); |
| 103 | |
Yunchao He | 108bcbd | 2019-02-15 02:20:57 +0000 | [diff] [blame] | 104 | // Create the color state descriptor |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 105 | WGPUBlendDescriptor blendDescriptor = {}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 106 | blendDescriptor.operation = WGPUBlendOperation_Add; |
| 107 | blendDescriptor.srcFactor = WGPUBlendFactor_One; |
| 108 | blendDescriptor.dstFactor = WGPUBlendFactor_One; |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 109 | WGPUColorStateDescriptor colorStateDescriptor = {}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 110 | colorStateDescriptor.format = WGPUTextureFormat_RGBA8Unorm; |
Yunchao He | 108bcbd | 2019-02-15 02:20:57 +0000 | [diff] [blame] | 111 | colorStateDescriptor.alphaBlend = blendDescriptor; |
| 112 | colorStateDescriptor.colorBlend = blendDescriptor; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 113 | colorStateDescriptor.writeMask = WGPUColorWriteMask_All; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 114 | |
| 115 | // Create the input state |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 116 | WGPUVertexStateDescriptor vertexState = {}; |
Kai Ninomiya | ae1f25f | 2019-11-07 22:23:29 +0000 | [diff] [blame] | 117 | vertexState.indexFormat = WGPUIndexFormat_Uint32; |
| 118 | vertexState.vertexBufferCount = 0; |
| 119 | vertexState.vertexBuffers = nullptr; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 120 | |
Yunchao He | c33a8c1 | 2019-04-11 18:46:54 +0000 | [diff] [blame] | 121 | // Create the rasterization state |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 122 | WGPURasterizationStateDescriptor rasterizationState = {}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 123 | rasterizationState.frontFace = WGPUFrontFace_CCW; |
| 124 | rasterizationState.cullMode = WGPUCullMode_None; |
Yunchao He | c33a8c1 | 2019-04-11 18:46:54 +0000 | [diff] [blame] | 125 | rasterizationState.depthBias = 0; |
| 126 | rasterizationState.depthBiasSlopeScale = 0.0; |
| 127 | rasterizationState.depthBiasClamp = 0.0; |
| 128 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 129 | // Create the depth-stencil state |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 130 | WGPUStencilStateFaceDescriptor stencilFace = {}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 131 | stencilFace.compare = WGPUCompareFunction_Always; |
| 132 | stencilFace.failOp = WGPUStencilOperation_Keep; |
| 133 | stencilFace.depthFailOp = WGPUStencilOperation_Keep; |
| 134 | stencilFace.passOp = WGPUStencilOperation_Keep; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 135 | |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 136 | WGPUDepthStencilStateDescriptor depthStencilState = {}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 137 | depthStencilState.format = WGPUTextureFormat_Depth24PlusStencil8; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 138 | depthStencilState.depthWriteEnabled = false; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 139 | depthStencilState.depthCompare = WGPUCompareFunction_Always; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 140 | depthStencilState.stencilBack = stencilFace; |
| 141 | depthStencilState.stencilFront = stencilFace; |
| 142 | depthStencilState.stencilReadMask = 0xff; |
| 143 | depthStencilState.stencilWriteMask = 0xff; |
| 144 | |
| 145 | // Create the pipeline layout |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 146 | WGPUPipelineLayoutDescriptor layoutDescriptor = {}; |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 147 | layoutDescriptor.bindGroupLayoutCount = 0; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 148 | layoutDescriptor.bindGroupLayouts = nullptr; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 149 | WGPUPipelineLayout layout = wgpuDeviceCreatePipelineLayout(device, &layoutDescriptor); |
| 150 | WGPUPipelineLayout apiLayout = api.GetNewPipelineLayout(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 151 | EXPECT_CALL(api, DeviceCreatePipelineLayout(apiDevice, _)).WillOnce(Return(apiLayout)); |
| 152 | |
| 153 | // Create pipeline |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 154 | WGPURenderPipelineDescriptor pipelineDescriptor = {}; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 155 | |
Corentin Wallez | c6c7a42 | 2019-09-05 09:35:07 +0000 | [diff] [blame] | 156 | pipelineDescriptor.vertexStage.module = vsModule; |
| 157 | pipelineDescriptor.vertexStage.entryPoint = "main"; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 158 | |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 159 | WGPUProgrammableStageDescriptor fragmentStage = {}; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 160 | fragmentStage.module = vsModule; |
| 161 | fragmentStage.entryPoint = "main"; |
| 162 | pipelineDescriptor.fragmentStage = &fragmentStage; |
| 163 | |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 164 | pipelineDescriptor.colorStateCount = 1; |
Corentin Wallez | c81a717 | 2019-09-20 23:22:27 +0000 | [diff] [blame] | 165 | pipelineDescriptor.colorStates = &colorStateDescriptor; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 166 | |
| 167 | pipelineDescriptor.sampleCount = 1; |
Corentin Wallez | f07e85c | 2019-07-15 20:47:56 +0000 | [diff] [blame] | 168 | pipelineDescriptor.sampleMask = 0xFFFFFFFF; |
| 169 | pipelineDescriptor.alphaToCoverageEnabled = false; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 170 | pipelineDescriptor.layout = layout; |
Kai Ninomiya | ae1f25f | 2019-11-07 22:23:29 +0000 | [diff] [blame] | 171 | pipelineDescriptor.vertexState = &vertexState; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 172 | pipelineDescriptor.primitiveTopology = WGPUPrimitiveTopology_TriangleList; |
Yunchao He | c33a8c1 | 2019-04-11 18:46:54 +0000 | [diff] [blame] | 173 | pipelineDescriptor.rasterizationState = &rasterizationState; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 174 | pipelineDescriptor.depthStencilState = &depthStencilState; |
| 175 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 176 | wgpuDeviceCreateRenderPipeline(device, &pipelineDescriptor); |
Corentin Wallez | cb2c64f | 2019-04-01 21:04:17 +0000 | [diff] [blame] | 177 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 178 | WGPURenderPipeline apiDummyPipeline = api.GetNewRenderPipeline(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 179 | EXPECT_CALL(api, |
| 180 | DeviceCreateRenderPipeline( |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 181 | apiDevice, MatchesLambda([](const WGPURenderPipelineDescriptor* desc) -> bool { |
Corentin Wallez | c6c7a42 | 2019-09-05 09:35:07 +0000 | [diff] [blame] | 182 | return desc->vertexStage.entryPoint == std::string("main"); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 183 | }))) |
Corentin Wallez | cb2c64f | 2019-04-01 21:04:17 +0000 | [diff] [blame] | 184 | .WillOnce(Return(apiDummyPipeline)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 185 | |
| 186 | FlushClient(); |
| 187 | } |
| 188 | |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 189 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 190 | // Test that the wire is able to send objects as value arguments |
| 191 | TEST_F(WireArgumentTests, ObjectAsValueArgument) { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 192 | WGPUCommandEncoder cmdBufEncoder = wgpuDeviceCreateCommandEncoder(device, nullptr); |
| 193 | WGPUCommandEncoder apiEncoder = api.GetNewCommandEncoder(); |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 194 | EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice, nullptr)).WillOnce(Return(apiEncoder)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 195 | |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 196 | WGPUBufferDescriptor descriptor = {}; |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 197 | descriptor.size = 8; |
Corentin Wallez | 9e9e29f | 2019-08-27 08:21:39 +0000 | [diff] [blame] | 198 | descriptor.usage = |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 199 | static_cast<WGPUBufferUsage>(WGPUBufferUsage_CopySrc | WGPUBufferUsage_CopyDst); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 200 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 201 | WGPUBuffer buffer = wgpuDeviceCreateBuffer(device, &descriptor); |
| 202 | WGPUBuffer apiBuffer = api.GetNewBuffer(); |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 203 | EXPECT_CALL(api, DeviceCreateBuffer(apiDevice, _)) |
| 204 | .WillOnce(Return(apiBuffer)) |
| 205 | .RetiresOnSaturation(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 206 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 207 | wgpuCommandEncoderCopyBufferToBuffer(cmdBufEncoder, buffer, 0, buffer, 4, 4); |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 208 | EXPECT_CALL(api, CommandEncoderCopyBufferToBuffer(apiEncoder, apiBuffer, 0, apiBuffer, 4, 4)); |
| 209 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 210 | FlushClient(); |
| 211 | } |
| 212 | |
| 213 | // Test that the wire is able to send array of objects |
| 214 | TEST_F(WireArgumentTests, ObjectsAsPointerArgument) { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 215 | WGPUCommandBuffer cmdBufs[2]; |
| 216 | WGPUCommandBuffer apiCmdBufs[2]; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 217 | |
| 218 | // 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] | 219 | // CreateCommandEncoder might be swapped since they are equivalent in term of matchers |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 220 | Sequence s; |
| 221 | for (int i = 0; i < 2; ++i) { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 222 | WGPUCommandEncoder cmdBufEncoder = wgpuDeviceCreateCommandEncoder(device, nullptr); |
| 223 | cmdBufs[i] = wgpuCommandEncoderFinish(cmdBufEncoder, nullptr); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 224 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 225 | WGPUCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder(); |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 226 | EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice, nullptr)) |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 227 | .InSequence(s) |
Corentin Wallez | 37b715d | 2019-02-18 09:42:03 +0000 | [diff] [blame] | 228 | .WillOnce(Return(apiCmdBufEncoder)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 229 | |
| 230 | apiCmdBufs[i] = api.GetNewCommandBuffer(); |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 231 | EXPECT_CALL(api, CommandEncoderFinish(apiCmdBufEncoder, nullptr)) |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 232 | .WillOnce(Return(apiCmdBufs[i])); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | // Create queue |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 236 | WGPUQueue queue = wgpuDeviceCreateQueue(device); |
| 237 | WGPUQueue apiQueue = api.GetNewQueue(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 238 | EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue)); |
| 239 | |
| 240 | // 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] | 241 | wgpuQueueSubmit(queue, 2, cmdBufs); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 242 | |
| 243 | EXPECT_CALL( |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 244 | api, QueueSubmit(apiQueue, 2, MatchesLambda([=](const WGPUCommandBuffer* cmdBufs) -> bool { |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 245 | return cmdBufs[0] == apiCmdBufs[0] && cmdBufs[1] == apiCmdBufs[1]; |
| 246 | }))); |
| 247 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 248 | FlushClient(); |
| 249 | } |
| 250 | |
| 251 | // Test that the wire is able to send structures that contain pure values (non-objects) |
| 252 | TEST_F(WireArgumentTests, StructureOfValuesArgument) { |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 253 | WGPUSamplerDescriptor descriptor = {}; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 254 | descriptor.magFilter = WGPUFilterMode_Linear; |
| 255 | descriptor.minFilter = WGPUFilterMode_Nearest; |
| 256 | descriptor.mipmapFilter = WGPUFilterMode_Linear; |
| 257 | descriptor.addressModeU = WGPUAddressMode_ClampToEdge; |
| 258 | descriptor.addressModeV = WGPUAddressMode_Repeat; |
| 259 | descriptor.addressModeW = WGPUAddressMode_MirrorRepeat; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 260 | descriptor.lodMinClamp = kLodMin; |
| 261 | descriptor.lodMaxClamp = kLodMax; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 262 | descriptor.compare = WGPUCompareFunction_Never; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 263 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 264 | wgpuDeviceCreateSampler(device, &descriptor); |
Corentin Wallez | cb2c64f | 2019-04-01 21:04:17 +0000 | [diff] [blame] | 265 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 266 | WGPUSampler apiDummySampler = api.GetNewSampler(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 267 | EXPECT_CALL(api, DeviceCreateSampler( |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 268 | apiDevice, MatchesLambda([](const WGPUSamplerDescriptor* desc) -> bool { |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 269 | return desc->nextInChain == nullptr && |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 270 | desc->magFilter == WGPUFilterMode_Linear && |
| 271 | desc->minFilter == WGPUFilterMode_Nearest && |
| 272 | desc->mipmapFilter == WGPUFilterMode_Linear && |
| 273 | desc->addressModeU == WGPUAddressMode_ClampToEdge && |
| 274 | desc->addressModeV == WGPUAddressMode_Repeat && |
| 275 | desc->addressModeW == WGPUAddressMode_MirrorRepeat && |
| 276 | desc->compare == WGPUCompareFunction_Never && |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 277 | desc->lodMinClamp == kLodMin && desc->lodMaxClamp == kLodMax; |
| 278 | }))) |
Corentin Wallez | cb2c64f | 2019-04-01 21:04:17 +0000 | [diff] [blame] | 279 | .WillOnce(Return(apiDummySampler)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 280 | |
| 281 | FlushClient(); |
| 282 | } |
| 283 | |
| 284 | // Test that the wire is able to send structures that contain objects |
| 285 | TEST_F(WireArgumentTests, StructureOfObjectArrayArgument) { |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 286 | WGPUBindGroupLayoutDescriptor bglDescriptor = {}; |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 287 | bglDescriptor.bindingCount = 0; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 288 | bglDescriptor.bindings = nullptr; |
| 289 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 290 | WGPUBindGroupLayout bgl = wgpuDeviceCreateBindGroupLayout(device, &bglDescriptor); |
| 291 | WGPUBindGroupLayout apiBgl = api.GetNewBindGroupLayout(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 292 | EXPECT_CALL(api, DeviceCreateBindGroupLayout(apiDevice, _)).WillOnce(Return(apiBgl)); |
| 293 | |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 294 | WGPUPipelineLayoutDescriptor descriptor = {}; |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 295 | descriptor.bindGroupLayoutCount = 1; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 296 | descriptor.bindGroupLayouts = &bgl; |
| 297 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 298 | wgpuDeviceCreatePipelineLayout(device, &descriptor); |
Corentin Wallez | cb2c64f | 2019-04-01 21:04:17 +0000 | [diff] [blame] | 299 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 300 | WGPUPipelineLayout apiDummyLayout = api.GetNewPipelineLayout(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 301 | EXPECT_CALL(api, DeviceCreatePipelineLayout( |
| 302 | apiDevice, |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 303 | MatchesLambda([apiBgl](const WGPUPipelineLayoutDescriptor* desc) -> bool { |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 304 | return desc->nextInChain == nullptr && |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 305 | desc->bindGroupLayoutCount == 1 && |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 306 | desc->bindGroupLayouts[0] == apiBgl; |
| 307 | }))) |
Corentin Wallez | cb2c64f | 2019-04-01 21:04:17 +0000 | [diff] [blame] | 308 | .WillOnce(Return(apiDummyLayout)); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 309 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 310 | FlushClient(); |
| 311 | } |
| 312 | |
| 313 | // Test that the wire is able to send structures that contain objects |
| 314 | TEST_F(WireArgumentTests, StructureOfStructureArrayArgument) { |
| 315 | static constexpr int NUM_BINDINGS = 3; |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 316 | WGPUBindGroupLayoutBinding bindings[NUM_BINDINGS]{ |
| 317 | {0, WGPUShaderStage_Vertex, WGPUBindingType_Sampler, false, false, |
| 318 | WGPUTextureViewDimension_2D, WGPUTextureComponentType_Float}, |
| 319 | {1, WGPUShaderStage_Vertex, WGPUBindingType_SampledTexture, false, false, |
| 320 | WGPUTextureViewDimension_2D, WGPUTextureComponentType_Float}, |
| 321 | {2, static_cast<WGPUShaderStage>(WGPUShaderStage_Vertex | WGPUShaderStage_Fragment), |
| 322 | WGPUBindingType_UniformBuffer, false, false, WGPUTextureViewDimension_2D, |
| 323 | WGPUTextureComponentType_Float}, |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 324 | }; |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 325 | WGPUBindGroupLayoutDescriptor bglDescriptor = {}; |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 326 | bglDescriptor.bindingCount = NUM_BINDINGS; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 327 | bglDescriptor.bindings = bindings; |
| 328 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 329 | wgpuDeviceCreateBindGroupLayout(device, &bglDescriptor); |
| 330 | WGPUBindGroupLayout apiBgl = api.GetNewBindGroupLayout(); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 331 | EXPECT_CALL( |
| 332 | api, |
| 333 | DeviceCreateBindGroupLayout( |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 334 | apiDevice, MatchesLambda([bindings](const WGPUBindGroupLayoutDescriptor* desc) -> bool { |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 335 | for (int i = 0; i < NUM_BINDINGS; ++i) { |
| 336 | const auto& a = desc->bindings[i]; |
| 337 | const auto& b = bindings[i]; |
| 338 | if (a.binding != b.binding || a.visibility != b.visibility || |
| 339 | a.type != b.type) { |
| 340 | return false; |
| 341 | } |
| 342 | } |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 343 | return desc->nextInChain == nullptr && desc->bindingCount == 3; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 344 | }))) |
| 345 | .WillOnce(Return(apiBgl)); |
| 346 | |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 347 | FlushClient(); |
| 348 | } |
| 349 | |
| 350 | // Test passing nullptr instead of objects - array of objects version |
| 351 | TEST_F(WireArgumentTests, DISABLED_NullptrInArray) { |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 352 | WGPUBindGroupLayout nullBGL = nullptr; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 353 | |
Austin Eng | 3ded65e | 2020-02-28 22:29:15 +0000 | [diff] [blame^] | 354 | WGPUPipelineLayoutDescriptor descriptor = {}; |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 355 | descriptor.bindGroupLayoutCount = 1; |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 356 | descriptor.bindGroupLayouts = &nullBGL; |
| 357 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 358 | wgpuDeviceCreatePipelineLayout(device, &descriptor); |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 359 | EXPECT_CALL(api, |
| 360 | DeviceCreatePipelineLayout( |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 361 | apiDevice, MatchesLambda([](const WGPUPipelineLayoutDescriptor* desc) -> bool { |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 362 | return desc->nextInChain == nullptr && desc->bindGroupLayoutCount == 1 && |
Austin Eng | 1198270 | 2019-02-14 18:47:07 +0000 | [diff] [blame] | 363 | desc->bindGroupLayouts[0] == nullptr; |
| 364 | }))) |
| 365 | .WillOnce(Return(nullptr)); |
| 366 | |
| 367 | FlushClient(); |
| 368 | } |