From 5c925374189555c85b18a4c032076162ce28ef81 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 12 Jun 2017 18:32:15 -0400 Subject: [PATCH] Add validation tests for B2B commands --- src/tests/CMakeLists.txt | 1 + .../CopyCommandsValidationTests.cpp | 106 ++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 src/tests/unittests/validation/CopyCommandsValidationTests.cpp diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 47e8eb5ff2..2baeb3268e 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -28,6 +28,7 @@ add_executable(nxt_unittests ${VALIDATION_TESTS_DIR}/BufferValidationTests.cpp ${VALIDATION_TESTS_DIR}/CommandBufferValidationTests.cpp ${VALIDATION_TESTS_DIR}/ComputeValidationTests.cpp + ${VALIDATION_TESTS_DIR}/CopyCommandsValidationTests.cpp ${VALIDATION_TESTS_DIR}/DepthStencilStateValidationTests.cpp ${VALIDATION_TESTS_DIR}/FramebufferValidationTests.cpp ${VALIDATION_TESTS_DIR}/RenderPassValidationTests.cpp diff --git a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp new file mode 100644 index 0000000000..a39115806b --- /dev/null +++ b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp @@ -0,0 +1,106 @@ +// Copyright 2017 The NXT Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "ValidationTest.h" + +class CopyCommandTest_B2B : public ValidationTest { +}; + +// Test a successfull B2B copy +TEST_F(CopyCommandTest_B2B, Success) { + nxt::Buffer source = device.CreateBufferBuilder() + .SetSize(16) + .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc) + .GetResult(); + source.FreezeUsage(nxt::BufferUsageBit::TransferSrc); + + nxt::Buffer destination = device.CreateBufferBuilder() + .SetSize(16) + .SetAllowedUsage(nxt::BufferUsageBit::TransferDst) + .GetResult(); + destination.FreezeUsage(nxt::BufferUsageBit::TransferDst); + + // Copy different copies, including some that touch the OOB condition + nxt::CommandBuffer commands = AssertWillBeSuccess(device.CreateCommandBufferBuilder()) + .CopyBufferToBuffer(source, 0, destination, 0, 16) + .CopyBufferToBuffer(source, 8, destination, 0, 8) + .CopyBufferToBuffer(source, 0, destination, 8, 8) + .GetResult(); +} + +// Test B2B copies with overflows +TEST_F(CopyCommandTest_B2B, OutOfBounds) { + nxt::Buffer source = device.CreateBufferBuilder() + .SetSize(16) + .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc) + .GetResult(); + source.FreezeUsage(nxt::BufferUsageBit::TransferSrc); + + nxt::Buffer destination = device.CreateBufferBuilder() + .SetSize(16) + .SetAllowedUsage(nxt::BufferUsageBit::TransferDst) + .GetResult(); + destination.FreezeUsage(nxt::BufferUsageBit::TransferDst); + + // OOB on the source + { + nxt::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder()) + .CopyBufferToBuffer(source, 8, destination, 0, 12) + .GetResult(); + } + + // OOB on the destination + { + nxt::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder()) + .CopyBufferToBuffer(source, 0, destination, 8, 12) + .GetResult(); + } +} + +// Test B2B copies with overflows +TEST_F(CopyCommandTest_B2B, BadUsage) { + nxt::Buffer source = device.CreateBufferBuilder() + .SetSize(16) + .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc) + .GetResult(); + source.FreezeUsage(nxt::BufferUsageBit::TransferSrc); + + nxt::Buffer destination = device.CreateBufferBuilder() + .SetSize(16) + .SetAllowedUsage(nxt::BufferUsageBit::TransferDst) + .GetResult(); + destination.FreezeUsage(nxt::BufferUsageBit::TransferDst); + + nxt::Buffer vertex = device.CreateBufferBuilder() + .SetSize(16) + .SetAllowedUsage(nxt::BufferUsageBit::Vertex) + .GetResult(); + vertex.FreezeUsage(nxt::BufferUsageBit::Vertex); + + // Source with incorrect usage + { + nxt::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder()) + .CopyBufferToBuffer(vertex, 0, destination, 0, 16) + .GetResult(); + } + + // Destination with incorrect usage + { + nxt::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder()) + .CopyBufferToBuffer(source, 0, vertex, 0, 16) + .GetResult(); + } +} + +// TODO(cwallez@chromium.org): Test that B2B copies are forbidden inside renderpasses