summaryrefslogtreecommitdiffstats
path: root/tools/render-test/vk-api.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-06-28 11:14:48 -0700
committerGitHub <noreply@github.com>2018-06-28 11:14:48 -0700
commitdfe13b54286b27dd15f591455bbb86b7798285c2 (patch)
tree4a11f01feaae059b6c11bdfbe12a614228af6dd5 /tools/render-test/vk-api.cpp
parent22033f06573f900dc030c487b2c30feddf3d8f16 (diff)
Share graphics API layer between tests/examples (#603)
The `render-test` project has an in-progress graphics API abstraction layer, and it makes sense to share this code with our examples rather than write a bunch of redundant code between examples and tests. Most of this change is just moving files from `tools/render-test/*` to a new library project at `tools/slang-graphics/`. The most complicated code change there is renaming from `render_test` to `slang_graphics`. The existing `hello` example was ported to use the graphics API layer instead of raw D3D11 API calls. It is still hard-coded to use the D3D11 back-end and the `SLANG_DXBC` target, so more work is needed if we want to actually support multiple APIs in the examples. I also went ahead and implemented an extremely rudimentary set of APIs to abstract over the Windows platform calls that were being made in the example, so that we could potentially run that same example on other platforms. I did *not* port `render-test` to use those APIs, and I also did not implement them for anything but Windows (my assumption is that for most other platforms we would just use SDL2, and require people to ensure it is installed to their machine before building Slang examples).
Diffstat (limited to 'tools/render-test/vk-api.cpp')
-rw-r--r--tools/render-test/vk-api.cpp138
1 files changed, 0 insertions, 138 deletions
diff --git a/tools/render-test/vk-api.cpp b/tools/render-test/vk-api.cpp
deleted file mode 100644
index df222d8ad..000000000
--- a/tools/render-test/vk-api.cpp
+++ /dev/null
@@ -1,138 +0,0 @@
-// vk-api.cpp
-#include "vk-api.h"
-
-#include "../../source/core/list.h"
-
-namespace renderer_test {
-using namespace Slang;
-
-// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! VulkanApi !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-#define VK_API_CHECK_FUNCTION(x) && (x != nullptr)
-#define VK_API_CHECK_FUNCTIONS(FUNCTION_LIST) true FUNCTION_LIST(VK_API_CHECK_FUNCTION)
-
-bool VulkanApi::areDefined(ProcType type) const
-{
- switch (type)
- {
- case ProcType::Global: return VK_API_CHECK_FUNCTIONS(VK_API_ALL_GLOBAL_PROCS);
- case ProcType::Instance: return VK_API_CHECK_FUNCTIONS(VK_API_ALL_INSTANCE_PROCS);
- case ProcType::Device: return VK_API_CHECK_FUNCTIONS(VK_API_ALL_DEVICE_PROCS);
- default:
- {
- assert(!"Unhandled type");
- return false;
- }
- }
-}
-
-Slang::Result VulkanApi::initGlobalProcs(const VulkanModule& module)
-{
-#define VK_API_GET_GLOBAL_PROC(x) x = (PFN_##x)module.getFunction(#x);
-
- // Initialize all the global functions
- VK_API_ALL_GLOBAL_PROCS(VK_API_GET_GLOBAL_PROC)
-
- if (!areDefined(ProcType::Global))
- {
- return SLANG_FAIL;
- }
- m_module = &module;
- return SLANG_OK;
-}
-
-Slang::Result VulkanApi::initInstanceProcs(VkInstance instance)
-{
- assert(instance && vkGetInstanceProcAddr != nullptr);
-
-#define VK_API_GET_INSTANCE_PROC(x) x = (PFN_##x)vkGetInstanceProcAddr(instance, #x);
-
- VK_API_ALL_INSTANCE_PROCS(VK_API_GET_INSTANCE_PROC)
-
- if (!areDefined(ProcType::Instance))
- {
- return SLANG_FAIL;
- }
-
- m_instance = instance;
- return SLANG_OK;
-}
-
-Slang::Result VulkanApi::initPhysicalDevice(VkPhysicalDevice physicalDevice)
-{
- assert(m_physicalDevice == VK_NULL_HANDLE);
- m_physicalDevice = physicalDevice;
-
- vkGetPhysicalDeviceProperties(m_physicalDevice, &m_deviceProperties);
- vkGetPhysicalDeviceFeatures(m_physicalDevice, &m_deviceFeatures);
- vkGetPhysicalDeviceMemoryProperties(m_physicalDevice, &m_deviceMemoryProperties);
-
- return SLANG_OK;
-}
-
-Slang::Result VulkanApi::initDeviceProcs(VkDevice device)
-{
- assert(m_instance && device && vkGetDeviceProcAddr != nullptr);
-
-#define VK_API_GET_DEVICE_PROC(x) x = (PFN_##x)vkGetDeviceProcAddr(device, #x);
-
- VK_API_ALL_DEVICE_PROCS(VK_API_GET_DEVICE_PROC)
-
- if (!areDefined(ProcType::Device))
- {
- return SLANG_FAIL;
- }
-
- m_device = device;
- return SLANG_OK;
-}
-
-int VulkanApi::findMemoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags properties) const
-{
- assert(typeBits);
-
- const int numMemoryTypes = int(m_deviceMemoryProperties.memoryTypeCount);
-
- // bit holds current test bit against typeBits. Ie bit == 1 << typeBits
-
- uint32_t bit = 1;
- for (int i = 0; i < numMemoryTypes; ++i, bit += bit)
- {
- auto const& memoryType = m_deviceMemoryProperties.memoryTypes[i];
- if ((typeBits & bit) && (memoryType.propertyFlags & properties) == properties)
- {
- return i;
- }
- }
-
- //assert(!"failed to find a usable memory type");
- return -1;
-}
-
-int VulkanApi::findQueue(VkQueueFlags reqFlags) const
-{
- assert(m_physicalDevice != VK_NULL_HANDLE);
-
- uint32_t numQueueFamilies = 0;
- vkGetPhysicalDeviceQueueFamilyProperties(m_physicalDevice, &numQueueFamilies, nullptr);
-
- Slang::List<VkQueueFamilyProperties> queueFamilies;
- queueFamilies.SetSize(numQueueFamilies);
- vkGetPhysicalDeviceQueueFamilyProperties(m_physicalDevice, &numQueueFamilies, queueFamilies.Buffer());
-
- // Find a queue that can service our needs
- //VkQueueFlags reqQueueFlags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT;
-
- int queueFamilyIndex = -1;
- for (int i = 0; i < int(numQueueFamilies); ++i)
- {
- if ((queueFamilies[i].queueFlags & reqFlags) == reqFlags)
- {
- return i;
- }
- }
-
- return -1;
-}
-
-} // renderer_test