Major Cleanup.
This commit is contained in:
parent
e7d74e6b0f
commit
9fe2815ab4
20
AppState.cpp
20
AppState.cpp
|
|
@ -3,15 +3,15 @@
|
||||||
#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;
|
||||||
|
|
||||||
|
|
@ -19,19 +19,23 @@ void AppState::cleanup()
|
||||||
|
|
||||||
Take(miscData)->cleanup(*renderDevice);
|
Take(miscData)->cleanup(*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)
|
||||||
|
: window{ window }
|
||||||
, renderDevice{ renderDevice }
|
, renderDevice{ renderDevice }
|
||||||
, miscData{ miscData }
|
, miscData{ miscData } {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AppState* CreateAppState(GlobalMemory* memory, uint32_t const width, uint32_t const height)
|
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);
|
SDL_Window* window = SDL_CreateWindow(
|
||||||
|
"Blaze Test",
|
||||||
|
static_cast<int>(width),
|
||||||
|
static_cast<int>(height),
|
||||||
|
SDL_WINDOW_VULKAN);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", SDL_GetError());
|
||||||
|
|
@ -60,5 +64,5 @@ AppState* CreateAppState(GlobalMemory* memory, uint32_t const width, uint32_t co
|
||||||
|
|
||||||
AppState::~AppState()
|
AppState::~AppState()
|
||||||
{
|
{
|
||||||
cleanup();
|
ASSERT(!isInit());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
struct GlobalMemory;
|
|
||||||
struct SDL_Window;
|
struct SDL_Window;
|
||||||
|
|
||||||
|
struct GlobalMemory;
|
||||||
struct RenderDevice;
|
struct RenderDevice;
|
||||||
struct MiscData;
|
struct MiscData;
|
||||||
|
|
||||||
|
|
@ -13,8 +14,9 @@ struct AppState
|
||||||
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 );
|
||||||
|
|
||||||
|
|
|
||||||
14
Blaze.cpp
14
Blaze.cpp
|
|
@ -56,8 +56,7 @@ SDL_AppResult SDL_AppInit(void** pAppState, int, char**)
|
||||||
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);
|
||||||
|
|
||||||
|
|
@ -76,11 +75,15 @@ SDL_AppResult SDL_AppIterate(void* appstate)
|
||||||
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(
|
||||||
|
vkWaitForFences(renderDevice.device, 1, ¤tFrame.frameReadyToReuse, VK_TRUE, std::numeric_limits<uint32_t>::max
|
||||||
|
()) );
|
||||||
// All resources of frame 'frameIndex' are free.
|
// All resources of frame 'frameIndex' are free.
|
||||||
|
|
||||||
uint32_t currentImageIndex;
|
uint32_t currentImageIndex;
|
||||||
VK_CHECK(vkAcquireNextImageKHR(renderDevice.device, renderDevice.swapchain, std::numeric_limits<uint32_t>::max(), currentFrame.imageAcquiredSemaphore, nullptr, ¤tImageIndex));
|
VK_CHECK(
|
||||||
|
vkAcquireNextImageKHR(renderDevice.device, renderDevice.swapchain, std::numeric_limits<uint32_t>::max(),
|
||||||
|
currentFrame.imageAcquiredSemaphore, nullptr, ¤tImageIndex) );
|
||||||
|
|
||||||
VK_CHECK( vkResetFences(renderDevice.device, 1, ¤tFrame.frameReadyToReuse) );
|
VK_CHECK( vkResetFences(renderDevice.device, 1, ¤tFrame.frameReadyToReuse) );
|
||||||
VK_CHECK( vkResetCommandPool(renderDevice.device, currentFrame.commandPool, 0) );
|
VK_CHECK( vkResetCommandPool(renderDevice.device, currentFrame.commandPool, 0) );
|
||||||
|
|
@ -150,7 +153,6 @@ SDL_AppResult SDL_AppIterate(void* appstate)
|
||||||
// Render Something?
|
// Render Something?
|
||||||
vkCmdBindPipeline( cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, misc.trianglePipeline );
|
vkCmdBindPipeline( cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, misc.trianglePipeline );
|
||||||
vkCmdDraw( cmd, 3, 1, 0, 0 );
|
vkCmdDraw( cmd, 3, 1, 0, 0 );
|
||||||
|
|
||||||
}
|
}
|
||||||
vkCmdEndRendering( cmd );
|
vkCmdEndRendering( cmd );
|
||||||
vkCmdPipelineBarrier2( cmd, &misc.renderToPresentDependency );
|
vkCmdPipelineBarrier2( cmd, &misc.renderToPresentDependency );
|
||||||
|
|
@ -203,7 +205,7 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
@ -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" />
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ Frame::Frame(VkDevice const device, uint32_t const directQueueFamilyIndex)
|
||||||
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;
|
||||||
|
|
||||||
|
|
|
||||||
3
Frame.h
3
Frame.h
|
|
@ -17,8 +17,7 @@ struct Frame
|
||||||
|
|
||||||
Frame( VkDevice device, uint32_t directQueueFamilyIndex );
|
Frame( VkDevice device, uint32_t directQueueFamilyIndex );
|
||||||
|
|
||||||
void cleanup(RenderDevice const& renderDevice);
|
void destroy( RenderDevice const& renderDevice );
|
||||||
|
|
||||||
~Frame();
|
~Frame();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,13 @@ Byte* GlobalMemory::allocate(size_t const size)
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
@ -57,8 +63,8 @@ GlobalMemory::State GlobalMemory::getState() const
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,13 @@ struct GlobalMemory
|
||||||
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;
|
||||||
|
|
|
||||||
|
|
@ -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,7 +15,7 @@ void MiscData::init(RenderDevice const& renderDevice)
|
||||||
void* rawData = SDL_LoadFile( "Triangle.spv", &dataSize );
|
void* rawData = SDL_LoadFile( "Triangle.spv", &dataSize );
|
||||||
ASSERT( dataSize % 4 == 0 );
|
ASSERT( dataSize % 4 == 0 );
|
||||||
|
|
||||||
if (not rawData)
|
if ( !rawData )
|
||||||
{
|
{
|
||||||
SDL_LogError( SDL_LOG_CATEGORY_SYSTEM, "%s", SDL_GetError() );
|
SDL_LogError( SDL_LOG_CATEGORY_SYSTEM, "%s", SDL_GetError() );
|
||||||
abort();
|
abort();
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,8 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
||||||
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(
|
||||||
|
sizeof( VkPhysicalDevice ) * physicalDeviceCount ));
|
||||||
VK_CHECK( vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, physicalDevices) );
|
VK_CHECK( vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, physicalDevices) );
|
||||||
|
|
||||||
for ( VkPhysicalDevice const physicalDevice : std::span{ physicalDevices, physicalDeviceCount } )
|
for ( VkPhysicalDevice const physicalDevice : std::span{ physicalDevices, physicalDeviceCount } )
|
||||||
|
|
@ -84,7 +85,9 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
||||||
|
|
||||||
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(
|
||||||
|
SDL_LOG_CATEGORY_GPU,
|
||||||
|
"- API Version %d.%d.%d",
|
||||||
VK_API_VERSION_MAJOR( properties.apiVersion ),
|
VK_API_VERSION_MAJOR( properties.apiVersion ),
|
||||||
VK_API_VERSION_MINOR( properties.apiVersion ),
|
VK_API_VERSION_MINOR( properties.apiVersion ),
|
||||||
VK_API_VERSION_PATCH( properties.apiVersion ) );
|
VK_API_VERSION_PATCH( properties.apiVersion ) );
|
||||||
|
|
@ -102,7 +105,8 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
||||||
|
|
||||||
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(
|
||||||
|
sizeof( VkQueueFamilyProperties ) * queueFamilyCount ));
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties( physicalDevice, &queueFamilyCount, queueFamilyProperties );
|
vkGetPhysicalDeviceQueueFamilyProperties( physicalDevice, &queueFamilyCount, queueFamilyProperties );
|
||||||
|
|
||||||
for ( uint32_t queueFamilyIndex = 0; queueFamilyIndex != queueFamilyCount;
|
for ( uint32_t queueFamilyIndex = 0; queueFamilyIndex != queueFamilyCount;
|
||||||
|
|
@ -133,7 +137,8 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
||||||
}
|
}
|
||||||
|
|
||||||
VkBool32 isSurfaceSupported;
|
VkBool32 isSurfaceSupported;
|
||||||
VK_CHECK(vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, surface, &isSurfaceSupported));
|
VK_CHECK(
|
||||||
|
vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, surface, &isSurfaceSupported) );
|
||||||
|
|
||||||
if ( isSurfaceSupported )
|
if ( isSurfaceSupported )
|
||||||
{
|
{
|
||||||
|
|
@ -147,7 +152,6 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
||||||
directQueueFamilyIndex = queueFamilyIndex;
|
directQueueFamilyIndex = queueFamilyIndex;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mem->restoreState( tempAllocQueueProperties );
|
mem->restoreState( tempAllocQueueProperties );
|
||||||
|
|
@ -254,7 +258,8 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
||||||
|
|
||||||
uint32_t surfaceFormatCount;
|
uint32_t surfaceFormatCount;
|
||||||
vkGetPhysicalDeviceSurfaceFormatsKHR( physicalDeviceInUse, surface, &surfaceFormatCount, nullptr );
|
vkGetPhysicalDeviceSurfaceFormatsKHR( physicalDeviceInUse, surface, &surfaceFormatCount, nullptr );
|
||||||
VkSurfaceFormatKHR* surfaceFormats = reinterpret_cast<VkSurfaceFormatKHR*>(mem->allocate(sizeof(VkSurfaceFormatKHR*) * surfaceFormatCount));
|
VkSurfaceFormatKHR* surfaceFormats = reinterpret_cast<VkSurfaceFormatKHR*>(mem->allocate(
|
||||||
|
sizeof( VkSurfaceFormatKHR* ) * surfaceFormatCount ));
|
||||||
vkGetPhysicalDeviceSurfaceFormatsKHR( physicalDeviceInUse, surface, &surfaceFormatCount, surfaceFormats );
|
vkGetPhysicalDeviceSurfaceFormatsKHR( physicalDeviceInUse, surface, &surfaceFormatCount, surfaceFormats );
|
||||||
|
|
||||||
VkSurfaceFormatKHR format = {
|
VkSurfaceFormatKHR format = {
|
||||||
|
|
@ -266,15 +271,18 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
||||||
if ( surfaceFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR )
|
if ( surfaceFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR )
|
||||||
{
|
{
|
||||||
SDL_LogInfo( SDL_LOG_CATEGORY_GPU, "Color Space SRGB Found %d", surfaceFormat.format );
|
SDL_LogInfo( SDL_LOG_CATEGORY_GPU, "Color Space SRGB Found %d", surfaceFormat.format );
|
||||||
if (surfaceFormat.format == VK_FORMAT_R8G8B8A8_SRGB) {
|
if ( surfaceFormat.format == VK_FORMAT_R8G8B8A8_SRGB )
|
||||||
|
{
|
||||||
format = surfaceFormat;
|
format = surfaceFormat;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (surfaceFormat.format == VK_FORMAT_B8G8R8A8_SRGB) {
|
if ( surfaceFormat.format == VK_FORMAT_B8G8R8A8_SRGB )
|
||||||
|
{
|
||||||
format = surfaceFormat;
|
format = surfaceFormat;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (surfaceFormat.format == VK_FORMAT_R8G8B8A8_UNORM) {
|
if ( surfaceFormat.format == VK_FORMAT_R8G8B8A8_UNORM )
|
||||||
|
{
|
||||||
format = surfaceFormat;
|
format = surfaceFormat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -284,7 +292,8 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
||||||
|
|
||||||
uint32_t presentModeCount;
|
uint32_t presentModeCount;
|
||||||
vkGetPhysicalDeviceSurfacePresentModesKHR( physicalDeviceInUse, surface, &presentModeCount, nullptr );
|
vkGetPhysicalDeviceSurfacePresentModesKHR( physicalDeviceInUse, surface, &presentModeCount, nullptr );
|
||||||
VkPresentModeKHR* presentModes = reinterpret_cast<VkPresentModeKHR*>(mem->allocate(sizeof(VkPresentModeKHR*) * presentModeCount));
|
VkPresentModeKHR* presentModes = reinterpret_cast<VkPresentModeKHR*>(mem->allocate(
|
||||||
|
sizeof( VkPresentModeKHR* ) * presentModeCount ));
|
||||||
vkGetPhysicalDeviceSurfacePresentModesKHR( physicalDeviceInUse, surface, &presentModeCount, presentModes );
|
vkGetPhysicalDeviceSurfacePresentModesKHR( physicalDeviceInUse, surface, &presentModeCount, presentModes );
|
||||||
|
|
||||||
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
|
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
|
||||||
|
|
@ -333,7 +342,8 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
||||||
vkGetSwapchainImagesKHR( device, swapchain, &swapchainImageCount, swapchainImages );
|
vkGetSwapchainImagesKHR( device, swapchain, &swapchainImageCount, swapchainImages );
|
||||||
|
|
||||||
swapchainViews = reinterpret_cast<VkImageView*>(mem->allocate( sizeof( VkImageView ) * swapchainImageCount ));
|
swapchainViews = reinterpret_cast<VkImageView*>(mem->allocate( sizeof( VkImageView ) * swapchainImageCount ));
|
||||||
for (uint32_t i = 0; i != swapchainImageCount; ++i) {
|
for ( uint32_t i = 0; i != swapchainImageCount; ++i )
|
||||||
|
{
|
||||||
VkImageViewCreateInfo const viewCreateInfo = {
|
VkImageViewCreateInfo const viewCreateInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
|
|
@ -370,9 +380,20 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
||||||
|
|
||||||
Byte* allocation = mem->allocate( sizeof( RenderDevice ), alignof( RenderDevice ) );
|
Byte* allocation = mem->allocate( sizeof( RenderDevice ), alignof( RenderDevice ) );
|
||||||
return new( allocation ) RenderDevice{
|
return new( allocation ) RenderDevice{
|
||||||
instance, surface, physicalDeviceInUse,
|
instance,
|
||||||
device, gpuAllocator, directQueue, directQueueFamilyIndex.value(),
|
surface,
|
||||||
swapchainFormat, swapchainExtent, swapchain, swapchainImages, swapchainViews, frames, swapchainImageCount,
|
physicalDeviceInUse,
|
||||||
|
device,
|
||||||
|
gpuAllocator,
|
||||||
|
directQueue,
|
||||||
|
directQueueFamilyIndex.value(),
|
||||||
|
swapchainFormat,
|
||||||
|
swapchainExtent,
|
||||||
|
swapchain,
|
||||||
|
swapchainImages,
|
||||||
|
swapchainViews,
|
||||||
|
frames,
|
||||||
|
swapchainImageCount,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -381,14 +402,13 @@ 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 } )
|
||||||
|
|
@ -417,10 +437,21 @@ 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,
|
||||||
|
VkDevice const device,
|
||||||
|
VmaAllocator gpuAllocator,
|
||||||
|
VkQueue const directQueue,
|
||||||
|
uint32_t const directQueueFamilyIndex,
|
||||||
|
VkFormat const swapchainFormat,
|
||||||
|
VkExtent2D const swapchainExtent,
|
||||||
|
VkSwapchainKHR const swapchain,
|
||||||
|
VkImage* swapchainImages,
|
||||||
|
VkImageView* swapchainViews,
|
||||||
|
Frame* frames,
|
||||||
|
uint32_t const swapchainImageCount )
|
||||||
: instance{ instance }
|
: instance{ instance }
|
||||||
, surface{ surface }
|
, surface{ surface }
|
||||||
, physicalDeviceInUse{ physicalDeviceInUse }
|
, physicalDeviceInUse{ physicalDeviceInUse }
|
||||||
|
|
@ -434,6 +465,4 @@ RenderDevice::RenderDevice(VkInstance const instance, VkSurfaceKHR const surface
|
||||||
, swapchainImages{ swapchainImages }
|
, swapchainImages{ swapchainImages }
|
||||||
, swapchainViews{ swapchainViews }
|
, swapchainViews{ swapchainViews }
|
||||||
, frames{ frames }
|
, frames{ frames }
|
||||||
, swapchainImageCount{ swapchainImageCount }
|
, swapchainImageCount{ swapchainImageCount } {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ struct RenderDevice
|
||||||
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;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue