Austin Eng | 05d9e2c | 2021-02-05 21:08:44 +0000 | [diff] [blame] | 1 | // Copyright 2021 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/validation/ValidationTest.h" |
| 16 | |
| 17 | #include "tests/MockCallback.h" |
| 18 | |
| 19 | using namespace testing; |
| 20 | |
| 21 | class MultipleDeviceTest : public ValidationTest {}; |
| 22 | |
| 23 | // Test that it is invalid to submit a command buffer created on a different device. |
| 24 | TEST_F(MultipleDeviceTest, ValidatesSameDevice) { |
| 25 | wgpu::Device device2 = RegisterDevice(CreateTestDevice()); |
| 26 | wgpu::CommandBuffer commandBuffer = device2.CreateCommandEncoder().Finish(); |
| 27 | |
| 28 | ASSERT_DEVICE_ERROR(device.GetQueue().Submit(1, &commandBuffer)); |
| 29 | } |
| 30 | |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 31 | // Test that CreatePipelineAsync fails creation with an Error status if it uses |
Austin Eng | 05d9e2c | 2021-02-05 21:08:44 +0000 | [diff] [blame] | 32 | // objects from a different device. |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 33 | TEST_F(MultipleDeviceTest, ValidatesSameDeviceCreatePipelineAsync) { |
Austin Eng | 05d9e2c | 2021-02-05 21:08:44 +0000 | [diff] [blame] | 34 | wgpu::ShaderModuleWGSLDescriptor wgslDesc = {}; |
| 35 | wgslDesc.source = R"( |
Corentin Wallez | 21bd02b | 2021-04-13 09:48:24 +0000 | [diff] [blame] | 36 | [[stage(compute)]] fn main() { |
Austin Eng | 05d9e2c | 2021-02-05 21:08:44 +0000 | [diff] [blame] | 37 | } |
| 38 | )"; |
| 39 | |
| 40 | wgpu::ShaderModuleDescriptor shaderModuleDesc = {}; |
| 41 | shaderModuleDesc.nextInChain = &wgslDesc; |
| 42 | |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 43 | // Base case: CreateComputePipelineAsync succeeds. |
Austin Eng | 05d9e2c | 2021-02-05 21:08:44 +0000 | [diff] [blame] | 44 | { |
| 45 | wgpu::ShaderModule shaderModule = device.CreateShaderModule(&shaderModuleDesc); |
| 46 | |
| 47 | wgpu::ComputePipelineDescriptor pipelineDesc = {}; |
| 48 | pipelineDesc.computeStage.module = shaderModule; |
| 49 | pipelineDesc.computeStage.entryPoint = "main"; |
| 50 | |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 51 | StrictMock<MockCallback<WGPUCreateComputePipelineAsyncCallback>> creationCallback; |
Austin Eng | 05d9e2c | 2021-02-05 21:08:44 +0000 | [diff] [blame] | 52 | EXPECT_CALL(creationCallback, |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 53 | Call(WGPUCreatePipelineAsyncStatus_Success, NotNull(), _, this)) |
Austin Eng | 05d9e2c | 2021-02-05 21:08:44 +0000 | [diff] [blame] | 54 | .WillOnce(WithArg<1>(Invoke( |
| 55 | [](WGPUComputePipeline pipeline) { wgpu::ComputePipeline::Acquire(pipeline); }))); |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 56 | device.CreateComputePipelineAsync(&pipelineDesc, creationCallback.Callback(), |
Austin Eng | 05d9e2c | 2021-02-05 21:08:44 +0000 | [diff] [blame] | 57 | creationCallback.MakeUserdata(this)); |
| 58 | |
| 59 | WaitForAllOperations(device); |
| 60 | } |
| 61 | |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 62 | // CreateComputePipelineAsync errors if the shader module is created on a different device. |
Austin Eng | 05d9e2c | 2021-02-05 21:08:44 +0000 | [diff] [blame] | 63 | { |
| 64 | wgpu::Device device2 = RegisterDevice(CreateTestDevice()); |
| 65 | wgpu::ShaderModule shaderModule = device2.CreateShaderModule(&shaderModuleDesc); |
| 66 | |
| 67 | wgpu::ComputePipelineDescriptor pipelineDesc = {}; |
| 68 | pipelineDesc.computeStage.module = shaderModule; |
| 69 | pipelineDesc.computeStage.entryPoint = "main"; |
| 70 | |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 71 | StrictMock<MockCallback<WGPUCreateComputePipelineAsyncCallback>> creationCallback; |
Austin Eng | 05d9e2c | 2021-02-05 21:08:44 +0000 | [diff] [blame] | 72 | EXPECT_CALL(creationCallback, |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 73 | Call(WGPUCreatePipelineAsyncStatus_Error, nullptr, _, this + 1)) |
Austin Eng | 05d9e2c | 2021-02-05 21:08:44 +0000 | [diff] [blame] | 74 | .Times(1); |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 75 | device.CreateComputePipelineAsync(&pipelineDesc, creationCallback.Callback(), |
Austin Eng | 05d9e2c | 2021-02-05 21:08:44 +0000 | [diff] [blame] | 76 | creationCallback.MakeUserdata(this + 1)); |
| 77 | |
| 78 | WaitForAllOperations(device); |
| 79 | } |
| 80 | } |