summaryrefslogtreecommitdiff
path: root/tools/render-test/vk-device-queue.h
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-device-queue.h
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-device-queue.h')
-rw-r--r--tools/render-test/vk-device-queue.h94
1 files changed, 0 insertions, 94 deletions
diff --git a/tools/render-test/vk-device-queue.h b/tools/render-test/vk-device-queue.h
deleted file mode 100644
index 8381f5166..000000000
--- a/tools/render-test/vk-device-queue.h
+++ /dev/null
@@ -1,94 +0,0 @@
-// vk-swap-chain.h
-#pragma once
-
-#include "vk-api.h"
-
-namespace renderer_test {
-
-struct VulkanDeviceQueue
-{
- enum
- {
- kMaxCommandBuffers = 8,
- };
-
- enum class EventType
- {
- BeginFrame,
- EndFrame,
- CountOf,
- };
-
- /// Initialize - must be called before anything else can be done
- SlangResult init(const VulkanApi& api, VkQueue queue, int queueIndex);
-
- /// Flushes the current command list, and steps to next (internally this is equivalent to a stepA followed by stepB)
- void flush();
- /// Performs a full flush, and then waits for idle.
- void flushAndWait();
-
- /// Blocks until all work submitted to GPU has completed
- void waitForIdle() { m_api->vkQueueWaitIdle(m_queue); }
-
- /// Get the graphics queue index (as set on init)
- int getQueueIndex() const { return m_queueIndex; }
-
- /// Make the specified event 'current' - meaning it's semaphore must be waited on
- VkSemaphore makeCurrent(EventType eventType);
- /// Makes the event no longer required to be waited on
- void makeCompleted(EventType eventType);
- /// Returns true if the event is already current
- SLANG_FORCE_INLINE bool isCurrent(EventType eventType) const { return m_currentSemaphores[int(eventType)] != VK_NULL_HANDLE; }
-
- /// Get the command buffer
- VkCommandBuffer getCommandBuffer() const { return m_commandBuffer; }
-
- /// Get the queue
- VkQueue getQueue() const { return m_queue; }
-
- /// Get the API
- const VulkanApi* getApi() const { return m_api; }
-
- /// Flushes the current command list
- void flushStepA();
- /// Steps to next command buffer and opens. May block if command buffer is still in use
- void flushStepB();
-
- /// Dtor
- ~VulkanDeviceQueue();
-
- protected:
-
- struct Fence
- {
- VkFence fence;
- bool active;
- uint64_t value;
- };
-
- void _updateFenceAtIndex(int fenceIndex, bool blocking);
-
- VkQueue m_queue = VK_NULL_HANDLE;
-
- VkCommandPool m_commandPool = VK_NULL_HANDLE;
- int m_numCommandBuffers = 0;
- int m_commandBufferIndex = 0;
- // There are the same amount of command buffers as fences
- VkCommandBuffer m_commandBuffers[kMaxCommandBuffers] = { VK_NULL_HANDLE };
-
- Fence m_fences[kMaxCommandBuffers] = { {VK_NULL_HANDLE, 0, 0u} };
-
- VkCommandBuffer m_commandBuffer = VK_NULL_HANDLE;
-
- VkSemaphore m_semaphores[int(EventType::CountOf)];
- VkSemaphore m_currentSemaphores[int(EventType::CountOf)];
-
- uint64_t m_lastFenceCompleted = 1;
- uint64_t m_nextFenceValue = 2;
-
- int m_queueIndex = 0;
-
- const VulkanApi* m_api = nullptr;
-};
-
-} // renderer_test