Commit abb57857 by Ben Clayton

tests: Add a unit test for a simple memcpy compute shader

Bug: b/126871859 Change-Id: I0b3db6c033419a2ad54453d470960330d4f337cc Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/25909 Presubmit-Ready: Ben Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent f2be26a1
......@@ -2353,6 +2353,7 @@ endif()
if(BUILD_TESTS AND BUILD_VULKAN)
set(UNITTESTS_LIST
${CMAKE_CURRENT_SOURCE_DIR}/tests/VulkanUnitTests/Device.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/VulkanUnitTests/Driver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/VulkanUnitTests/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/VulkanUnitTests/unittests.cpp
......@@ -2363,6 +2364,7 @@ if(BUILD_TESTS AND BUILD_VULKAN)
${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest/googletest/include/
${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest/googlemock/include/
${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest/googletest/
${CMAKE_CURRENT_SOURCE_DIR}/third_party/SPIRV-Tools/include
${CMAKE_CURRENT_SOURCE_DIR}/include/
)
......@@ -2373,5 +2375,5 @@ if(BUILD_TESTS AND BUILD_VULKAN)
COMPILE_DEFINITIONS "STANDALONE"
)
target_link_libraries(vk-unittests ${OS_LIBS})
target_link_libraries(vk-unittests ${OS_LIBS} SPIRV-Tools)
endif()
// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
//
// 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 <vulkan/vulkan_core.h>
#include <vector>
class Driver;
// Device provides a wrapper around a VkDevice with a number of helper functions
// for common test operations.
class Device
{
public:
Device();
// CreateComputeDevice enumerates the physical devices, looking for a device
// that supports compute.
// If a compatible physical device is found, then a device is created and
// assigned to out.
// If a compatible physical device is not found, VK_SUCCESS will still be
// returned (as there was no Vulkan error), but calling Device::IsValid()
// on this device will return false.
static VkResult CreateComputeDevice(
Driver const *driver, VkInstance instance, Device *out);
// IsValid returns true if the Device is initialized and can be used.
bool IsValid() const;
// CreateBuffer creates a new buffer with the
// VK_BUFFER_USAGE_STORAGE_BUFFER_BIT usage, and
// VK_SHARING_MODE_EXCLUSIVE sharing mode.
VkResult CreateStorageBuffer(VkDeviceMemory memory, VkDeviceSize size,
VkDeviceSize offset, VkBuffer *out) const;
// CreateShaderModule creates a new shader module with the given SPIR-V
// code.
VkResult CreateShaderModule(const std::vector<uint32_t> &spirv,
VkShaderModule *out) const;
// CreateDescriptorSetLayout creates a new descriptor set layout with the
// given bindings.
VkResult CreateDescriptorSetLayout(
const std::vector<VkDescriptorSetLayoutBinding> &bindings,
VkDescriptorSetLayout *out) const;
// CreatePipelineLayout creates a new single set descriptor set layout.
VkResult CreatePipelineLayout(VkDescriptorSetLayout layout,
VkPipelineLayout *out) const;
// CreateComputePipeline creates a new compute pipeline with the entry point
// "main".
VkResult CreateComputePipeline(VkShaderModule module,
VkPipelineLayout pipelineLayout,
VkPipeline *out) const;
// CreateStorageBufferDescriptorPool creates a new descriptor pool that can
// hold descriptorCount storage buffers.
VkResult CreateStorageBufferDescriptorPool(uint32_t descriptorCount,
VkDescriptorPool *out) const;
// AllocateDescriptorSet allocates a single descriptor set with the given
// layout from pool.
VkResult AllocateDescriptorSet(VkDescriptorPool pool,
VkDescriptorSetLayout layout,
VkDescriptorSet *out) const;
// UpdateStorageBufferDescriptorSets updates the storage buffers in
// descriptorSet with the given list of VkDescriptorBufferInfos.
void UpdateStorageBufferDescriptorSets(VkDescriptorSet descriptorSet,
const std::vector<VkDescriptorBufferInfo> &bufferInfos) const;
// AllocateMemory allocates size bytes from a memory heap that has all the
// given flag bits set.
// If memory could not be allocated from any heap then
// VK_ERROR_OUT_OF_DEVICE_MEMORY is returned.
VkResult AllocateMemory(size_t size, VkMemoryPropertyFlags flags, VkDeviceMemory* out) const;
// MapMemory wraps vkMapMemory, supplying the first VkDevice parameter.
VkResult MapMemory(VkDeviceMemory memory, VkDeviceSize offset,
VkDeviceSize size, VkMemoryMapFlags flags, void **ppData) const;
// UnmapMemory wraps vkUnmapMemory, supplying the first VkDevice parameter.
void UnmapMemory(VkDeviceMemory memory) const;
// CreateCommandPool creates a new command pool.
VkResult CreateCommandPool(VkCommandPool* out) const;
// AllocateCommandBuffer creates a new command buffer with a primary level.
VkResult AllocateCommandBuffer(VkCommandPool pool, VkCommandBuffer* out) const;
// BeginCommandBuffer begins writing to commandBuffer.
VkResult BeginCommandBuffer(VkCommandBufferUsageFlagBits usage, VkCommandBuffer commandBuffer) const;
// QueueSubmitAndWait submits the given command buffer and waits for it to
// complete.
VkResult QueueSubmitAndWait(VkCommandBuffer commandBuffer) const;
private:
Device(Driver const *driver, VkDevice device, VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex);
static VkResult GetPhysicalDevices(
Driver const *driver, VkInstance instance,
std::vector<VkPhysicalDevice> &out);
static int GetComputeQueueFamilyIndex(
Driver const *driver, VkPhysicalDevice device);
static std::vector<VkQueueFamilyProperties>
GetPhysicalDeviceQueueFamilyProperties(
Driver const *driver, VkPhysicalDevice device);
Driver const *driver;
VkDevice device;
VkPhysicalDevice physicalDevice;
uint32_t queueFamilyIndex;
};
......@@ -98,6 +98,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\third_party\googletest\googletest\src\gtest-all.cc" />
<ClCompile Include="Device.cpp" />
<ClCompile Include="Driver.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="unittests.cpp" />
......@@ -108,6 +109,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Device.hpp" />
<ClInclude Include="Driver.hpp" />
<ClInclude Include="VkGlobalFuncs.hpp" />
<ClInclude Include="VkInstanceFuncs.hpp" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment