Compare commits
3 Commits
e7d74e6b0f
...
fd9ceae67d
| Author | SHA1 | Date |
|---|---|---|
|
|
fd9ceae67d | |
|
|
9115b97bc2 | |
|
|
9fe2815ab4 |
|
|
@ -613,3 +613,4 @@ $RECYCLE.BIN/
|
||||||
# Windows shortcuts
|
# Windows shortcuts
|
||||||
*.lnk
|
*.lnk
|
||||||
|
|
||||||
|
*.spv
|
||||||
|
|
|
||||||
75
AppState.cpp
75
AppState.cpp
|
|
@ -3,62 +3,65 @@
|
||||||
#include <SDL3/SDL_log.h>
|
#include <SDL3/SDL_log.h>
|
||||||
|
|
||||||
#include "GlobalMemory.h"
|
#include "GlobalMemory.h"
|
||||||
#include "RenderDevice.h"
|
|
||||||
#include "MiscData.h"
|
#include "MiscData.h"
|
||||||
|
#include "RenderDevice.h"
|
||||||
|
|
||||||
bool AppState::isInit() const
|
bool AppState::isInit() const
|
||||||
{
|
{
|
||||||
return window and renderDevice and renderDevice->isInit();
|
return window and renderDevice and renderDevice->isInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppState::cleanup()
|
void AppState::destroy()
|
||||||
{
|
{
|
||||||
if (!isInit()) return;
|
if ( !isInit() ) return;
|
||||||
|
|
||||||
renderDevice->waitIdle();
|
renderDevice->waitIdle();
|
||||||
|
|
||||||
Take(miscData)->cleanup(*renderDevice);
|
Take( miscData )->destroy( *renderDevice );
|
||||||
|
|
||||||
Take(renderDevice)->cleanup();
|
Take( renderDevice )->destroy();
|
||||||
SDL_DestroyWindow(Take(window));
|
SDL_DestroyWindow( Take( window ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
AppState::AppState(SDL_Window* window, RenderDevice* renderDevice, MiscData* miscData): window{ window }
|
AppState::AppState( SDL_Window* window, RenderDevice* renderDevice, MiscData* miscData )
|
||||||
, renderDevice{ renderDevice }
|
: window{ window }
|
||||||
, miscData{ miscData }
|
, renderDevice{ renderDevice }
|
||||||
|
, miscData{ miscData } {}
|
||||||
|
|
||||||
|
AppState* CreateAppState( GlobalMemory* memory, uint32_t const width, uint32_t const height )
|
||||||
{
|
{
|
||||||
}
|
SDL_Window* window = SDL_CreateWindow(
|
||||||
|
"Blaze Test",
|
||||||
|
static_cast<int>(width),
|
||||||
|
static_cast<int>(height),
|
||||||
|
SDL_WINDOW_VULKAN );
|
||||||
|
if ( !window )
|
||||||
|
{
|
||||||
|
SDL_LogError( SDL_LOG_CATEGORY_APPLICATION, "%s", SDL_GetError() );
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
AppState* CreateAppState(GlobalMemory* memory, uint32_t const width, uint32_t const height)
|
auto state = memory->getState();
|
||||||
{
|
RenderDevice* renderDevice = CreateRenderDevice( memory, { .window = window } );
|
||||||
SDL_Window* window = SDL_CreateWindow("Blaze Test", static_cast<int>(width), static_cast<int>(height), SDL_WINDOW_VULKAN);
|
if ( !renderDevice->isInit() )
|
||||||
if (!window)
|
{
|
||||||
{
|
SDL_LogError( SDL_LOG_CATEGORY_APPLICATION, "RenderDevice failed to init" );
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", SDL_GetError());
|
return nullptr;
|
||||||
return nullptr;
|
}
|
||||||
}
|
(void)state;
|
||||||
|
|
||||||
auto state = memory->getState();
|
auto* miscDataAllocation = memory->allocate( sizeof( MiscData ) );
|
||||||
RenderDevice* renderDevice = CreateRenderDevice(memory, { .window = window });
|
|
||||||
if (!renderDevice->isInit())
|
|
||||||
{
|
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "RenderDevice failed to init");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
(void)state;
|
|
||||||
|
|
||||||
auto* miscDataAllocation = memory->allocate(sizeof(MiscData));
|
MiscData* miscData = new( miscDataAllocation ) MiscData{};
|
||||||
|
miscData->init( *renderDevice );
|
||||||
|
|
||||||
MiscData* miscData = new (miscDataAllocation) MiscData{};
|
auto* allocation = memory->allocate( sizeof( AppState ) );
|
||||||
miscData->init(*renderDevice);
|
AppState* appState = new( allocation ) AppState{ window, renderDevice, miscData };
|
||||||
|
|
||||||
auto* allocation = memory->allocate(sizeof(AppState));
|
return appState;
|
||||||
AppState* appState = new (allocation) AppState{ window, renderDevice, miscData };
|
|
||||||
|
|
||||||
return appState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AppState::~AppState()
|
AppState::~AppState()
|
||||||
{
|
{
|
||||||
cleanup();
|
ASSERT( !isInit() );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
AppState.h
28
AppState.h
|
|
@ -2,29 +2,31 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
struct GlobalMemory;
|
|
||||||
struct SDL_Window;
|
struct SDL_Window;
|
||||||
|
|
||||||
|
struct GlobalMemory;
|
||||||
struct RenderDevice;
|
struct RenderDevice;
|
||||||
struct MiscData;
|
struct MiscData;
|
||||||
|
|
||||||
struct AppState
|
struct AppState
|
||||||
{
|
{
|
||||||
SDL_Window* window;
|
SDL_Window* window;
|
||||||
RenderDevice* renderDevice;
|
RenderDevice* renderDevice;
|
||||||
MiscData* miscData;
|
MiscData* miscData;
|
||||||
|
|
||||||
[[nodiscard]] bool isInit() const;
|
[[nodiscard]]
|
||||||
void cleanup();
|
bool isInit() const;
|
||||||
|
void destroy();
|
||||||
|
|
||||||
AppState(SDL_Window* window, RenderDevice* renderDevice, MiscData* miscData);
|
AppState( SDL_Window* window, RenderDevice* renderDevice, MiscData* miscData );
|
||||||
|
|
||||||
AppState(AppState const& other) = delete;
|
AppState( AppState const& other ) = delete;
|
||||||
AppState(AppState&& other) noexcept = delete;
|
AppState( AppState&& other ) noexcept = delete;
|
||||||
|
|
||||||
AppState& operator=(AppState const& other) = delete;
|
AppState& operator=( AppState const& other ) = delete;
|
||||||
AppState& operator=(AppState&& other) noexcept = delete;
|
AppState& operator=( AppState&& other ) noexcept = delete;
|
||||||
|
|
||||||
~AppState();
|
~AppState();
|
||||||
};
|
};
|
||||||
|
|
||||||
AppState* CreateAppState(GlobalMemory* memory, uint32_t const width, uint32_t const height);
|
AppState* CreateAppState( GlobalMemory* memory, uint32_t const width, uint32_t const height );
|
||||||
|
|
|
||||||
301
Blaze.cpp
301
Blaze.cpp
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#define SDL_MAIN_USE_CALLBACKS 1
|
#define SDL_MAIN_USE_CALLBACKS 1
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3/SDL_main.h>
|
#include <SDL3/SDL_main.h>
|
||||||
#include <SDL3/SDL_filesystem.h>
|
#include <SDL3/SDL_filesystem.h>
|
||||||
|
|
@ -23,187 +24,223 @@
|
||||||
#include "RenderDevice.h"
|
#include "RenderDevice.h"
|
||||||
#include "MiscData.h"
|
#include "MiscData.h"
|
||||||
|
|
||||||
constexpr uint32_t WIDTH = 1280;
|
constexpr uint32_t WIDTH = 1280;
|
||||||
constexpr uint32_t HEIGHT = 720;
|
constexpr uint32_t HEIGHT = 720;
|
||||||
constexpr uint32_t NUM_FRAMES = 3;
|
constexpr uint32_t NUM_FRAMES = 3;
|
||||||
|
|
||||||
using Byte = uint8_t;
|
using Byte = uint8_t;
|
||||||
|
|
||||||
constexpr size_t operator ""_KiB(size_t const value)
|
constexpr size_t operator ""_KiB( size_t const value )
|
||||||
{
|
{
|
||||||
return value * 1024;
|
return value * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr size_t operator ""_MiB(size_t const value)
|
constexpr size_t operator ""_MiB( size_t const value )
|
||||||
{
|
{
|
||||||
return value * 1024_KiB;
|
return value * 1024_KiB;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr size_t operator ""_GiB(size_t const value)
|
constexpr size_t operator ""_GiB( size_t const value )
|
||||||
{
|
{
|
||||||
return value * 1024_MiB;
|
return value * 1024_MiB;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Blaze::Global
|
namespace Blaze::Global
|
||||||
{
|
{
|
||||||
GlobalMemory g_Memory;
|
GlobalMemory g_Memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_AppResult SDL_AppInit(void** pAppState, int, char**)
|
SDL_AppResult SDL_AppInit( void** pAppState, int, char** )
|
||||||
{
|
{
|
||||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
|
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_EVENTS );
|
||||||
|
|
||||||
Blaze::Global::g_Memory.init(128_MiB);
|
Blaze::Global::g_Memory.init( 128_MiB );
|
||||||
|
|
||||||
*pAppState = CreateAppState(&Blaze::Global::g_Memory, WIDTH, HEIGHT);
|
*pAppState = CreateAppState( &Blaze::Global::g_Memory, WIDTH, HEIGHT );
|
||||||
if (!*pAppState)
|
if ( !*pAppState ) return SDL_APP_FAILURE;
|
||||||
return SDL_APP_FAILURE;
|
|
||||||
|
|
||||||
AppState& appState = *static_cast<AppState*>(*pAppState);
|
AppState& appState = *static_cast<AppState*>(*pAppState);
|
||||||
|
|
||||||
if (!appState.isInit())
|
if ( !appState.isInit() )
|
||||||
{
|
{
|
||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SDL_APP_CONTINUE;
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_AppResult SDL_AppIterate(void* appstate)
|
char g_buf[1000];
|
||||||
|
|
||||||
|
SDL_AppResult SDL_AppIterate( void* appstate )
|
||||||
{
|
{
|
||||||
AppState& appState = *static_cast<AppState*>(appstate);
|
AppState& appState = *static_cast<AppState*>(appstate);
|
||||||
RenderDevice& renderDevice = *appState.renderDevice;
|
RenderDevice& renderDevice = *appState.renderDevice;
|
||||||
MiscData& misc = *appState.miscData;
|
MiscData& misc = *appState.miscData;
|
||||||
Frame& currentFrame = renderDevice.frames[renderDevice.frameIndex];
|
Frame& currentFrame = renderDevice.frames[renderDevice.frameIndex];
|
||||||
|
|
||||||
VK_CHECK(vkWaitForFences(renderDevice.device, 1, ¤tFrame.frameReadyToReuse, VK_TRUE, std::numeric_limits<uint32_t>::max()));
|
VK_CHECK(
|
||||||
// All resources of frame 'frameIndex' are free.
|
vkWaitForFences(renderDevice.device,
|
||||||
|
1,
|
||||||
|
¤tFrame.frameReadyToReuse,
|
||||||
|
VK_TRUE,
|
||||||
|
std::numeric_limits<uint32_t>::max()) );
|
||||||
|
// All resources of frame 'frameIndex' are free.
|
||||||
|
|
||||||
uint32_t currentImageIndex;
|
uint64_t const previousCounter = misc.previousCounter;
|
||||||
VK_CHECK(vkAcquireNextImageKHR(renderDevice.device, renderDevice.swapchain, std::numeric_limits<uint32_t>::max(), currentFrame.imageAcquiredSemaphore, nullptr, ¤tImageIndex));
|
uint64_t const currentCounter = SDL_GetPerformanceCounter();
|
||||||
|
uint64_t const deltaCount = currentCounter - previousCounter;
|
||||||
|
uint64_t const perfFreq = SDL_GetPerformanceFrequency();
|
||||||
|
double const deltaTime = static_cast<double>(deltaCount) / static_cast<double>(perfFreq);
|
||||||
|
misc.previousCounter = currentCounter;
|
||||||
|
|
||||||
VK_CHECK(vkResetFences(renderDevice.device, 1, ¤tFrame.frameReadyToReuse));
|
double deltaTimeMs = deltaTime * 1000.0;
|
||||||
VK_CHECK(vkResetCommandPool(renderDevice.device, currentFrame.commandPool, 0));
|
double fps = 1.0 / deltaTime;
|
||||||
|
auto _ = sprintf_s<1000>( g_buf, "%.2f fps %.5fms %llu -> %llu", fps, deltaTimeMs, previousCounter, currentCounter );
|
||||||
|
SDL_SetWindowTitle( appState.window, g_buf );
|
||||||
|
|
||||||
misc.acquireToRenderBarrier.image = renderDevice.swapchainImages[currentImageIndex];
|
misc.cameraData.modelMatrix = glm::rotate(
|
||||||
misc.renderToPresentBarrier.image = renderDevice.swapchainImages[currentImageIndex];
|
misc.cameraData.modelMatrix,
|
||||||
|
glm::radians( 60.0f ) * static_cast<float>(deltaTime),
|
||||||
|
glm::vec3{ 0.0f, 1.0f, 0.0f } );
|
||||||
|
memcpy( misc.cameraUniformBufferPtr, &misc.cameraData, sizeof misc.cameraData );
|
||||||
|
|
||||||
VkCommandBuffer cmd = currentFrame.commandBuffer;
|
uint32_t currentImageIndex;
|
||||||
|
VK_CHECK(
|
||||||
|
vkAcquireNextImageKHR(renderDevice.device, renderDevice.swapchain, std::numeric_limits<uint32_t>::max(),
|
||||||
|
currentFrame.imageAcquiredSemaphore, nullptr, ¤tImageIndex) );
|
||||||
|
|
||||||
VkCommandBufferBeginInfo constexpr beginInfo = {
|
VK_CHECK( vkResetFences(renderDevice.device, 1, ¤tFrame.frameReadyToReuse) );
|
||||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
VK_CHECK( vkResetCommandPool(renderDevice.device, currentFrame.commandPool, 0) );
|
||||||
.pNext = nullptr,
|
|
||||||
.flags = 0,
|
|
||||||
.pInheritanceInfo = nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkClearColorValue constexpr static BLACK_CLEAR = {
|
misc.acquireToRenderBarrier.image = renderDevice.swapchainImages[currentImageIndex];
|
||||||
.float32 = { 0.0f, 0.0f, 0.0f, 1.0f },
|
misc.renderToPresentBarrier.image = renderDevice.swapchainImages[currentImageIndex];
|
||||||
};
|
|
||||||
|
|
||||||
VK_CHECK(vkBeginCommandBuffer(cmd, &beginInfo));
|
VkCommandBuffer cmd = currentFrame.commandBuffer;
|
||||||
{
|
|
||||||
VkRenderingAttachmentInfo const attachmentInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO,
|
|
||||||
.pNext = nullptr,
|
|
||||||
.imageView = renderDevice.swapchainViews[currentImageIndex],
|
|
||||||
.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
|
||||||
.resolveMode = VK_RESOLVE_MODE_NONE,
|
|
||||||
.resolveImageView = nullptr,
|
|
||||||
.resolveImageLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
|
||||||
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
|
|
||||||
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
|
||||||
.clearValue = {.color = BLACK_CLEAR},
|
|
||||||
};
|
|
||||||
|
|
||||||
VkRenderingInfo renderingInfo = {
|
VkCommandBufferBeginInfo constexpr beginInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_RENDERING_INFO,
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.renderArea = {.offset = {0,0}, .extent = renderDevice.swapchainExtent},
|
.pInheritanceInfo = nullptr,
|
||||||
.layerCount = 1,
|
};
|
||||||
.viewMask = 0,
|
|
||||||
.colorAttachmentCount = 1,
|
|
||||||
.pColorAttachments = &attachmentInfo,
|
|
||||||
.pDepthAttachment = nullptr,
|
|
||||||
.pStencilAttachment = nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
vkCmdPipelineBarrier2(cmd, &misc.acquireToRenderDependency);
|
VkClearColorValue constexpr static BLACK_CLEAR = {
|
||||||
vkCmdBeginRendering(cmd, &renderingInfo);
|
.float32 = { 0.0f, 0.0f, 0.0f, 1.0f },
|
||||||
{
|
};
|
||||||
VkViewport viewport = {
|
|
||||||
.x = 0,
|
|
||||||
.y = static_cast<float>(renderDevice.swapchainExtent.height),
|
|
||||||
.width = static_cast<float>(renderDevice.swapchainExtent.width),
|
|
||||||
.height = -static_cast<float>(renderDevice.swapchainExtent.height),
|
|
||||||
.minDepth = 0.0f,
|
|
||||||
.maxDepth = 1.0f,
|
|
||||||
};
|
|
||||||
vkCmdSetViewport(cmd, 0, 1, &viewport);
|
|
||||||
VkRect2D scissor = {
|
|
||||||
.offset = {0, 0},
|
|
||||||
.extent = renderDevice.swapchainExtent,
|
|
||||||
};
|
|
||||||
vkCmdSetScissor(cmd, 0, 1, &scissor);
|
|
||||||
|
|
||||||
// Render Something?
|
VK_CHECK( vkBeginCommandBuffer(cmd, &beginInfo) );
|
||||||
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, misc.trianglePipeline);
|
{
|
||||||
vkCmdDraw(cmd, 3, 1, 0, 0);
|
VkRenderingAttachmentInfo const attachmentInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.imageView = renderDevice.swapchainViews[currentImageIndex],
|
||||||
|
.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||||
|
.resolveMode = VK_RESOLVE_MODE_NONE,
|
||||||
|
.resolveImageView = nullptr,
|
||||||
|
.resolveImageLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||||
|
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
|
||||||
|
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
||||||
|
.clearValue = { .color = BLACK_CLEAR },
|
||||||
|
};
|
||||||
|
|
||||||
}
|
VkRenderingInfo renderingInfo = {
|
||||||
vkCmdEndRendering(cmd);
|
.sType = VK_STRUCTURE_TYPE_RENDERING_INFO,
|
||||||
vkCmdPipelineBarrier2(cmd, &misc.renderToPresentDependency);
|
.pNext = nullptr,
|
||||||
}
|
.flags = 0,
|
||||||
VK_CHECK(vkEndCommandBuffer(cmd));
|
.renderArea = { .offset = { 0, 0 }, .extent = renderDevice.swapchainExtent },
|
||||||
|
.layerCount = 1,
|
||||||
|
.viewMask = 0,
|
||||||
|
.colorAttachmentCount = 1,
|
||||||
|
.pColorAttachments = &attachmentInfo,
|
||||||
|
.pDepthAttachment = nullptr,
|
||||||
|
.pStencilAttachment = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
vkCmdPipelineBarrier2( cmd, &misc.acquireToRenderDependency );
|
||||||
VkSubmitInfo const submitInfo = {
|
vkCmdBeginRendering( cmd, &renderingInfo );
|
||||||
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
|
{
|
||||||
.pNext = nullptr,
|
VkViewport viewport = {
|
||||||
.waitSemaphoreCount = 1,
|
.x = 0,
|
||||||
.pWaitSemaphores = ¤tFrame.imageAcquiredSemaphore,
|
.y = static_cast<float>(renderDevice.swapchainExtent.height),
|
||||||
.pWaitDstStageMask = &stageMask,
|
.width = static_cast<float>(renderDevice.swapchainExtent.width),
|
||||||
.commandBufferCount = 1,
|
.height = -static_cast<float>(renderDevice.swapchainExtent.height),
|
||||||
.pCommandBuffers = &cmd,
|
.minDepth = 0.0f,
|
||||||
.signalSemaphoreCount = 1,
|
.maxDepth = 1.0f,
|
||||||
.pSignalSemaphores = ¤tFrame.renderFinishedSemaphore,
|
};
|
||||||
};
|
vkCmdSetViewport( cmd, 0, 1, &viewport );
|
||||||
VK_CHECK(vkQueueSubmit(renderDevice.directQueue, 1, &submitInfo, currentFrame.frameReadyToReuse));
|
VkRect2D scissor = {
|
||||||
|
.offset = { 0, 0 },
|
||||||
|
.extent = renderDevice.swapchainExtent,
|
||||||
|
};
|
||||||
|
vkCmdSetScissor( cmd, 0, 1, &scissor );
|
||||||
|
|
||||||
VkPresentInfoKHR const presentInfo = {
|
// Render Something?
|
||||||
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
|
vkCmdBindPipeline( cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, misc.meshPipeline );
|
||||||
.pNext = nullptr,
|
VkDeviceSize constexpr offset = 0;
|
||||||
.waitSemaphoreCount = 1,
|
vkCmdBindVertexBuffers( cmd, 0, 1, &misc.vertexBuffer, &offset );
|
||||||
.pWaitSemaphores = ¤tFrame.renderFinishedSemaphore,
|
vkCmdBindDescriptorSets(
|
||||||
.swapchainCount = 1,
|
cmd,
|
||||||
.pSwapchains = &renderDevice.swapchain,
|
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||||
.pImageIndices = ¤tImageIndex,
|
misc.pipelineLayout,
|
||||||
.pResults = nullptr,
|
0,
|
||||||
};
|
1,
|
||||||
|
&misc.descriptorSet,
|
||||||
|
0,
|
||||||
|
nullptr );
|
||||||
|
vkCmdDraw( cmd, static_cast<uint32_t>(misc.vertices.size()), 1, 0, 0 );
|
||||||
|
}
|
||||||
|
vkCmdEndRendering( cmd );
|
||||||
|
vkCmdPipelineBarrier2( cmd, &misc.renderToPresentDependency );
|
||||||
|
}
|
||||||
|
VK_CHECK( vkEndCommandBuffer(cmd) );
|
||||||
|
|
||||||
VK_CHECK(vkQueuePresentKHR(renderDevice.directQueue, &presentInfo));
|
VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
VkSubmitInfo const submitInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.waitSemaphoreCount = 1,
|
||||||
|
.pWaitSemaphores = ¤tFrame.imageAcquiredSemaphore,
|
||||||
|
.pWaitDstStageMask = &stageMask,
|
||||||
|
.commandBufferCount = 1,
|
||||||
|
.pCommandBuffers = &cmd,
|
||||||
|
.signalSemaphoreCount = 1,
|
||||||
|
.pSignalSemaphores = ¤tFrame.renderFinishedSemaphore,
|
||||||
|
};
|
||||||
|
VK_CHECK( vkQueueSubmit(renderDevice.directQueue, 1, &submitInfo, currentFrame.frameReadyToReuse) );
|
||||||
|
|
||||||
renderDevice.frameIndex = (renderDevice.frameIndex + 1) % NUM_FRAMES;
|
VkPresentInfoKHR const presentInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.waitSemaphoreCount = 1,
|
||||||
|
.pWaitSemaphores = ¤tFrame.renderFinishedSemaphore,
|
||||||
|
.swapchainCount = 1,
|
||||||
|
.pSwapchains = &renderDevice.swapchain,
|
||||||
|
.pImageIndices = ¤tImageIndex,
|
||||||
|
.pResults = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
return SDL_APP_CONTINUE;
|
VK_CHECK( vkQueuePresentKHR(renderDevice.directQueue, &presentInfo) );
|
||||||
|
|
||||||
|
renderDevice.frameIndex = (renderDevice.frameIndex + 1) % NUM_FRAMES;
|
||||||
|
|
||||||
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_AppResult SDL_AppEvent(void*, SDL_Event* event)
|
SDL_AppResult SDL_AppEvent( void*, SDL_Event* event )
|
||||||
{
|
{
|
||||||
if (event->type == SDL_EVENT_QUIT)
|
if ( event->type == SDL_EVENT_QUIT )
|
||||||
{
|
{
|
||||||
return SDL_APP_SUCCESS;
|
return SDL_APP_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SDL_APP_CONTINUE;
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL_AppQuit(void* appstate, SDL_AppResult)
|
void SDL_AppQuit( void* appstate, SDL_AppResult )
|
||||||
{
|
{
|
||||||
AppState* appState = static_cast<AppState*> (appstate);
|
AppState* appState = static_cast<AppState*>(appstate);
|
||||||
|
|
||||||
appState->cleanup();
|
appState->destroy();
|
||||||
|
|
||||||
Blaze::Global::g_Memory.destroy();
|
Blaze::Global::g_Memory.destroy();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@
|
||||||
</SubType>
|
</SubType>
|
||||||
</None>
|
</None>
|
||||||
<None Include="README.md" />
|
<None Include="README.md" />
|
||||||
<CustomBuild Include="Triangle.slang">
|
<CustomBuild Include="Mesh.slang">
|
||||||
<FileType>Document</FileType>
|
<FileType>Document</FileType>
|
||||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">slangc %(FullPath) -profile sm_6_6 -target spirv -o %(Filename).spv</Command>
|
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">slangc %(FullPath) -profile sm_6_6 -target spirv -o %(Filename).spv</Command>
|
||||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).spv</Outputs>
|
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).spv</Outputs>
|
||||||
|
|
@ -183,7 +183,6 @@
|
||||||
<ClInclude Include="AppState.h" />
|
<ClInclude Include="AppState.h" />
|
||||||
<ClInclude Include="Frame.h" />
|
<ClInclude Include="Frame.h" />
|
||||||
<ClInclude Include="GlobalMemory.h" />
|
<ClInclude Include="GlobalMemory.h" />
|
||||||
<ClInclude Include="MemoryUtils.h" />
|
|
||||||
<ClInclude Include="MacroUtils.h" />
|
<ClInclude Include="MacroUtils.h" />
|
||||||
<ClInclude Include="MathUtil.h" />
|
<ClInclude Include="MathUtil.h" />
|
||||||
<ClInclude Include="MiscData.h" />
|
<ClInclude Include="MiscData.h" />
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<CustomBuild Include="Triangle.slang">
|
<CustomBuild Include="Mesh.slang">
|
||||||
<Filter>Shader Files</Filter>
|
<Filter>Shader Files</Filter>
|
||||||
</CustomBuild>
|
</CustomBuild>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
@ -75,9 +75,6 @@
|
||||||
<ClInclude Include="MathUtil.h">
|
<ClInclude Include="MathUtil.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="MemoryUtils.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="AppState.h">
|
<ClInclude Include="AppState.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
||||||
78
Frame.cpp
78
Frame.cpp
|
|
@ -7,58 +7,58 @@
|
||||||
|
|
||||||
bool Frame::isInit() const
|
bool Frame::isInit() const
|
||||||
{
|
{
|
||||||
return static_cast<bool>(commandPool);
|
return static_cast<bool>(commandPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
Frame::Frame(VkDevice const device, uint32_t const directQueueFamilyIndex)
|
Frame::Frame( VkDevice const device, uint32_t const directQueueFamilyIndex )
|
||||||
{
|
{
|
||||||
VkCommandPoolCreateInfo const commandPoolCreateInfo = {
|
VkCommandPoolCreateInfo const commandPoolCreateInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT,
|
.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT,
|
||||||
.queueFamilyIndex = directQueueFamilyIndex,
|
.queueFamilyIndex = directQueueFamilyIndex,
|
||||||
};
|
};
|
||||||
VK_CHECK(vkCreateCommandPool(device, &commandPoolCreateInfo, nullptr, &commandPool));
|
VK_CHECK( vkCreateCommandPool(device, &commandPoolCreateInfo, nullptr, &commandPool) );
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo const commandBufferAllocateInfo = {
|
VkCommandBufferAllocateInfo const commandBufferAllocateInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.commandPool = commandPool,
|
.commandPool = commandPool,
|
||||||
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
||||||
.commandBufferCount = 1,
|
.commandBufferCount = 1,
|
||||||
};
|
};
|
||||||
VK_CHECK(vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer));
|
VK_CHECK( vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer) );
|
||||||
|
|
||||||
VkSemaphoreCreateInfo constexpr semaphoreCreateInfo = {
|
VkSemaphoreCreateInfo constexpr semaphoreCreateInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.flags = 0
|
.flags = 0
|
||||||
};
|
};
|
||||||
VK_CHECK(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &imageAcquiredSemaphore));
|
VK_CHECK( vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &imageAcquiredSemaphore) );
|
||||||
VK_CHECK(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &renderFinishedSemaphore));
|
VK_CHECK( vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &renderFinishedSemaphore) );
|
||||||
|
|
||||||
VkFenceCreateInfo constexpr fenceCreateInfo = {
|
VkFenceCreateInfo constexpr fenceCreateInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.flags = VK_FENCE_CREATE_SIGNALED_BIT,
|
.flags = VK_FENCE_CREATE_SIGNALED_BIT,
|
||||||
};
|
};
|
||||||
VK_CHECK(vkCreateFence(device, &fenceCreateInfo, nullptr, &frameReadyToReuse));
|
VK_CHECK( vkCreateFence(device, &fenceCreateInfo, nullptr, &frameReadyToReuse) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Frame::cleanup(RenderDevice const& renderDevice)
|
void Frame::destroy( RenderDevice const& renderDevice )
|
||||||
{
|
{
|
||||||
if (!isInit()) return;
|
if ( !isInit() ) return;
|
||||||
|
|
||||||
VkDevice const device = renderDevice.device;
|
VkDevice const device = renderDevice.device;
|
||||||
|
|
||||||
vkDestroyCommandPool(device, Take(commandPool), nullptr);
|
vkDestroyCommandPool( device, Take( commandPool ), nullptr );
|
||||||
vkDestroyFence(device, Take(frameReadyToReuse), nullptr);
|
vkDestroyFence( device, Take( frameReadyToReuse ), nullptr );
|
||||||
vkDestroySemaphore(device, Take(imageAcquiredSemaphore), nullptr);
|
vkDestroySemaphore( device, Take( imageAcquiredSemaphore ), nullptr );
|
||||||
vkDestroySemaphore(device, Take(renderFinishedSemaphore), nullptr);
|
vkDestroySemaphore( device, Take( renderFinishedSemaphore ), nullptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
Frame::~Frame()
|
Frame::~Frame()
|
||||||
{
|
{
|
||||||
// Manual Cleanup Required.
|
// Manual Cleanup Required.
|
||||||
ASSERT(not isInit());
|
ASSERT( not isInit() );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
19
Frame.h
19
Frame.h
|
|
@ -7,18 +7,17 @@ struct RenderDevice;
|
||||||
|
|
||||||
struct Frame
|
struct Frame
|
||||||
{
|
{
|
||||||
VkCommandPool commandPool;
|
VkCommandPool commandPool;
|
||||||
VkCommandBuffer commandBuffer;
|
VkCommandBuffer commandBuffer;
|
||||||
VkSemaphore imageAcquiredSemaphore;
|
VkSemaphore imageAcquiredSemaphore;
|
||||||
VkSemaphore renderFinishedSemaphore;
|
VkSemaphore renderFinishedSemaphore;
|
||||||
VkFence frameReadyToReuse;
|
VkFence frameReadyToReuse;
|
||||||
|
|
||||||
[[nodiscard]] bool isInit() const;
|
[[nodiscard]] bool isInit() const;
|
||||||
|
|
||||||
Frame(VkDevice device, uint32_t directQueueFamilyIndex);
|
Frame( VkDevice device, uint32_t directQueueFamilyIndex );
|
||||||
|
|
||||||
void cleanup(RenderDevice const& renderDevice);
|
void destroy( RenderDevice const& renderDevice );
|
||||||
|
|
||||||
~Frame();
|
~Frame();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,64 +2,70 @@
|
||||||
|
|
||||||
#include <SDL3/SDL_log.h>
|
#include <SDL3/SDL_log.h>
|
||||||
|
|
||||||
void GlobalMemory::init(size_t const size)
|
void GlobalMemory::init( size_t const size )
|
||||||
{
|
{
|
||||||
memory = new Byte[size];
|
memory = new Byte[size];
|
||||||
capacity = size;
|
capacity = size;
|
||||||
available = size;
|
available = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalMemory::destroy()
|
void GlobalMemory::destroy()
|
||||||
{
|
{
|
||||||
Byte const* originalMemory = memory - (capacity - available);
|
Byte const* originalMemory = memory - (capacity - available);
|
||||||
delete[] originalMemory;
|
delete[] originalMemory;
|
||||||
memory = nullptr;
|
memory = nullptr;
|
||||||
available = 0;
|
available = 0;
|
||||||
capacity = 0;
|
capacity = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Byte* GlobalMemory::allocate(size_t const size)
|
Byte* GlobalMemory::allocate( size_t const size )
|
||||||
{
|
{
|
||||||
assert(size <= available && "No enough space available");
|
assert( size <= available && "No enough space available" );
|
||||||
|
|
||||||
Byte* retVal = memory;
|
Byte* retVal = memory;
|
||||||
memory += size;
|
memory += size;
|
||||||
available -= size;
|
available -= size;
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_SYSTEM, "ALLOC: %p -> %p (%llu) (avail: %llu)", reinterpret_cast<void*>(retVal), reinterpret_cast<void*>(memory), size, available);
|
SDL_LogInfo(
|
||||||
|
SDL_LOG_CATEGORY_SYSTEM,
|
||||||
|
"ALLOC: %p -> %p (%llu) (avail: %llu)",
|
||||||
|
reinterpret_cast<void*>(retVal),
|
||||||
|
reinterpret_cast<void*>(memory),
|
||||||
|
size,
|
||||||
|
available );
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
Byte* GlobalMemory::allocate(size_t const size, size_t const alignment)
|
Byte* GlobalMemory::allocate( size_t const size, size_t const alignment )
|
||||||
{
|
{
|
||||||
uintptr_t const addr = reinterpret_cast<uintptr_t>(memory);
|
uintptr_t const addr = reinterpret_cast<uintptr_t>(memory);
|
||||||
uintptr_t const foundOffset = addr % alignment;
|
uintptr_t const foundOffset = addr % alignment;
|
||||||
|
|
||||||
if (foundOffset == 0)
|
if ( foundOffset == 0 )
|
||||||
{
|
{
|
||||||
return allocate(size);
|
return allocate( size );
|
||||||
}
|
}
|
||||||
|
|
||||||
uintptr_t const offset = alignment - foundOffset;
|
uintptr_t const offset = alignment - foundOffset;
|
||||||
size_t const allocationSize = size + offset;
|
size_t const allocationSize = size + offset;
|
||||||
|
|
||||||
return offset + allocate(allocationSize);
|
return offset + allocate( allocationSize );
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalMemory::State GlobalMemory::getState() const
|
GlobalMemory::State GlobalMemory::getState() const
|
||||||
{
|
{
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_SYSTEM, "TEMP: %p %llu", reinterpret_cast<void*>(memory), available);
|
SDL_LogInfo( SDL_LOG_CATEGORY_SYSTEM, "TEMP: %p %llu", reinterpret_cast<void*>(memory), available );
|
||||||
return {
|
return {
|
||||||
.memory = memory,
|
.memory = memory,
|
||||||
.available = available,
|
.available = available,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalMemory::restoreState(State const& state)
|
void GlobalMemory::restoreState( State const& state )
|
||||||
{
|
{
|
||||||
assert(memory >= state.memory); //< Behind top of allocator
|
ASSERT( memory >= state.memory ); //< Behind top of allocator
|
||||||
assert(memory - (capacity - available) <= state.memory); //< Ahead of start of allocator
|
ASSERT( memory - (capacity - available) <= state.memory ); //< Ahead of start of allocator
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_SYSTEM, "RESTORE: %p %llu", reinterpret_cast<void*>(memory), available);
|
SDL_LogInfo( SDL_LOG_CATEGORY_SYSTEM, "RESTORE: %p %llu", reinterpret_cast<void*>(memory), available );
|
||||||
memory = state.memory;
|
memory = state.memory;
|
||||||
available = state.available;
|
available = state.available;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,27 +8,27 @@ using Byte = uint8_t;
|
||||||
|
|
||||||
struct GlobalMemory
|
struct GlobalMemory
|
||||||
{
|
{
|
||||||
struct State
|
struct State
|
||||||
{
|
{
|
||||||
Byte* memory;
|
Byte* memory;
|
||||||
size_t available;
|
size_t available;
|
||||||
};
|
};
|
||||||
|
|
||||||
Byte* memory;
|
Byte* memory;
|
||||||
size_t available;
|
size_t available;
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
|
|
||||||
void init(size_t const size);
|
void init( size_t size );
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
Byte* allocate(size_t const size);
|
Byte* allocate( size_t size );
|
||||||
|
|
||||||
Byte* allocate(size_t const size, size_t const alignment);
|
Byte* allocate( size_t size, size_t alignment );
|
||||||
|
|
||||||
// Do not do any permanent allocations after calling this.
|
// Do not do any permanent allocations after calling this.
|
||||||
[[nodiscard]] State getState() const;
|
[[nodiscard]] State getState() const;
|
||||||
|
|
||||||
// Call this before permanent allocations.
|
// Call this before permanent allocations.
|
||||||
void restoreState(State const& state);
|
void restoreState( State const& state );
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -26,4 +26,4 @@ do { \
|
||||||
} \
|
} \
|
||||||
} while(false)
|
} while(false)
|
||||||
|
|
||||||
#define Take(OBJ) std::exchange(OBJ, {})
|
#define Take(OBJ) std::exchange(OBJ, {})
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
template <std::totally_ordered T>
|
template < std::totally_ordered T >
|
||||||
T Clamp(T const val, T const minVal, T const maxVal)
|
T Clamp( T const val, T const minVal, T const maxVal )
|
||||||
{
|
{
|
||||||
return std::min(maxVal, std::max(val, minVal));
|
return std::min( maxVal, std::max( val, minVal ) );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <foonathan/memory/memory_arena.hpp>
|
|
||||||
#include <foonathan/memory/memory_stack.hpp>
|
|
||||||
#include <foonathan/memory/temporary_allocator.hpp>
|
|
||||||
|
|
||||||
using global_allocator_t = foonathan::memory::memory_stack<foonathan::memory::virtual_block_allocator>;
|
|
||||||
|
|
||||||
using subsystem_allocator_t = foonathan::memory::memory_stack<foonathan::memory::fixed_block_allocator<global_allocator_t>>;
|
|
||||||
using temporary_allocator_t = foonathan::memory::temporary_allocator;
|
|
||||||
|
|
@ -15,13 +15,23 @@ struct VertexOut {
|
||||||
float4 vertexColor : CoarseColor;
|
float4 vertexColor : CoarseColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CameraData {
|
||||||
|
float4x4 model;
|
||||||
|
float4x4 view;
|
||||||
|
float4x4 proj;
|
||||||
|
};
|
||||||
|
|
||||||
|
ParameterBlock<CameraData> camera;
|
||||||
|
|
||||||
[shader("vertex")]
|
[shader("vertex")]
|
||||||
VertexOut VertexMain(
|
VertexOut VertexMain(
|
||||||
uint vertexId: SV_VertexID
|
uint vertexId: SV_VertexID,
|
||||||
|
float4 position,
|
||||||
|
float4 color,
|
||||||
) {
|
) {
|
||||||
VertexOut output;
|
VertexOut output;
|
||||||
output.outPosition = vertexPos[vertexId];
|
output.outPosition = mul(camera.proj, mul(camera.view, mul(camera.model, position)));
|
||||||
output.vertexColor = vertexColors[vertexId];
|
output.vertexColor = color;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
727
MiscData.cpp
727
MiscData.cpp
|
|
@ -6,284 +6,511 @@
|
||||||
#include "MacroUtils.h"
|
#include "MacroUtils.h"
|
||||||
#include "RenderDevice.h"
|
#include "RenderDevice.h"
|
||||||
|
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
void MiscData::init(RenderDevice const& renderDevice)
|
void MiscData::init( RenderDevice const& renderDevice )
|
||||||
{
|
{
|
||||||
VkDevice const device = renderDevice.device;
|
VkDevice const device = renderDevice.device;
|
||||||
{
|
|
||||||
size_t dataSize;
|
|
||||||
void* rawData = SDL_LoadFile("Triangle.spv", &dataSize);
|
|
||||||
ASSERT(dataSize % 4 == 0);
|
|
||||||
|
|
||||||
if (not rawData)
|
previousCounter = 0;
|
||||||
{
|
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "%s", SDL_GetError());
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto data = static_cast<uint32_t const*>(rawData);
|
// Pipeline Creation
|
||||||
|
{
|
||||||
|
size_t dataSize;
|
||||||
|
void* rawData = SDL_LoadFile( "Mesh.spv", &dataSize );
|
||||||
|
ASSERT( dataSize % 4 == 0 );
|
||||||
|
|
||||||
VkShaderModuleCreateInfo const shaderModuleCreateInfo = {
|
if ( !rawData )
|
||||||
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
{
|
||||||
.pNext = nullptr,
|
SDL_LogError( SDL_LOG_CATEGORY_SYSTEM, "%s", SDL_GetError() );
|
||||||
.flags = 0,
|
abort();
|
||||||
.codeSize = dataSize,
|
}
|
||||||
.pCode = data,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkShaderModule shaderModule;
|
auto data = static_cast<uint32_t const*>(rawData);
|
||||||
VK_CHECK(vkCreateShaderModule(device, &shaderModuleCreateInfo, nullptr, &shaderModule));
|
|
||||||
|
|
||||||
VkPipelineLayoutCreateInfo constexpr pipelineLayoutCreateInfo = {
|
VkShaderModuleCreateInfo const shaderModuleCreateInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.setLayoutCount = 0,
|
.codeSize = dataSize,
|
||||||
.pSetLayouts = nullptr,
|
.pCode = data,
|
||||||
.pushConstantRangeCount = 0,
|
};
|
||||||
.pPushConstantRanges = nullptr,
|
|
||||||
};
|
|
||||||
VK_CHECK(vkCreatePipelineLayout(device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayout));
|
|
||||||
|
|
||||||
std::array stages = {
|
VkShaderModule shaderModule;
|
||||||
VkPipelineShaderStageCreateInfo{
|
VK_CHECK( vkCreateShaderModule(device, &shaderModuleCreateInfo, nullptr, &shaderModule) );
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
|
||||||
.pNext = nullptr,
|
|
||||||
.flags = 0,
|
|
||||||
.stage = VK_SHADER_STAGE_VERTEX_BIT,
|
|
||||||
.module = shaderModule,
|
|
||||||
.pName = "VertexMain",
|
|
||||||
.pSpecializationInfo = nullptr,
|
|
||||||
},
|
|
||||||
VkPipelineShaderStageCreateInfo{
|
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
|
||||||
.pNext = nullptr,
|
|
||||||
.flags = 0,
|
|
||||||
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
|
|
||||||
.module = shaderModule,
|
|
||||||
.pName = "FragmentMain",
|
|
||||||
.pSpecializationInfo = nullptr,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
VkPipelineVertexInputStateCreateInfo constexpr vertexInputState = {
|
VkDescriptorSetLayoutBinding constexpr descriptorSetLayoutBinding = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
.binding = 0,
|
||||||
.pNext = nullptr,
|
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
.flags = 0,
|
.descriptorCount = 1,
|
||||||
.vertexBindingDescriptionCount = 0,
|
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
|
||||||
.pVertexBindingDescriptions = nullptr,
|
.pImmutableSamplers = nullptr,
|
||||||
.vertexAttributeDescriptionCount = 0,
|
};
|
||||||
.pVertexAttributeDescriptions = nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkPipelineInputAssemblyStateCreateInfo constexpr inputAssembly = {
|
VkDescriptorSetLayoutCreateInfo const descriptorSetLayoutCreateInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
|
.bindingCount = 1,
|
||||||
.primitiveRestartEnable = VK_FALSE,
|
.pBindings = &descriptorSetLayoutBinding,
|
||||||
};
|
};
|
||||||
|
VK_CHECK( vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCreateInfo, nullptr, &descriptorSetLayout) );
|
||||||
|
|
||||||
VkPipelineTessellationStateCreateInfo constexpr tessellationState = {
|
VkPipelineLayoutCreateInfo const pipelineLayoutCreateInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.patchControlPoints = 0,
|
.setLayoutCount = 1,
|
||||||
};
|
.pSetLayouts = &descriptorSetLayout,
|
||||||
|
.pushConstantRangeCount = 0,
|
||||||
|
.pPushConstantRanges = nullptr,
|
||||||
|
};
|
||||||
|
VK_CHECK( vkCreatePipelineLayout(device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayout) );
|
||||||
|
|
||||||
VkPipelineViewportStateCreateInfo constexpr viewportState = {
|
std::array stages = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
VkPipelineShaderStageCreateInfo{
|
||||||
.pNext = nullptr,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||||
.flags = 0,
|
.pNext = nullptr,
|
||||||
.viewportCount = 1,
|
.flags = 0,
|
||||||
.pViewports = nullptr,
|
.stage = VK_SHADER_STAGE_VERTEX_BIT,
|
||||||
.scissorCount = 1,
|
.module = shaderModule,
|
||||||
.pScissors = nullptr,
|
.pName = "VertexMain",
|
||||||
};
|
.pSpecializationInfo = nullptr,
|
||||||
|
},
|
||||||
|
VkPipelineShaderStageCreateInfo{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||||
|
.module = shaderModule,
|
||||||
|
.pName = "FragmentMain",
|
||||||
|
.pSpecializationInfo = nullptr,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
VkPipelineRasterizationStateCreateInfo constexpr rasterizationState = {
|
VkVertexInputBindingDescription constexpr bindingDescription = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
.binding = 0,
|
||||||
.pNext = nullptr,
|
.stride = sizeof( Vertex ),
|
||||||
.flags = 0,
|
.inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
|
||||||
.depthClampEnable = VK_TRUE,
|
};
|
||||||
.rasterizerDiscardEnable = VK_FALSE,
|
|
||||||
.polygonMode = VK_POLYGON_MODE_FILL,
|
|
||||||
.cullMode = VK_CULL_MODE_NONE,
|
|
||||||
.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE,
|
|
||||||
.depthBiasEnable = VK_FALSE,
|
|
||||||
.depthBiasConstantFactor = 0.0f,
|
|
||||||
.depthBiasClamp = 0.0f,
|
|
||||||
.depthBiasSlopeFactor = 0.0f,
|
|
||||||
.lineWidth = 1.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkPipelineMultisampleStateCreateInfo constexpr multisampleState = {
|
std::array attributeDescriptions = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
VkVertexInputAttributeDescription{
|
||||||
.pNext = nullptr,
|
.location = 0,
|
||||||
.flags = 0,
|
.binding = 0,
|
||||||
.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
|
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
|
||||||
.sampleShadingEnable = VK_FALSE,
|
.offset = offsetof( Vertex, position ),
|
||||||
.minSampleShading = 0.0f,
|
},
|
||||||
.pSampleMask = nullptr,
|
VkVertexInputAttributeDescription{
|
||||||
.alphaToCoverageEnable = VK_FALSE,
|
.location = 1,
|
||||||
.alphaToOneEnable = VK_FALSE,
|
.binding = 0,
|
||||||
};
|
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
|
||||||
|
.offset = offsetof( Vertex, color ),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
VkPipelineDepthStencilStateCreateInfo constexpr depthStencilState = {
|
VkPipelineVertexInputStateCreateInfo const vertexInputState = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.depthTestEnable = VK_FALSE,
|
.vertexBindingDescriptionCount = 1,
|
||||||
.depthWriteEnable = VK_FALSE,
|
.pVertexBindingDescriptions = &bindingDescription,
|
||||||
.depthCompareOp = VK_COMPARE_OP_ALWAYS,
|
.vertexAttributeDescriptionCount = static_cast<uint32_t>(attributeDescriptions.size()),
|
||||||
.depthBoundsTestEnable = VK_FALSE,
|
.pVertexAttributeDescriptions = attributeDescriptions.data(),
|
||||||
.stencilTestEnable = VK_FALSE,
|
};
|
||||||
.front = {},
|
|
||||||
.back = {},
|
|
||||||
.minDepthBounds = 0.0f,
|
|
||||||
.maxDepthBounds = 1.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkPipelineColorBlendAttachmentState constexpr colorBlendAttachmentState = {
|
VkPipelineInputAssemblyStateCreateInfo constexpr inputAssembly = {
|
||||||
.blendEnable = VK_FALSE,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
|
||||||
.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA,
|
.pNext = nullptr,
|
||||||
.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
.flags = 0,
|
||||||
.colorBlendOp = VK_BLEND_OP_ADD,
|
.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
|
||||||
.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE,
|
.primitiveRestartEnable = VK_FALSE,
|
||||||
.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO,
|
};
|
||||||
.alphaBlendOp = VK_BLEND_OP_ADD,
|
|
||||||
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT
|
|
||||||
| VK_COLOR_COMPONENT_G_BIT
|
|
||||||
| VK_COLOR_COMPONENT_B_BIT
|
|
||||||
| VK_COLOR_COMPONENT_A_BIT,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkPipelineColorBlendStateCreateInfo const colorBlendState = {
|
VkPipelineTessellationStateCreateInfo constexpr tessellationState = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.logicOpEnable = VK_FALSE,
|
.patchControlPoints = 0,
|
||||||
.logicOp = VK_LOGIC_OP_COPY,
|
};
|
||||||
.attachmentCount = 1,
|
|
||||||
.pAttachments = &colorBlendAttachmentState,
|
|
||||||
.blendConstants = {0.0f, 0.0f, 0.0f, 0.0f},
|
|
||||||
};
|
|
||||||
|
|
||||||
std::array constexpr dynamicStates = {
|
VkPipelineViewportStateCreateInfo constexpr viewportState = {
|
||||||
VK_DYNAMIC_STATE_VIEWPORT,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
||||||
VK_DYNAMIC_STATE_SCISSOR
|
.pNext = nullptr,
|
||||||
};
|
.flags = 0,
|
||||||
|
.viewportCount = 1,
|
||||||
|
.pViewports = nullptr,
|
||||||
|
.scissorCount = 1,
|
||||||
|
.pScissors = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
VkPipelineDynamicStateCreateInfo const dynamicStateCreateInfo = {
|
VkPipelineRasterizationStateCreateInfo constexpr rasterizationState = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.dynamicStateCount = static_cast<uint32_t>(dynamicStates.size()),
|
.depthClampEnable = VK_TRUE,
|
||||||
.pDynamicStates = dynamicStates.data()
|
.rasterizerDiscardEnable = VK_FALSE,
|
||||||
};
|
.polygonMode = VK_POLYGON_MODE_FILL,
|
||||||
|
.cullMode = VK_CULL_MODE_NONE,
|
||||||
|
.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE,
|
||||||
|
.depthBiasEnable = VK_FALSE,
|
||||||
|
.depthBiasConstantFactor = 0.0f,
|
||||||
|
.depthBiasClamp = 0.0f,
|
||||||
|
.depthBiasSlopeFactor = 0.0f,
|
||||||
|
.lineWidth = 1.0f,
|
||||||
|
};
|
||||||
|
|
||||||
VkPipelineRenderingCreateInfoKHR const renderingCreateInfo = {
|
VkPipelineMultisampleStateCreateInfo constexpr multisampleState = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
||||||
.colorAttachmentCount = 1,
|
.pNext = nullptr,
|
||||||
.pColorAttachmentFormats = &renderDevice.swapchainFormat,
|
.flags = 0,
|
||||||
};
|
.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
|
||||||
|
.sampleShadingEnable = VK_FALSE,
|
||||||
|
.minSampleShading = 0.0f,
|
||||||
|
.pSampleMask = nullptr,
|
||||||
|
.alphaToCoverageEnable = VK_FALSE,
|
||||||
|
.alphaToOneEnable = VK_FALSE,
|
||||||
|
};
|
||||||
|
|
||||||
VkGraphicsPipelineCreateInfo const graphicsPipelineCreateInfo = {
|
VkPipelineDepthStencilStateCreateInfo constexpr depthStencilState = {
|
||||||
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
|
||||||
.pNext = &renderingCreateInfo,
|
.pNext = nullptr,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.stageCount = static_cast<uint32_t>(stages.size()),
|
.depthTestEnable = VK_FALSE,
|
||||||
.pStages = stages.data(),
|
.depthWriteEnable = VK_FALSE,
|
||||||
.pVertexInputState = &vertexInputState,
|
.depthCompareOp = VK_COMPARE_OP_ALWAYS,
|
||||||
.pInputAssemblyState = &inputAssembly,
|
.depthBoundsTestEnable = VK_FALSE,
|
||||||
.pTessellationState = &tessellationState,
|
.stencilTestEnable = VK_FALSE,
|
||||||
.pViewportState = &viewportState,
|
.front = {},
|
||||||
.pRasterizationState = &rasterizationState,
|
.back = {},
|
||||||
.pMultisampleState = &multisampleState,
|
.minDepthBounds = 0.0f,
|
||||||
.pDepthStencilState = &depthStencilState,
|
.maxDepthBounds = 1.0f,
|
||||||
.pColorBlendState = &colorBlendState,
|
};
|
||||||
.pDynamicState = &dynamicStateCreateInfo,
|
|
||||||
.layout = pipelineLayout,
|
|
||||||
.renderPass = nullptr,
|
|
||||||
.subpass = 0,
|
|
||||||
.basePipelineHandle = nullptr,
|
|
||||||
.basePipelineIndex = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
VK_CHECK(vkCreateGraphicsPipelines(device, nullptr, 1, &graphicsPipelineCreateInfo, nullptr, &trianglePipeline));
|
VkPipelineColorBlendAttachmentState constexpr colorBlendAttachmentState = {
|
||||||
|
.blendEnable = VK_FALSE,
|
||||||
|
.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA,
|
||||||
|
.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
||||||
|
.colorBlendOp = VK_BLEND_OP_ADD,
|
||||||
|
.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE,
|
||||||
|
.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO,
|
||||||
|
.alphaBlendOp = VK_BLEND_OP_ADD,
|
||||||
|
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT
|
||||||
|
| VK_COLOR_COMPONENT_G_BIT
|
||||||
|
| VK_COLOR_COMPONENT_B_BIT
|
||||||
|
| VK_COLOR_COMPONENT_A_BIT,
|
||||||
|
};
|
||||||
|
|
||||||
vkDestroyShaderModule(device, shaderModule, nullptr);
|
VkPipelineColorBlendStateCreateInfo const colorBlendState = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.logicOpEnable = VK_FALSE,
|
||||||
|
.logicOp = VK_LOGIC_OP_COPY,
|
||||||
|
.attachmentCount = 1,
|
||||||
|
.pAttachments = &colorBlendAttachmentState,
|
||||||
|
.blendConstants = { 0.0f, 0.0f, 0.0f, 0.0f },
|
||||||
|
};
|
||||||
|
|
||||||
SDL_free(rawData);
|
std::array constexpr dynamicStates = {
|
||||||
}
|
VK_DYNAMIC_STATE_VIEWPORT,
|
||||||
|
VK_DYNAMIC_STATE_SCISSOR
|
||||||
|
};
|
||||||
|
|
||||||
acquireToRenderBarrier = {
|
VkPipelineDynamicStateCreateInfo const dynamicStateCreateInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.srcStageMask = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT,
|
.flags = 0,
|
||||||
.srcAccessMask = VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT,
|
.dynamicStateCount = static_cast<uint32_t>(dynamicStates.size()),
|
||||||
.dstStageMask = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT,
|
.pDynamicStates = dynamicStates.data()
|
||||||
.dstAccessMask = VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT,
|
};
|
||||||
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
|
||||||
.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
|
||||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
|
||||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
|
||||||
.subresourceRange = {
|
|
||||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
|
||||||
.baseMipLevel = 0,
|
|
||||||
.levelCount = 1,
|
|
||||||
.baseArrayLayer = 0,
|
|
||||||
.layerCount = 1,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
acquireToRenderDependency = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
|
|
||||||
.pNext = nullptr,
|
|
||||||
.dependencyFlags = 0,
|
|
||||||
.memoryBarrierCount = 0,
|
|
||||||
.pMemoryBarriers = nullptr,
|
|
||||||
.bufferMemoryBarrierCount = 0,
|
|
||||||
.pBufferMemoryBarriers = nullptr,
|
|
||||||
.imageMemoryBarrierCount = 1,
|
|
||||||
.pImageMemoryBarriers = &acquireToRenderBarrier,
|
|
||||||
};
|
|
||||||
|
|
||||||
renderToPresentBarrier = {
|
VkPipelineRenderingCreateInfoKHR const renderingCreateInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR,
|
||||||
.pNext = nullptr,
|
.colorAttachmentCount = 1,
|
||||||
.srcStageMask = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT,
|
.pColorAttachmentFormats = &renderDevice.swapchainFormat,
|
||||||
.srcAccessMask = VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT,
|
};
|
||||||
.dstStageMask = VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT,
|
|
||||||
.dstAccessMask = VK_ACCESS_2_NONE,
|
VkGraphicsPipelineCreateInfo const graphicsPipelineCreateInfo = {
|
||||||
.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||||
.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
.pNext = &renderingCreateInfo,
|
||||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
.flags = 0,
|
||||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
.stageCount = static_cast<uint32_t>(stages.size()),
|
||||||
.subresourceRange = {
|
.pStages = stages.data(),
|
||||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
.pVertexInputState = &vertexInputState,
|
||||||
.baseMipLevel = 0,
|
.pInputAssemblyState = &inputAssembly,
|
||||||
.levelCount = 1,
|
.pTessellationState = &tessellationState,
|
||||||
.baseArrayLayer = 0,
|
.pViewportState = &viewportState,
|
||||||
.layerCount = 1,
|
.pRasterizationState = &rasterizationState,
|
||||||
}
|
.pMultisampleState = &multisampleState,
|
||||||
};
|
.pDepthStencilState = &depthStencilState,
|
||||||
renderToPresentDependency = {
|
.pColorBlendState = &colorBlendState,
|
||||||
.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
|
.pDynamicState = &dynamicStateCreateInfo,
|
||||||
.pNext = nullptr,
|
.layout = pipelineLayout,
|
||||||
.dependencyFlags = 0,
|
.renderPass = nullptr,
|
||||||
.memoryBarrierCount = 0,
|
.subpass = 0,
|
||||||
.pMemoryBarriers = nullptr,
|
.basePipelineHandle = nullptr,
|
||||||
.bufferMemoryBarrierCount = 0,
|
.basePipelineIndex = 0,
|
||||||
.pBufferMemoryBarriers = nullptr,
|
};
|
||||||
.imageMemoryBarrierCount = 1,
|
|
||||||
.pImageMemoryBarriers = &renderToPresentBarrier,
|
VK_CHECK( vkCreateGraphicsPipelines(device, nullptr, 1, &graphicsPipelineCreateInfo, nullptr, &meshPipeline) );
|
||||||
};
|
|
||||||
|
vkDestroyShaderModule( device, shaderModule, nullptr );
|
||||||
|
|
||||||
|
SDL_free( rawData );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vertex Buffer Creation
|
||||||
|
{
|
||||||
|
vertexBufferSize = sizeof vertices[0] * vertices.size();
|
||||||
|
|
||||||
|
// TL----TR
|
||||||
|
// | \ |
|
||||||
|
// | \ |
|
||||||
|
// | \ |
|
||||||
|
// BL----BR
|
||||||
|
//
|
||||||
|
// BL -> BR -> TL
|
||||||
|
// TL -> BR -> TR
|
||||||
|
|
||||||
|
vertices = std::array{
|
||||||
|
// Bottom Left
|
||||||
|
Vertex{
|
||||||
|
.position = { -1.0f, -1.0f, 0.0f, 1.0f },
|
||||||
|
.color = { 0.0f, 0.0f, 1.0f, 1.0f },
|
||||||
|
},
|
||||||
|
// Bottom Right
|
||||||
|
Vertex{
|
||||||
|
.position = { 1.0f, -1.0f, 0.0f, 1.0f },
|
||||||
|
.color = { 1.0f, 0.0f, 0.0f, 1.0f },
|
||||||
|
},
|
||||||
|
// Top Left
|
||||||
|
Vertex{
|
||||||
|
.position = { -1.0f, 1.0f, 0.0f, 1.0f },
|
||||||
|
.color = { 0.0f, 1.0f, 0.0f, 1.0f },
|
||||||
|
},
|
||||||
|
// Top Right
|
||||||
|
Vertex{
|
||||||
|
.position = { 1.0f, 1.0f, 0.0f, 1.0f },
|
||||||
|
.color = { 1.0f, 1.0f, 0.0f, 1.0f },
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
VkBufferCreateInfo const bufferCreateInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.size = vertexBufferSize,
|
||||||
|
.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
||||||
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||||
|
.queueFamilyIndexCount = 0,
|
||||||
|
.pQueueFamilyIndices = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
|
VmaAllocationCreateInfo constexpr allocationCreateInfo = {
|
||||||
|
.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT |
|
||||||
|
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
|
||||||
|
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||||
|
.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
|
||||||
|
.preferredFlags = 0,
|
||||||
|
.memoryTypeBits = 0,
|
||||||
|
.pool = nullptr,
|
||||||
|
.pUserData = nullptr,
|
||||||
|
.priority = 1.0f,
|
||||||
|
};
|
||||||
|
|
||||||
|
VmaAllocationInfo allocationInfo;
|
||||||
|
|
||||||
|
VK_CHECK(
|
||||||
|
vmaCreateBuffer(
|
||||||
|
renderDevice.gpuAllocator,
|
||||||
|
&bufferCreateInfo,
|
||||||
|
&allocationCreateInfo,
|
||||||
|
&vertexBuffer,
|
||||||
|
&vertexBufferAllocation,
|
||||||
|
&allocationInfo) );
|
||||||
|
|
||||||
|
if ( allocationInfo.pMappedData )
|
||||||
|
{
|
||||||
|
memcpy( allocationInfo.pMappedData, vertices.data(), vertices.size() * sizeof vertices[0] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Camera
|
||||||
|
{
|
||||||
|
cameraPosition = glm::vec3{ 0.0f, 0.0f, -5.0f };
|
||||||
|
cameraTarget = glm::vec3{ 0.0f, 0.0f, 0.0f };
|
||||||
|
cameraData.modelMatrix = glm::mat4{ 1.0f };
|
||||||
|
cameraData.viewMatrix = glm::lookAt( cameraPosition, cameraTarget, glm::vec3{ 0.0f, 1.0f, 0.0f } );
|
||||||
|
cameraData.projectionMatrix = glm::perspective( glm::radians( 70.0f ), 16.0f / 9.0f, 0.1f, 1000.0f );
|
||||||
|
|
||||||
|
cameraUniformBufferSize = sizeof( CameraData );
|
||||||
|
|
||||||
|
VkBufferCreateInfo const bufferCreateInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.size = cameraUniformBufferSize,
|
||||||
|
.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
||||||
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||||
|
.queueFamilyIndexCount = 0,
|
||||||
|
.pQueueFamilyIndices = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
|
VmaAllocationCreateInfo constexpr allocationCreateInfo = {
|
||||||
|
.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT |
|
||||||
|
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
|
||||||
|
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||||
|
.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
|
||||||
|
.preferredFlags = 0,
|
||||||
|
.memoryTypeBits = 0,
|
||||||
|
.pool = nullptr,
|
||||||
|
.pUserData = nullptr,
|
||||||
|
.priority = 1.0f,
|
||||||
|
};
|
||||||
|
|
||||||
|
VmaAllocationInfo allocationInfo;
|
||||||
|
|
||||||
|
VK_CHECK(
|
||||||
|
vmaCreateBuffer(
|
||||||
|
renderDevice.gpuAllocator,
|
||||||
|
&bufferCreateInfo,
|
||||||
|
&allocationCreateInfo,
|
||||||
|
&cameraUniformBuffer,
|
||||||
|
&cameraUniformBufferAllocation,
|
||||||
|
&allocationInfo) );
|
||||||
|
|
||||||
|
if ( allocationInfo.pMappedData )
|
||||||
|
{
|
||||||
|
memcpy( allocationInfo.pMappedData, &cameraData, sizeof cameraData );
|
||||||
|
cameraUniformBufferPtr = static_cast<uint8_t*>(allocationInfo.pMappedData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Descriptors
|
||||||
|
{
|
||||||
|
VkDescriptorPoolSize const poolSize = {
|
||||||
|
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
|
.descriptorCount = renderDevice.getNumFrames(),
|
||||||
|
};
|
||||||
|
VkDescriptorPoolCreateInfo const descriptorPoolCreateInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.maxSets = renderDevice.getNumFrames(),
|
||||||
|
.poolSizeCount = 1,
|
||||||
|
.pPoolSizes = &poolSize,
|
||||||
|
};
|
||||||
|
|
||||||
|
VK_CHECK( vkCreateDescriptorPool(device, &descriptorPoolCreateInfo, nullptr, &descriptorPool) );
|
||||||
|
|
||||||
|
VkDescriptorSetAllocateInfo const descriptorSetAllocateInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.descriptorPool = descriptorPool,
|
||||||
|
.descriptorSetCount = 1,
|
||||||
|
.pSetLayouts = &descriptorSetLayout,
|
||||||
|
};
|
||||||
|
|
||||||
|
VK_CHECK( vkAllocateDescriptorSets(device, &descriptorSetAllocateInfo, &descriptorSet) );
|
||||||
|
|
||||||
|
VkDescriptorBufferInfo const descriptorBufferInfo = {
|
||||||
|
.buffer = cameraUniformBuffer,
|
||||||
|
.offset = 0,
|
||||||
|
.range = sizeof CameraData,
|
||||||
|
};
|
||||||
|
|
||||||
|
VkWriteDescriptorSet writeDescriptorSet = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.dstSet = descriptorSet,
|
||||||
|
.dstBinding = 0,
|
||||||
|
.dstArrayElement = 0,
|
||||||
|
.descriptorCount = 1,
|
||||||
|
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
|
.pImageInfo = nullptr,
|
||||||
|
.pBufferInfo = &descriptorBufferInfo,
|
||||||
|
.pTexelBufferView = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
|
vkUpdateDescriptorSets( device, 1, &writeDescriptorSet, 0, nullptr );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Barrier Creation
|
||||||
|
{
|
||||||
|
acquireToRenderBarrier = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.srcStageMask = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT,
|
||||||
|
.srcAccessMask = VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT,
|
||||||
|
.dstStageMask = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT,
|
||||||
|
.dstAccessMask = VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT,
|
||||||
|
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||||
|
.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||||
|
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||||
|
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||||
|
.subresourceRange = {
|
||||||
|
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
|
.baseMipLevel = 0,
|
||||||
|
.levelCount = 1,
|
||||||
|
.baseArrayLayer = 0,
|
||||||
|
.layerCount = 1,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
acquireToRenderDependency = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.dependencyFlags = 0,
|
||||||
|
.memoryBarrierCount = 0,
|
||||||
|
.pMemoryBarriers = nullptr,
|
||||||
|
.bufferMemoryBarrierCount = 0,
|
||||||
|
.pBufferMemoryBarriers = nullptr,
|
||||||
|
.imageMemoryBarrierCount = 1,
|
||||||
|
.pImageMemoryBarriers = &acquireToRenderBarrier,
|
||||||
|
};
|
||||||
|
|
||||||
|
renderToPresentBarrier = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.srcStageMask = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT,
|
||||||
|
.srcAccessMask = VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT,
|
||||||
|
.dstStageMask = VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT,
|
||||||
|
.dstAccessMask = VK_ACCESS_2_NONE,
|
||||||
|
.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||||
|
.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
||||||
|
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||||
|
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||||
|
.subresourceRange = {
|
||||||
|
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
|
.baseMipLevel = 0,
|
||||||
|
.levelCount = 1,
|
||||||
|
.baseArrayLayer = 0,
|
||||||
|
.layerCount = 1,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
renderToPresentDependency = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.dependencyFlags = 0,
|
||||||
|
.memoryBarrierCount = 0,
|
||||||
|
.pMemoryBarriers = nullptr,
|
||||||
|
.bufferMemoryBarrierCount = 0,
|
||||||
|
.pBufferMemoryBarriers = nullptr,
|
||||||
|
.imageMemoryBarrierCount = 1,
|
||||||
|
.pImageMemoryBarriers = &renderToPresentBarrier,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MiscData::cleanup(RenderDevice const& renderDevice)
|
void MiscData::destroy( RenderDevice const& renderDevice )
|
||||||
{
|
{
|
||||||
VkDevice const device = renderDevice.device;
|
VkDevice const device = renderDevice.device;
|
||||||
|
|
||||||
vkDestroyPipeline(device, trianglePipeline, nullptr);
|
vkDestroyDescriptorPool( device, Take( descriptorPool ), nullptr );
|
||||||
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
vmaDestroyBuffer( renderDevice.gpuAllocator, Take( cameraUniformBuffer ), Take( cameraUniformBufferAllocation ) );
|
||||||
|
vmaDestroyBuffer( renderDevice.gpuAllocator, Take( vertexBuffer ), Take( vertexBufferAllocation ) );
|
||||||
|
|
||||||
|
vkDestroyPipeline( device, Take( meshPipeline ), nullptr );
|
||||||
|
vkDestroyPipelineLayout( device, Take( pipelineLayout ), nullptr );
|
||||||
|
vkDestroyDescriptorSetLayout( device, Take( descriptorSetLayout ), nullptr );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
52
MiscData.h
52
MiscData.h
|
|
@ -1,19 +1,55 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <volk.h>
|
#include <volk.h>
|
||||||
|
|
||||||
|
#include <vma/vk_mem_alloc.h>
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
struct RenderDevice;
|
struct RenderDevice;
|
||||||
|
|
||||||
|
struct Vertex
|
||||||
|
{
|
||||||
|
float position[4];
|
||||||
|
float color[4];
|
||||||
|
};
|
||||||
|
|
||||||
struct MiscData
|
struct MiscData
|
||||||
{
|
{
|
||||||
VkPipelineLayout pipelineLayout;
|
struct CameraData
|
||||||
VkPipeline trianglePipeline;
|
{
|
||||||
|
glm::mat4x4 modelMatrix;
|
||||||
|
glm::mat4x4 viewMatrix;
|
||||||
|
glm::mat4x4 projectionMatrix;
|
||||||
|
};
|
||||||
|
|
||||||
VkImageMemoryBarrier2 acquireToRenderBarrier;
|
uint64_t previousCounter;
|
||||||
VkDependencyInfo acquireToRenderDependency;
|
|
||||||
VkImageMemoryBarrier2 renderToPresentBarrier;
|
|
||||||
VkDependencyInfo renderToPresentDependency;
|
|
||||||
|
|
||||||
void init(RenderDevice const& renderDevice);
|
VkDescriptorSetLayout descriptorSetLayout;
|
||||||
void cleanup(RenderDevice const& renderDevice);
|
VkPipelineLayout pipelineLayout;
|
||||||
|
VkPipeline meshPipeline;
|
||||||
|
|
||||||
|
VkBuffer vertexBuffer;
|
||||||
|
VmaAllocation vertexBufferAllocation;
|
||||||
|
size_t vertexBufferSize;
|
||||||
|
std::array<Vertex, 4> vertices;
|
||||||
|
|
||||||
|
glm::vec3 cameraPosition;
|
||||||
|
glm::vec3 cameraTarget;
|
||||||
|
CameraData cameraData;
|
||||||
|
VkBuffer cameraUniformBuffer;
|
||||||
|
VmaAllocation cameraUniformBufferAllocation;
|
||||||
|
size_t cameraUniformBufferSize;
|
||||||
|
uint8_t* cameraUniformBufferPtr;
|
||||||
|
VkDescriptorPool descriptorPool;
|
||||||
|
VkDescriptorSet descriptorSet;
|
||||||
|
|
||||||
|
VkImageMemoryBarrier2 acquireToRenderBarrier;
|
||||||
|
VkDependencyInfo acquireToRenderDependency;
|
||||||
|
VkImageMemoryBarrier2 renderToPresentBarrier;
|
||||||
|
VkDependencyInfo renderToPresentDependency;
|
||||||
|
|
||||||
|
void init( RenderDevice const& renderDevice );
|
||||||
|
void destroy( RenderDevice const& renderDevice );
|
||||||
};
|
};
|
||||||
|
|
|
||||||
714
RenderDevice.cpp
714
RenderDevice.cpp
|
|
@ -14,426 +14,456 @@
|
||||||
|
|
||||||
RenderDevice::~RenderDevice()
|
RenderDevice::~RenderDevice()
|
||||||
{
|
{
|
||||||
ASSERT(!isInit());
|
ASSERT( !isInit() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Failure Handling
|
// TODO: Failure Handling
|
||||||
RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo const& createInfo)
|
RenderDevice* CreateRenderDevice( GlobalMemory* mem, RenderDevice::CreateInfo const& createInfo )
|
||||||
{
|
{
|
||||||
ASSERT(createInfo.window);
|
ASSERT( createInfo.window );
|
||||||
|
|
||||||
volkInitialize();
|
volkInitialize();
|
||||||
|
|
||||||
VkInstance instance;
|
VkInstance instance;
|
||||||
// Create Instance
|
// Create Instance
|
||||||
{
|
{
|
||||||
VkApplicationInfo constexpr applicationInfo = {
|
VkApplicationInfo constexpr applicationInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.pApplicationName = "Test",
|
.pApplicationName = "Test",
|
||||||
.applicationVersion = VK_MAKE_API_VERSION(0, 0, 1, 0),
|
.applicationVersion = VK_MAKE_API_VERSION( 0, 0, 1, 0 ),
|
||||||
.pEngineName = "Blaze",
|
.pEngineName = "Blaze",
|
||||||
.engineVersion = VK_MAKE_API_VERSION(0, 0, 1, 0),
|
.engineVersion = VK_MAKE_API_VERSION( 0, 0, 1, 0 ),
|
||||||
.apiVersion = VK_API_VERSION_1_3,
|
.apiVersion = VK_API_VERSION_1_3,
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t instanceExtensionCount;
|
uint32_t instanceExtensionCount;
|
||||||
char const* const* instanceExtensions = SDL_Vulkan_GetInstanceExtensions(&instanceExtensionCount);
|
char const* const* instanceExtensions = SDL_Vulkan_GetInstanceExtensions( &instanceExtensionCount );
|
||||||
|
|
||||||
VkInstanceCreateInfo const instanceCreateInfo = {
|
VkInstanceCreateInfo const instanceCreateInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.pApplicationInfo = &applicationInfo,
|
.pApplicationInfo = &applicationInfo,
|
||||||
.enabledLayerCount = 0,
|
.enabledLayerCount = 0,
|
||||||
.ppEnabledLayerNames = nullptr,
|
.ppEnabledLayerNames = nullptr,
|
||||||
.enabledExtensionCount = instanceExtensionCount,
|
.enabledExtensionCount = instanceExtensionCount,
|
||||||
.ppEnabledExtensionNames = instanceExtensions,
|
.ppEnabledExtensionNames = instanceExtensions,
|
||||||
};
|
};
|
||||||
|
|
||||||
VK_CHECK(vkCreateInstance(&instanceCreateInfo, nullptr, &instance));
|
VK_CHECK( vkCreateInstance(&instanceCreateInfo, nullptr, &instance) );
|
||||||
volkLoadInstance(instance);
|
volkLoadInstance( instance );
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSurfaceKHR surface;
|
VkSurfaceKHR surface;
|
||||||
// Create Surface
|
// Create Surface
|
||||||
ASSERT(SDL_Vulkan_CreateSurface(createInfo.window, instance, nullptr, &surface));
|
ASSERT( SDL_Vulkan_CreateSurface(createInfo.window, instance, nullptr, &surface) );
|
||||||
|
|
||||||
VkPhysicalDevice physicalDeviceInUse = nullptr;
|
VkPhysicalDevice physicalDeviceInUse = nullptr;
|
||||||
VkDevice device = nullptr;
|
VkDevice device = nullptr;
|
||||||
VmaAllocator gpuAllocator = nullptr;
|
VmaAllocator gpuAllocator = nullptr;
|
||||||
std::optional<uint32_t> directQueueFamilyIndex;
|
std::optional<uint32_t> directQueueFamilyIndex = std::nullopt;
|
||||||
VkQueue directQueue = nullptr;
|
VkQueue directQueue = nullptr;
|
||||||
// Create Device and Queue
|
// Create Device and Queue
|
||||||
{
|
{
|
||||||
auto tempAllocStart = mem->getState();
|
auto tempAllocStart = mem->getState();
|
||||||
|
|
||||||
uint32_t physicalDeviceCount;
|
uint32_t physicalDeviceCount;
|
||||||
VK_CHECK(vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, nullptr));
|
VK_CHECK( vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, nullptr) );
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_GPU, "Found %u GPUs", physicalDeviceCount);
|
SDL_LogInfo( SDL_LOG_CATEGORY_GPU, "Found %u GPUs", physicalDeviceCount );
|
||||||
|
|
||||||
VkPhysicalDevice* physicalDevices = reinterpret_cast<VkPhysicalDevice*>(mem->allocate(sizeof(VkPhysicalDevice) * physicalDeviceCount));
|
VkPhysicalDevice* physicalDevices = reinterpret_cast<VkPhysicalDevice*>(mem->allocate(
|
||||||
VK_CHECK(vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, physicalDevices));
|
sizeof( VkPhysicalDevice ) * physicalDeviceCount ));
|
||||||
|
VK_CHECK( vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, physicalDevices) );
|
||||||
|
|
||||||
for (VkPhysicalDevice const physicalDevice : std::span{ physicalDevices, physicalDeviceCount })
|
for ( VkPhysicalDevice const physicalDevice : std::span{ physicalDevices, physicalDeviceCount } )
|
||||||
{
|
{
|
||||||
auto tempAllocQueueProperties = mem->getState();
|
auto tempAllocQueueProperties = mem->getState();
|
||||||
|
|
||||||
VkPhysicalDeviceProperties properties;
|
VkPhysicalDeviceProperties properties;
|
||||||
vkGetPhysicalDeviceProperties(physicalDevice, &properties);
|
vkGetPhysicalDeviceProperties( physicalDevice, &properties );
|
||||||
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_GPU, "GPU: %s", properties.deviceName);
|
SDL_LogInfo( SDL_LOG_CATEGORY_GPU, "GPU: %s", properties.deviceName );
|
||||||
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_GPU, "- API Version %d.%d.%d",
|
SDL_LogInfo(
|
||||||
VK_API_VERSION_MAJOR(properties.apiVersion),
|
SDL_LOG_CATEGORY_GPU,
|
||||||
VK_API_VERSION_MINOR(properties.apiVersion),
|
"- API Version %d.%d.%d",
|
||||||
VK_API_VERSION_PATCH(properties.apiVersion));
|
VK_API_VERSION_MAJOR( properties.apiVersion ),
|
||||||
|
VK_API_VERSION_MINOR( properties.apiVersion ),
|
||||||
|
VK_API_VERSION_PATCH( properties.apiVersion ) );
|
||||||
|
|
||||||
constexpr static uint32_t API_PATCH_BITS = 0xFFF;
|
constexpr static uint32_t API_PATCH_BITS = 0xFFF;
|
||||||
if ((properties.apiVersion & (~API_PATCH_BITS)) < VK_API_VERSION_1_3)
|
if ( (properties.apiVersion & (~API_PATCH_BITS)) < VK_API_VERSION_1_3 )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU)
|
if ( properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t queueFamilyCount;
|
uint32_t queueFamilyCount;
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, nullptr);
|
vkGetPhysicalDeviceQueueFamilyProperties( physicalDevice, &queueFamilyCount, nullptr );
|
||||||
VkQueueFamilyProperties* queueFamilyProperties = reinterpret_cast<VkQueueFamilyProperties*>(mem->allocate(sizeof(VkQueueFamilyProperties) * queueFamilyCount));
|
VkQueueFamilyProperties* queueFamilyProperties = reinterpret_cast<VkQueueFamilyProperties*>(mem->allocate(
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, queueFamilyProperties);
|
sizeof( VkQueueFamilyProperties ) * queueFamilyCount ));
|
||||||
|
vkGetPhysicalDeviceQueueFamilyProperties( physicalDevice, &queueFamilyCount, queueFamilyProperties );
|
||||||
|
|
||||||
for (uint32_t queueFamilyIndex = 0; queueFamilyIndex != queueFamilyCount;
|
for ( uint32_t queueFamilyIndex = 0; queueFamilyIndex != queueFamilyCount;
|
||||||
++queueFamilyIndex)
|
++queueFamilyIndex )
|
||||||
{
|
{
|
||||||
VkQueueFamilyProperties const& qfp = queueFamilyProperties[queueFamilyIndex];
|
VkQueueFamilyProperties const& qfp = queueFamilyProperties[queueFamilyIndex];
|
||||||
|
|
||||||
bool hasGraphicsSupport = false;
|
bool hasGraphicsSupport = false;
|
||||||
bool hasComputeSupport = false;
|
bool hasComputeSupport = false;
|
||||||
bool hasTransferSupport = false;
|
bool hasTransferSupport = false;
|
||||||
bool hasPresentSupport = false;
|
bool hasPresentSupport = false;
|
||||||
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_GPU, "- Queue [%d]", queueFamilyIndex);
|
SDL_LogInfo( SDL_LOG_CATEGORY_GPU, "- Queue [%d]", queueFamilyIndex );
|
||||||
if (qfp.queueFlags & VK_QUEUE_GRAPHICS_BIT)
|
if ( qfp.queueFlags & VK_QUEUE_GRAPHICS_BIT )
|
||||||
{
|
{
|
||||||
hasGraphicsSupport = true;
|
hasGraphicsSupport = true;
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_GPU, "-- Graphic");
|
SDL_LogInfo( SDL_LOG_CATEGORY_GPU, "-- Graphic" );
|
||||||
}
|
}
|
||||||
if (qfp.queueFlags & VK_QUEUE_COMPUTE_BIT)
|
if ( qfp.queueFlags & VK_QUEUE_COMPUTE_BIT )
|
||||||
{
|
{
|
||||||
hasComputeSupport = true;
|
hasComputeSupport = true;
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_GPU, "-- Compute");
|
SDL_LogInfo( SDL_LOG_CATEGORY_GPU, "-- Compute" );
|
||||||
}
|
}
|
||||||
if (qfp.queueFlags & VK_QUEUE_TRANSFER_BIT)
|
if ( qfp.queueFlags & VK_QUEUE_TRANSFER_BIT )
|
||||||
{
|
{
|
||||||
hasTransferSupport = true;
|
hasTransferSupport = true;
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_GPU, "-- Transfer");
|
SDL_LogInfo( SDL_LOG_CATEGORY_GPU, "-- Transfer" );
|
||||||
}
|
}
|
||||||
|
|
||||||
VkBool32 isSurfaceSupported;
|
VkBool32 isSurfaceSupported;
|
||||||
VK_CHECK(vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, surface, &isSurfaceSupported));
|
VK_CHECK(
|
||||||
|
vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, surface, &isSurfaceSupported) );
|
||||||
|
|
||||||
if (isSurfaceSupported)
|
if ( isSurfaceSupported )
|
||||||
{
|
{
|
||||||
hasPresentSupport = true;
|
hasPresentSupport = true;
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_GPU, "-- Present");
|
SDL_LogInfo( SDL_LOG_CATEGORY_GPU, "-- Present" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasGraphicsSupport and hasComputeSupport and hasTransferSupport and hasPresentSupport)
|
if ( hasGraphicsSupport and hasComputeSupport and hasTransferSupport and hasPresentSupport )
|
||||||
{
|
{
|
||||||
physicalDeviceInUse = physicalDevice;
|
physicalDeviceInUse = physicalDevice;
|
||||||
directQueueFamilyIndex = queueFamilyIndex;
|
directQueueFamilyIndex = queueFamilyIndex;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
mem->restoreState( tempAllocQueueProperties );
|
||||||
|
}
|
||||||
|
|
||||||
mem->restoreState(tempAllocQueueProperties);
|
ASSERT( physicalDeviceInUse );
|
||||||
}
|
ASSERT( directQueueFamilyIndex.has_value() );
|
||||||
|
|
||||||
ASSERT(physicalDeviceInUse);
|
float priority = 1.0f;
|
||||||
ASSERT(directQueueFamilyIndex.has_value());
|
VkDeviceQueueCreateInfo queueCreateInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.queueFamilyIndex = directQueueFamilyIndex.value(),
|
||||||
|
.queueCount = 1,
|
||||||
|
.pQueuePriorities = &priority,
|
||||||
|
};
|
||||||
|
|
||||||
float priority = 1.0f;
|
VkPhysicalDeviceVulkan13Features constexpr features13 = {
|
||||||
VkDeviceQueueCreateInfo queueCreateInfo = {
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES,
|
||||||
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
|
.pNext = nullptr,
|
||||||
.pNext = nullptr,
|
.synchronization2 = true,
|
||||||
.flags = 0,
|
.dynamicRendering = true,
|
||||||
.queueFamilyIndex = directQueueFamilyIndex.value(),
|
};
|
||||||
.queueCount = 1,
|
|
||||||
.pQueuePriorities = &priority,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkPhysicalDeviceVulkan13Features constexpr features13 = {
|
VkPhysicalDeviceFeatures features = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES,
|
.depthClamp = true,
|
||||||
.pNext = nullptr,
|
.samplerAnisotropy = true,
|
||||||
.synchronization2 = true,
|
};
|
||||||
.dynamicRendering = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkPhysicalDeviceFeatures features = {
|
std::array enabledDeviceExtensions = {
|
||||||
.depthClamp = true,
|
VK_KHR_SWAPCHAIN_EXTENSION_NAME
|
||||||
.samplerAnisotropy = true,
|
};
|
||||||
};
|
|
||||||
|
|
||||||
std::array enabledDeviceExtensions = {
|
VkDeviceCreateInfo const deviceCreateInfo = {
|
||||||
VK_KHR_SWAPCHAIN_EXTENSION_NAME
|
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
||||||
};
|
.pNext = &features13,
|
||||||
|
.flags = 0,
|
||||||
|
.queueCreateInfoCount = 1,
|
||||||
|
.pQueueCreateInfos = &queueCreateInfo,
|
||||||
|
.enabledLayerCount = 0,
|
||||||
|
.ppEnabledLayerNames = nullptr,
|
||||||
|
.enabledExtensionCount = static_cast<uint32_t>(enabledDeviceExtensions.size()),
|
||||||
|
.ppEnabledExtensionNames = enabledDeviceExtensions.data(),
|
||||||
|
.pEnabledFeatures = &features,
|
||||||
|
};
|
||||||
|
|
||||||
VkDeviceCreateInfo const deviceCreateInfo = {
|
VK_CHECK( vkCreateDevice(physicalDeviceInUse, &deviceCreateInfo, nullptr, &device) );
|
||||||
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
volkLoadDevice( device );
|
||||||
.pNext = &features13,
|
|
||||||
.flags = 0,
|
|
||||||
.queueCreateInfoCount = 1,
|
|
||||||
.pQueueCreateInfos = &queueCreateInfo,
|
|
||||||
.enabledLayerCount = 0,
|
|
||||||
.ppEnabledLayerNames = nullptr,
|
|
||||||
.enabledExtensionCount = static_cast<uint32_t>(enabledDeviceExtensions.size()),
|
|
||||||
.ppEnabledExtensionNames = enabledDeviceExtensions.data(),
|
|
||||||
.pEnabledFeatures = &features,
|
|
||||||
};
|
|
||||||
|
|
||||||
VK_CHECK(vkCreateDevice(physicalDeviceInUse, &deviceCreateInfo, nullptr, &device));
|
VmaAllocatorCreateInfo allocatorCreateInfo = {
|
||||||
volkLoadDevice(device);
|
.flags = 0,
|
||||||
|
.physicalDevice = physicalDeviceInUse,
|
||||||
|
.device = device,
|
||||||
|
.preferredLargeHeapBlockSize = 0,
|
||||||
|
.pAllocationCallbacks = nullptr,
|
||||||
|
.pDeviceMemoryCallbacks = nullptr,
|
||||||
|
.pHeapSizeLimit = nullptr,
|
||||||
|
.pVulkanFunctions = nullptr,
|
||||||
|
.instance = instance,
|
||||||
|
.vulkanApiVersion = VK_API_VERSION_1_3,
|
||||||
|
.pTypeExternalMemoryHandleTypes = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
VmaAllocatorCreateInfo allocatorCreateInfo = {
|
VmaVulkanFunctions vkFunctions;
|
||||||
.flags = 0,
|
VK_CHECK( vmaImportVulkanFunctionsFromVolk(&allocatorCreateInfo, &vkFunctions) );
|
||||||
.physicalDevice = physicalDeviceInUse,
|
allocatorCreateInfo.pVulkanFunctions = &vkFunctions;
|
||||||
.device = device,
|
|
||||||
.preferredLargeHeapBlockSize = 0,
|
|
||||||
.pAllocationCallbacks = nullptr,
|
|
||||||
.pDeviceMemoryCallbacks = nullptr,
|
|
||||||
.pHeapSizeLimit = nullptr,
|
|
||||||
.pVulkanFunctions = nullptr,
|
|
||||||
.instance = instance,
|
|
||||||
.vulkanApiVersion = VK_API_VERSION_1_3,
|
|
||||||
.pTypeExternalMemoryHandleTypes = nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
VmaVulkanFunctions vkFunctions;
|
VK_CHECK( vmaCreateAllocator(&allocatorCreateInfo, &gpuAllocator) );
|
||||||
VK_CHECK(vmaImportVulkanFunctionsFromVolk(&allocatorCreateInfo, &vkFunctions));
|
|
||||||
allocatorCreateInfo.pVulkanFunctions = &vkFunctions;
|
|
||||||
|
|
||||||
VK_CHECK(vmaCreateAllocator(&allocatorCreateInfo, &gpuAllocator));
|
vkGetDeviceQueue( device, directQueueFamilyIndex.value(), 0, &directQueue );
|
||||||
|
|
||||||
vkGetDeviceQueue(device, directQueueFamilyIndex.value(), 0, &directQueue);
|
mem->restoreState( tempAllocStart );
|
||||||
|
}
|
||||||
|
|
||||||
mem->restoreState(tempAllocStart);
|
// Swapchain creation
|
||||||
}
|
VkExtent2D swapchainExtent = { createInfo.width, createInfo.height };
|
||||||
|
VkFormat swapchainFormat = VK_FORMAT_UNDEFINED;
|
||||||
|
VkSwapchainKHR swapchain;
|
||||||
|
VkImage* swapchainImages;
|
||||||
|
VkImageView* swapchainViews;
|
||||||
|
uint32_t swapchainImageCount;
|
||||||
|
{
|
||||||
|
auto tempAllocStart = mem->getState();
|
||||||
|
|
||||||
// Swapchain creation
|
VkSurfaceCapabilitiesKHR capabilities;
|
||||||
VkExtent2D swapchainExtent = { createInfo.width, createInfo.height };
|
VK_CHECK( vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDeviceInUse, surface, &capabilities) );
|
||||||
VkFormat swapchainFormat = VK_FORMAT_UNDEFINED;
|
|
||||||
VkSwapchainKHR swapchain;
|
|
||||||
VkImage* swapchainImages;
|
|
||||||
VkImageView* swapchainViews;
|
|
||||||
uint32_t swapchainImageCount;
|
|
||||||
{
|
|
||||||
auto tempAllocStart = mem->getState();
|
|
||||||
|
|
||||||
VkSurfaceCapabilitiesKHR capabilities;
|
// Image Count Calculation
|
||||||
VK_CHECK(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDeviceInUse, surface, &capabilities));
|
swapchainImageCount = 3;
|
||||||
|
if ( capabilities.maxImageCount > 0 )
|
||||||
|
{
|
||||||
|
swapchainImageCount = std::min( swapchainImageCount, capabilities.maxImageCount );
|
||||||
|
}
|
||||||
|
swapchainImageCount = std::max( swapchainImageCount, capabilities.minImageCount + 1 );
|
||||||
|
|
||||||
// Image Count Calculation
|
// Image Size calculation
|
||||||
swapchainImageCount = 3;
|
{
|
||||||
if (capabilities.maxImageCount > 0)
|
auto [minWidth, minHeight] = capabilities.minImageExtent;
|
||||||
{
|
auto [maxWidth, maxHeight] = capabilities.maxImageExtent;
|
||||||
swapchainImageCount = std::min(swapchainImageCount, capabilities.maxImageCount);
|
swapchainExtent.width = Clamp( swapchainExtent.width, minWidth, maxWidth );
|
||||||
}
|
swapchainExtent.height = Clamp( swapchainExtent.height, minHeight, maxHeight );
|
||||||
swapchainImageCount = std::max(swapchainImageCount, capabilities.minImageCount + 1);
|
}
|
||||||
|
|
||||||
// Image Size calculation
|
uint32_t surfaceFormatCount;
|
||||||
{
|
vkGetPhysicalDeviceSurfaceFormatsKHR( physicalDeviceInUse, surface, &surfaceFormatCount, nullptr );
|
||||||
auto [minWidth, minHeight] = capabilities.minImageExtent;
|
VkSurfaceFormatKHR* surfaceFormats = reinterpret_cast<VkSurfaceFormatKHR*>(mem->allocate(
|
||||||
auto [maxWidth, maxHeight] = capabilities.maxImageExtent;
|
sizeof( VkSurfaceFormatKHR ) * surfaceFormatCount ));
|
||||||
swapchainExtent.width = Clamp(swapchainExtent.width, minWidth, maxWidth);
|
vkGetPhysicalDeviceSurfaceFormatsKHR( physicalDeviceInUse, surface, &surfaceFormatCount, surfaceFormats );
|
||||||
swapchainExtent.height = Clamp(swapchainExtent.height, minHeight, maxHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t surfaceFormatCount;
|
VkSurfaceFormatKHR format = {
|
||||||
vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDeviceInUse, surface, &surfaceFormatCount, nullptr);
|
.format = VK_FORMAT_UNDEFINED,
|
||||||
VkSurfaceFormatKHR* surfaceFormats = reinterpret_cast<VkSurfaceFormatKHR*>(mem->allocate(sizeof(VkSurfaceFormatKHR*) * surfaceFormatCount));
|
.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
|
||||||
vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDeviceInUse, surface, &surfaceFormatCount, surfaceFormats);
|
};
|
||||||
|
for ( auto& surfaceFormat : std::span{ surfaceFormats, surfaceFormatCount } )
|
||||||
|
{
|
||||||
|
if ( surfaceFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR )
|
||||||
|
{
|
||||||
|
SDL_LogInfo( SDL_LOG_CATEGORY_GPU, "Color Space SRGB Found %d", surfaceFormat.format );
|
||||||
|
if ( surfaceFormat.format == VK_FORMAT_R8G8B8A8_SRGB )
|
||||||
|
{
|
||||||
|
format = surfaceFormat;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( surfaceFormat.format == VK_FORMAT_B8G8R8A8_SRGB )
|
||||||
|
{
|
||||||
|
format = surfaceFormat;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( surfaceFormat.format == VK_FORMAT_R8G8B8A8_UNORM )
|
||||||
|
{
|
||||||
|
format = surfaceFormat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ASSERT( format.format != VK_FORMAT_UNDEFINED );
|
||||||
|
swapchainFormat = format.format;
|
||||||
|
|
||||||
VkSurfaceFormatKHR format = {
|
uint32_t presentModeCount;
|
||||||
.format = VK_FORMAT_UNDEFINED,
|
vkGetPhysicalDeviceSurfacePresentModesKHR( physicalDeviceInUse, surface, &presentModeCount, nullptr );
|
||||||
.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
|
VkPresentModeKHR* presentModes = reinterpret_cast<VkPresentModeKHR*>(mem->allocate(
|
||||||
};
|
sizeof( VkPresentModeKHR ) * presentModeCount ));
|
||||||
for (auto& surfaceFormat : std::span{ surfaceFormats, surfaceFormatCount })
|
vkGetPhysicalDeviceSurfacePresentModesKHR( physicalDeviceInUse, surface, &presentModeCount, presentModes );
|
||||||
{
|
|
||||||
if (surfaceFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
|
|
||||||
{
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_GPU, "Color Space SRGB Found %d", surfaceFormat.format);
|
|
||||||
if (surfaceFormat.format == VK_FORMAT_R8G8B8A8_SRGB) {
|
|
||||||
format = surfaceFormat;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (surfaceFormat.format == VK_FORMAT_B8G8R8A8_SRGB) {
|
|
||||||
format = surfaceFormat;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (surfaceFormat.format == VK_FORMAT_R8G8B8A8_UNORM) {
|
|
||||||
format = surfaceFormat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ASSERT(format.format != VK_FORMAT_UNDEFINED);
|
|
||||||
swapchainFormat = format.format;
|
|
||||||
|
|
||||||
uint32_t presentModeCount;
|
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
|
||||||
vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDeviceInUse, surface, &presentModeCount, nullptr);
|
for ( VkPresentModeKHR presentModeIter : std::span{ presentModes, presentModeCount } )
|
||||||
VkPresentModeKHR* presentModes = reinterpret_cast<VkPresentModeKHR*>(mem->allocate(sizeof(VkPresentModeKHR*) * presentModeCount));
|
{
|
||||||
vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDeviceInUse, surface, &presentModeCount, presentModes);
|
if ( presentModeIter == VK_PRESENT_MODE_FIFO_RELAXED_KHR )
|
||||||
|
{
|
||||||
|
presentMode = presentModeIter;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
|
if ( presentModeIter == VK_PRESENT_MODE_MAILBOX_KHR )
|
||||||
for (VkPresentModeKHR presentModeIter : std::span{ presentModes, presentModeCount })
|
{
|
||||||
{
|
presentMode = presentModeIter;
|
||||||
if (presentModeIter == VK_PRESENT_MODE_FIFO_RELAXED_KHR)
|
}
|
||||||
{
|
}
|
||||||
presentMode = presentModeIter;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (presentModeIter == VK_PRESENT_MODE_MAILBOX_KHR)
|
mem->restoreState( tempAllocStart );
|
||||||
{
|
|
||||||
presentMode = presentModeIter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mem->restoreState(tempAllocStart);
|
VkSwapchainCreateInfoKHR const swapchainCreateInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.surface = surface,
|
||||||
|
.minImageCount = swapchainImageCount,
|
||||||
|
.imageFormat = format.format,
|
||||||
|
.imageColorSpace = format.colorSpace,
|
||||||
|
.imageExtent = swapchainExtent,
|
||||||
|
.imageArrayLayers = 1,
|
||||||
|
.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
||||||
|
.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||||
|
.queueFamilyIndexCount = 0,
|
||||||
|
.pQueueFamilyIndices = nullptr,
|
||||||
|
.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR,
|
||||||
|
.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
|
||||||
|
.presentMode = presentMode,
|
||||||
|
.clipped = false,
|
||||||
|
.oldSwapchain = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
VkSwapchainCreateInfoKHR const swapchainCreateInfo = {
|
VK_CHECK( vkCreateSwapchainKHR(device, &swapchainCreateInfo, nullptr, &swapchain) );
|
||||||
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
|
|
||||||
.pNext = nullptr,
|
|
||||||
.flags = 0,
|
|
||||||
.surface = surface,
|
|
||||||
.minImageCount = swapchainImageCount,
|
|
||||||
.imageFormat = format.format,
|
|
||||||
.imageColorSpace = format.colorSpace,
|
|
||||||
.imageExtent = swapchainExtent,
|
|
||||||
.imageArrayLayers = 1,
|
|
||||||
.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
|
||||||
.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
|
||||||
.queueFamilyIndexCount = 0,
|
|
||||||
.pQueueFamilyIndices = nullptr,
|
|
||||||
.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR,
|
|
||||||
.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
|
|
||||||
.presentMode = presentMode,
|
|
||||||
.clipped = false,
|
|
||||||
.oldSwapchain = nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
VK_CHECK(vkCreateSwapchainKHR(device, &swapchainCreateInfo, nullptr, &swapchain));
|
swapchainImageCount = 0;
|
||||||
|
vkGetSwapchainImagesKHR( device, swapchain, &swapchainImageCount, nullptr );
|
||||||
|
swapchainImages = reinterpret_cast<VkImage*>(mem->allocate( sizeof( VkImage ) * swapchainImageCount ));
|
||||||
|
vkGetSwapchainImagesKHR( device, swapchain, &swapchainImageCount, swapchainImages );
|
||||||
|
|
||||||
swapchainImageCount = 0;
|
swapchainViews = reinterpret_cast<VkImageView*>(mem->allocate( sizeof( VkImageView ) * swapchainImageCount ));
|
||||||
vkGetSwapchainImagesKHR(device, swapchain, &swapchainImageCount, nullptr);
|
for ( uint32_t i = 0; i != swapchainImageCount; ++i )
|
||||||
swapchainImages = reinterpret_cast<VkImage*>(mem->allocate(sizeof(VkImage) * swapchainImageCount));
|
{
|
||||||
vkGetSwapchainImagesKHR(device, swapchain, &swapchainImageCount, swapchainImages);
|
VkImageViewCreateInfo const viewCreateInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.image = swapchainImages[i],
|
||||||
|
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
||||||
|
.format = format.format,
|
||||||
|
.components = {
|
||||||
|
VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||||
|
VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||||
|
VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||||
|
VK_COMPONENT_SWIZZLE_IDENTITY
|
||||||
|
},
|
||||||
|
.subresourceRange = {
|
||||||
|
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
|
.baseMipLevel = 0,
|
||||||
|
.levelCount = 1,
|
||||||
|
.baseArrayLayer = 0,
|
||||||
|
.layerCount = 1,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
swapchainViews = reinterpret_cast<VkImageView*>(mem->allocate(sizeof(VkImageView) * swapchainImageCount));
|
VK_CHECK( vkCreateImageView(device, &viewCreateInfo, nullptr, &swapchainViews[i]) );
|
||||||
for (uint32_t i = 0; i != swapchainImageCount; ++i) {
|
}
|
||||||
VkImageViewCreateInfo const viewCreateInfo = {
|
}
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
|
||||||
.pNext = nullptr,
|
|
||||||
.flags = 0,
|
|
||||||
.image = swapchainImages[i],
|
|
||||||
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
|
||||||
.format = format.format,
|
|
||||||
.components = {
|
|
||||||
VK_COMPONENT_SWIZZLE_IDENTITY,
|
|
||||||
VK_COMPONENT_SWIZZLE_IDENTITY,
|
|
||||||
VK_COMPONENT_SWIZZLE_IDENTITY,
|
|
||||||
VK_COMPONENT_SWIZZLE_IDENTITY
|
|
||||||
},
|
|
||||||
.subresourceRange = {
|
|
||||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
|
||||||
.baseMipLevel = 0,
|
|
||||||
.levelCount = 1,
|
|
||||||
.baseArrayLayer = 0,
|
|
||||||
.layerCount = 1,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
VK_CHECK(vkCreateImageView(device, &viewCreateInfo, nullptr, &swapchainViews[i]));
|
// Init frames.
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init frames.
|
Frame* frames = reinterpret_cast<Frame*>(mem->allocate( sizeof( Frame ) * swapchainImageCount ));
|
||||||
|
for ( uint32_t i = 0; i != swapchainImageCount; ++i )
|
||||||
|
{
|
||||||
|
new( frames + i ) Frame( device, directQueueFamilyIndex.value() );
|
||||||
|
}
|
||||||
|
|
||||||
Frame* frames = reinterpret_cast<Frame*>(mem->allocate(sizeof(Frame) * swapchainImageCount));
|
Byte* allocation = mem->allocate( sizeof( RenderDevice ), alignof( RenderDevice ) );
|
||||||
for (uint32_t i = 0; i != swapchainImageCount; ++i)
|
return new( allocation ) RenderDevice{
|
||||||
{
|
instance,
|
||||||
new (frames + i) Frame(device, directQueueFamilyIndex.value());
|
surface,
|
||||||
}
|
physicalDeviceInUse,
|
||||||
|
device,
|
||||||
Byte* allocation = mem->allocate(sizeof(RenderDevice), alignof(RenderDevice));
|
gpuAllocator,
|
||||||
return new (allocation) RenderDevice{
|
directQueue,
|
||||||
instance, surface, physicalDeviceInUse,
|
directQueueFamilyIndex.value(),
|
||||||
device, gpuAllocator, directQueue, directQueueFamilyIndex.value(),
|
swapchainFormat,
|
||||||
swapchainFormat, swapchainExtent, swapchain, swapchainImages, swapchainViews, frames, swapchainImageCount,
|
swapchainExtent,
|
||||||
};
|
swapchain,
|
||||||
|
swapchainImages,
|
||||||
|
swapchainViews,
|
||||||
|
frames,
|
||||||
|
swapchainImageCount,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool RenderDevice::isInit() const
|
inline bool RenderDevice::isInit() const
|
||||||
{
|
{
|
||||||
return instance and device;
|
return instance and device;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderDevice::cleanup()
|
void RenderDevice::destroy()
|
||||||
{
|
{
|
||||||
if (not isInit())
|
if ( not isInit() ) return;
|
||||||
return;
|
|
||||||
|
|
||||||
for (Frame& frame : std::span{ frames, swapchainImageCount })
|
for ( Frame& frame : std::span{ frames, swapchainImageCount } )
|
||||||
{
|
{
|
||||||
frame.cleanup(*this);
|
frame.destroy( *this );
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto const& view : std::span{ swapchainViews, swapchainImageCount })
|
for ( auto const& view : std::span{ swapchainViews, swapchainImageCount } )
|
||||||
{
|
{
|
||||||
vkDestroyImageView(device, view, nullptr);
|
vkDestroyImageView( device, view, nullptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
vkDestroySwapchainKHR(device, Take(swapchain), nullptr);
|
vkDestroySwapchainKHR( device, Take( swapchain ), nullptr );
|
||||||
|
|
||||||
vkDestroyDevice(Take(device), nullptr);
|
vmaDestroyAllocator( Take( gpuAllocator ) );
|
||||||
|
vkDestroyDevice( Take( device ), nullptr );
|
||||||
|
|
||||||
SDL_Vulkan_DestroySurface(instance, Take(surface), nullptr);
|
SDL_Vulkan_DestroySurface( instance, Take( surface ), nullptr );
|
||||||
|
|
||||||
vkDestroyInstance(Take(instance), nullptr);
|
vkDestroyInstance( Take( instance ), nullptr );
|
||||||
|
|
||||||
volkFinalize();
|
volkFinalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderDevice::waitIdle() const
|
void RenderDevice::waitIdle() const
|
||||||
{
|
{
|
||||||
VK_CHECK(vkDeviceWaitIdle(device));
|
VK_CHECK( vkDeviceWaitIdle(device) );
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RenderDevice::getNumFrames() const
|
uint32_t RenderDevice::getNumFrames() const
|
||||||
{
|
{
|
||||||
return swapchainImageCount;
|
return swapchainImageCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderDevice::RenderDevice(VkInstance const instance, VkSurfaceKHR const surface, VkPhysicalDevice const physicalDeviceInUse,
|
RenderDevice::RenderDevice(
|
||||||
VkDevice const device, VmaAllocator gpuAllocator, VkQueue const directQueue, uint32_t const directQueueFamilyIndex,
|
VkInstance const instance,
|
||||||
VkFormat const swapchainFormat, VkExtent2D const swapchainExtent, VkSwapchainKHR const swapchain, VkImage* swapchainImages,
|
VkSurfaceKHR const surface,
|
||||||
VkImageView* swapchainViews, Frame* frames, uint32_t const swapchainImageCount)
|
VkPhysicalDevice const physicalDeviceInUse,
|
||||||
: instance{ instance }
|
VkDevice const device,
|
||||||
, surface{ surface }
|
VmaAllocator const gpuAllocator,
|
||||||
, physicalDeviceInUse{ physicalDeviceInUse }
|
VkQueue const directQueue,
|
||||||
, device{ device }
|
uint32_t const directQueueFamilyIndex,
|
||||||
, gpuAllocator{ gpuAllocator }
|
VkFormat const swapchainFormat,
|
||||||
, directQueue{ directQueue }
|
VkExtent2D const swapchainExtent,
|
||||||
, directQueueFamilyIndex{ directQueueFamilyIndex }
|
VkSwapchainKHR const swapchain,
|
||||||
, swapchainFormat{ swapchainFormat }
|
VkImage* swapchainImages,
|
||||||
, swapchainExtent{ swapchainExtent }
|
VkImageView* swapchainViews,
|
||||||
, swapchain{ swapchain }
|
Frame* frames,
|
||||||
, swapchainImages{ swapchainImages }
|
uint32_t const swapchainImageCount )
|
||||||
, swapchainViews{ swapchainViews }
|
: instance{ instance }
|
||||||
, frames{ frames }
|
, surface{ surface }
|
||||||
, swapchainImageCount{ swapchainImageCount }
|
, physicalDeviceInUse{ physicalDeviceInUse }
|
||||||
{
|
, device{ device }
|
||||||
}
|
, gpuAllocator{ gpuAllocator }
|
||||||
|
, directQueue{ directQueue }
|
||||||
|
, directQueueFamilyIndex{ directQueueFamilyIndex }
|
||||||
|
, swapchainFormat{ swapchainFormat }
|
||||||
|
, swapchainExtent{ swapchainExtent }
|
||||||
|
, swapchain{ swapchain }
|
||||||
|
, swapchainImages{ swapchainImages }
|
||||||
|
, swapchainViews{ swapchainViews }
|
||||||
|
, frames{ frames }
|
||||||
|
, swapchainImageCount{ swapchainImageCount } {}
|
||||||
|
|
|
||||||
|
|
@ -18,63 +18,63 @@ struct Frame;
|
||||||
/// TODO: Fail elegantly.
|
/// TODO: Fail elegantly.
|
||||||
struct RenderDevice
|
struct RenderDevice
|
||||||
{
|
{
|
||||||
struct CreateInfo
|
struct CreateInfo
|
||||||
{
|
{
|
||||||
SDL_Window* window = nullptr;
|
SDL_Window* window = nullptr;
|
||||||
uint32_t width = 640;
|
uint32_t width = 640;
|
||||||
uint32_t height = 480;
|
uint32_t height = 480;
|
||||||
};
|
};
|
||||||
|
|
||||||
VkInstance instance;
|
VkInstance instance;
|
||||||
VkSurfaceKHR surface;
|
VkSurfaceKHR surface;
|
||||||
VkPhysicalDevice physicalDeviceInUse;
|
VkPhysicalDevice physicalDeviceInUse;
|
||||||
|
|
||||||
VkDevice device;
|
VkDevice device;
|
||||||
VmaAllocator gpuAllocator;
|
VmaAllocator gpuAllocator;
|
||||||
VkQueue directQueue;
|
VkQueue directQueue;
|
||||||
uint32_t directQueueFamilyIndex;
|
uint32_t directQueueFamilyIndex;
|
||||||
|
|
||||||
VkFormat swapchainFormat;
|
VkFormat swapchainFormat;
|
||||||
VkExtent2D swapchainExtent;
|
VkExtent2D swapchainExtent;
|
||||||
VkSwapchainKHR swapchain;
|
VkSwapchainKHR swapchain;
|
||||||
VkImage* swapchainImages;
|
VkImage* swapchainImages;
|
||||||
VkImageView* swapchainViews;
|
VkImageView* swapchainViews;
|
||||||
Frame* frames;
|
Frame* frames;
|
||||||
uint32_t swapchainImageCount;
|
uint32_t swapchainImageCount;
|
||||||
uint32_t frameIndex = 0;
|
uint32_t frameIndex = 0;
|
||||||
|
|
||||||
[[nodiscard]] bool isInit() const;
|
[[nodiscard]] bool isInit() const;
|
||||||
void cleanup();
|
void destroy();
|
||||||
void waitIdle() const;
|
void waitIdle() const;
|
||||||
[[nodiscard]] uint32_t getNumFrames() const;
|
[[nodiscard]] uint32_t getNumFrames() const;
|
||||||
|
|
||||||
RenderDevice(
|
RenderDevice(
|
||||||
VkInstance instance,
|
VkInstance instance,
|
||||||
VkSurfaceKHR surface,
|
VkSurfaceKHR surface,
|
||||||
VkPhysicalDevice physicalDeviceInUse,
|
VkPhysicalDevice physicalDeviceInUse,
|
||||||
VkDevice device,
|
VkDevice device,
|
||||||
VmaAllocator gpuAllocator,
|
VmaAllocator gpuAllocator,
|
||||||
VkQueue directQueue,
|
VkQueue directQueue,
|
||||||
uint32_t directQueueFamilyIndex,
|
uint32_t directQueueFamilyIndex,
|
||||||
// TODO: Pack?
|
// TODO: Pack?
|
||||||
|
|
||||||
VkFormat swapchainFormat,
|
VkFormat swapchainFormat,
|
||||||
VkExtent2D swapchainExtent,
|
VkExtent2D swapchainExtent,
|
||||||
VkSwapchainKHR swapchain,
|
VkSwapchainKHR swapchain,
|
||||||
|
|
||||||
VkImage* swapchainImages,
|
VkImage* swapchainImages,
|
||||||
VkImageView* swapchainViews,
|
VkImageView* swapchainViews,
|
||||||
Frame* frames,
|
Frame* frames,
|
||||||
uint32_t swapchainImageCount
|
uint32_t swapchainImageCount
|
||||||
);
|
);
|
||||||
|
|
||||||
RenderDevice(RenderDevice const&) = delete;
|
RenderDevice( RenderDevice const& ) = delete;
|
||||||
RenderDevice& operator=(RenderDevice const&) = delete;
|
RenderDevice& operator=( RenderDevice const& ) = delete;
|
||||||
|
|
||||||
RenderDevice(RenderDevice&&) noexcept = delete;
|
RenderDevice( RenderDevice&& ) noexcept = delete;
|
||||||
RenderDevice& operator=(RenderDevice&&) noexcept = delete;
|
RenderDevice& operator=( RenderDevice&& ) noexcept = delete;
|
||||||
|
|
||||||
~RenderDevice();
|
~RenderDevice();
|
||||||
};
|
};
|
||||||
|
|
||||||
RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo const& createInfo);
|
RenderDevice* CreateRenderDevice( GlobalMemory* mem, RenderDevice::CreateInfo const& createInfo );
|
||||||
|
|
|
||||||
BIN
Triangle.spv
BIN
Triangle.spv
Binary file not shown.
|
|
@ -4,4 +4,4 @@
|
||||||
#pragma warning(disable : 5045)
|
#pragma warning(disable : 5045)
|
||||||
#define VMA_IMPLEMENTATION
|
#define VMA_IMPLEMENTATION
|
||||||
#include <vma/vk_mem_alloc.h>
|
#include <vma/vk_mem_alloc.h>
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
"volk",
|
"volk",
|
||||||
"shader-slang",
|
"shader-slang",
|
||||||
"vulkan-memory-allocator",
|
"vulkan-memory-allocator",
|
||||||
|
"glm",
|
||||||
{
|
{
|
||||||
"name": "sdl3",
|
"name": "sdl3",
|
||||||
"features": [ "vulkan" ]
|
"features": [ "vulkan" ]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue