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-util.h | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 tools/render-test/vk-util.h (limited to 'tools/render-test/vk-util.h') diff --git a/tools/render-test/vk-util.h b/tools/render-test/vk-util.h deleted file mode 100644 index 2d98a1c0f..000000000 --- a/tools/render-test/vk-util.h +++ /dev/null @@ -1,41 +0,0 @@ -// vk-util.h -#pragma once - -#include "vk-api.h" -#include "render.h" - -// Macros to make testing vulkan return codes simpler - -/// SLANG_VK_RETURN_ON_FAIL can be used in a similar way to SLANG_RETURN_ON_FAIL macro, except it will turn a vulkan failure into Slang::Result in the process -/// Calls handleFail which on debug builds asserts -#define SLANG_VK_RETURN_ON_FAIL(x) { VkResult _res = x; if (_res != VK_SUCCESS) { return VulkanUtil::handleFail(_res); } } - -#define SLANG_VK_RETURN_NULL_ON_FAIL(x) { VkResult _res = x; if (_res != VK_SUCCESS) { VulkanUtil::handleFail(_res); return nullptr; } } - -/// Is similar to SLANG_VK_RETURN_ON_FAIL, but does not return. Will call checkFail on failure - which asserts on debug builds. -#define SLANG_VK_CHECK(x) { VkResult _res = x; if (_res != VK_SUCCESS) { VulkanUtil::checkFail(_res); } } - -namespace renderer_test { - -// Utility functions for Vulkan -struct VulkanUtil -{ - /// Get the equivalent VkFormat from the format - /// Returns VK_FORMAT_UNDEFINED if a match is not found - static VkFormat getVkFormat(Format format); - - /// Called by SLANG_VK_RETURN_FAIL if a res is a failure. - /// On debug builds this will cause an assertion on failure. - static Slang::Result handleFail(VkResult res); - /// Called when a failure has occurred with SLANG_VK_CHECK - will typically assert. - static void checkFail(VkResult res); - - /// Get the VkPrimitiveTopology for the given topology. - /// Returns VK_PRIMITIVE_TOPOLOGY_MAX_ENUM on failure - static VkPrimitiveTopology getVkPrimitiveTopology(PrimitiveTopology topology); - - /// Returns Slang::Result equivalent of a VkResult - static Slang::Result toSlangResult(VkResult res); -}; - -} // renderer_test -- cgit v1.2.3