From dfe13b54286b27dd15f591455bbb86b7798285c2 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 28 Jun 2018 11:14:48 -0700 Subject: 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). --- tools/render-test/vk-api.h | 196 --------------------------------------------- 1 file changed, 196 deletions(-) delete mode 100644 tools/render-test/vk-api.h (limited to 'tools/render-test/vk-api.h') diff --git a/tools/render-test/vk-api.h b/tools/render-test/vk-api.h deleted file mode 100644 index 521d6301d..000000000 --- a/tools/render-test/vk-api.h +++ /dev/null @@ -1,196 +0,0 @@ -// vk-api.h -#pragma once - -#include "vk-module.h" - -namespace renderer_test { - -#define VK_API_GLOBAL_PROCS(x) \ - x(vkGetInstanceProcAddr) \ - x(vkCreateInstance) \ - /* */ - -#define VK_API_INSTANCE_PROCS(x) \ - x(vkCreateDevice) \ - x(vkCreateDebugReportCallbackEXT) \ - x(vkDestroyDebugReportCallbackEXT) \ - x(vkDebugReportMessageEXT) \ - x(vkEnumeratePhysicalDevices) \ - x(vkGetPhysicalDeviceProperties) \ - x(vkGetPhysicalDeviceFeatures) \ - x(vkGetPhysicalDeviceMemoryProperties) \ - x(vkGetPhysicalDeviceQueueFamilyProperties) \ - x(vkGetPhysicalDeviceFormatProperties) \ - x(vkGetDeviceProcAddr) \ - /* */ - -#define VK_API_DEVICE_PROCS(x) \ - x(vkCreateDescriptorPool) \ - x(vkDestroyDescriptorPool) \ - x(vkGetDeviceQueue) \ - x(vkQueueSubmit) \ - x(vkQueueWaitIdle) \ - x(vkCreateBuffer) \ - x(vkAllocateMemory) \ - x(vkMapMemory) \ - x(vkUnmapMemory) \ - x(vkCmdCopyBuffer) \ - x(vkDestroyBuffer) \ - x(vkFreeMemory) \ - x(vkCreateDescriptorSetLayout) \ - x(vkDestroyDescriptorSetLayout) \ - x(vkAllocateDescriptorSets) \ - x(vkUpdateDescriptorSets) \ - x(vkCreatePipelineLayout) \ - x(vkDestroyPipelineLayout) \ - x(vkCreateComputePipelines) \ - x(vkCreateGraphicsPipelines) \ - x(vkDestroyPipeline) \ - x(vkCreateShaderModule) \ - x(vkDestroyShaderModule) \ - x(vkCreateFramebuffer) \ - x(vkDestroyFramebuffer) \ - x(vkCreateImage) \ - x(vkDestroyImage) \ - x(vkCreateImageView) \ - x(vkDestroyImageView) \ - x(vkCreateRenderPass) \ - x(vkDestroyRenderPass) \ - x(vkCreateCommandPool) \ - x(vkDestroyCommandPool) \ - x(vkCreateSampler) \ - x(vkDestroySampler) \ - x(vkCreateBufferView) \ - x(vkDestroyBufferView) \ - \ - x(vkGetBufferMemoryRequirements) \ - x(vkGetImageMemoryRequirements) \ - \ - x(vkCmdBindPipeline) \ - x(vkCmdBindDescriptorSets) \ - x(vkCmdDispatch) \ - x(vkCmdDraw) \ - x(vkCmdSetScissor) \ - x(vkCmdSetViewport) \ - x(vkCmdBindVertexBuffers) \ - x(vkCmdBindIndexBuffer) \ - x(vkCmdBeginRenderPass) \ - x(vkCmdEndRenderPass) \ - x(vkCmdPipelineBarrier) \ - x(vkCmdCopyBufferToImage)\ - \ - x(vkCreateFence) \ - x(vkDestroyFence) \ - x(vkResetFences) \ - x(vkGetFenceStatus) \ - x(vkWaitForFences) \ - \ - x(vkCreateSemaphore) \ - x(vkDestroySemaphore) \ - \ - x(vkCreateEvent) \ - x(vkDestroyEvent) \ - x(vkGetEventStatus) \ - x(vkSetEvent) \ - x(vkResetEvent) \ - \ - x(vkFreeCommandBuffers) \ - x(vkAllocateCommandBuffers) \ - x(vkBeginCommandBuffer) \ - x(vkEndCommandBuffer) \ - x(vkResetCommandBuffer) \ - \ - x(vkBindImageMemory) \ - x(vkBindBufferMemory) \ - /* */ - -#if SLANG_WINDOWS_FAMILY -# define VK_API_INSTANCE_PLATFORM_KHR_PROCS(x) \ - x(vkCreateWin32SurfaceKHR) \ - /* */ -#else -# define VK_API_INSTANCE_PLATFORM_KHR_PROCS(x) \ - x(vkCreateXlibSurfaceKHR) \ - /* */ -#endif - -#define VK_API_INSTANCE_KHR_PROCS(x) \ - VK_API_INSTANCE_PLATFORM_KHR_PROCS(x) \ - x(vkGetPhysicalDeviceSurfaceSupportKHR) \ - x(vkGetPhysicalDeviceSurfaceFormatsKHR) \ - x(vkGetPhysicalDeviceSurfacePresentModesKHR) \ - x(vkGetPhysicalDeviceSurfaceCapabilitiesKHR) \ - x(vkDestroySurfaceKHR) \ - /* */ - -#define VK_API_DEVICE_KHR_PROCS(x) \ - x(vkQueuePresentKHR) \ - x(vkCreateSwapchainKHR) \ - x(vkGetSwapchainImagesKHR) \ - x(vkDestroySwapchainKHR) \ - x(vkAcquireNextImageKHR) \ - /* */ - -#define VK_API_ALL_GLOBAL_PROCS(x) \ - VK_API_GLOBAL_PROCS(x) - -#define VK_API_ALL_INSTANCE_PROCS(x) \ - VK_API_INSTANCE_PROCS(x) \ - VK_API_INSTANCE_KHR_PROCS(x) - -#define VK_API_ALL_DEVICE_PROCS(x) \ - VK_API_DEVICE_PROCS(x) \ - VK_API_DEVICE_KHR_PROCS(x) - -#define VK_API_ALL_PROCS(x) \ - VK_API_ALL_GLOBAL_PROCS(x) \ - VK_API_ALL_INSTANCE_PROCS(x) \ - VK_API_ALL_DEVICE_PROCS(x) \ - /* */ - -#define VK_API_DECLARE_PROC(NAME) PFN_##NAME NAME = nullptr; - -struct VulkanApi -{ - VK_API_ALL_PROCS(VK_API_DECLARE_PROC) - - enum class ProcType - { - Global, - Instance, - Device, - }; - - /// Returns true if all the functions in the class are defined - bool areDefined(ProcType type) const; - - /// Sets up global parameters - Slang::Result initGlobalProcs(const VulkanModule& module); - /// Initialize the instance functions - Slang::Result initInstanceProcs(VkInstance instance); - - /// Called before initDevice - Slang::Result initPhysicalDevice(VkPhysicalDevice physicalDevice); - - /// Initialize the device functions - Slang::Result initDeviceProcs(VkDevice device); - - /// Type bits control which indices are tested against bit 0 for testing at index 0 - /// properties - a memory type must have all the bits set as passed in - /// Returns -1 if couldn't find an appropriate memory type index - int findMemoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags properties) const; - - /// Given queue required flags, finds a queue - int findQueue(VkQueueFlags reqFlags) const; - - const VulkanModule* m_module = nullptr; ///< Module this was all loaded from - VkInstance m_instance = VK_NULL_HANDLE; - VkDevice m_device = VK_NULL_HANDLE; - VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE; - - VkPhysicalDeviceProperties m_deviceProperties; - VkPhysicalDeviceFeatures m_deviceFeatures; - VkPhysicalDeviceMemoryProperties m_deviceMemoryProperties; -}; - -} // renderer_test -- cgit v1.2.3