Reformatted + Frame_Create.
This commit is contained in:
parent
fd9ceae67d
commit
d09f725803
|
|
@ -0,0 +1,72 @@
|
|||
---
|
||||
BasedOnStyle: Microsoft
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AlignFunctionPointers: true
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AlignCompound: true
|
||||
AlignFunctionPointers: true
|
||||
PadOperators: true
|
||||
AlignOperands: true
|
||||
AlignTrailingComments:
|
||||
OverEmptyLines: 2
|
||||
AllowShortIfStatementsOnASingleLine: true
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterDefinitionReturnType: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: true
|
||||
AfterClass: true
|
||||
AfterControlStatement: true
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
BeforeLambdaBody: true
|
||||
BeforeWhile: true
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
ConstructorInitializerIndentWidth: 2
|
||||
Cpp11BracedListStyle: false
|
||||
IncludeCategories:
|
||||
- Regex: ^<.*
|
||||
Priority: 1
|
||||
- Regex: ^".*
|
||||
Priority: 2
|
||||
- Regex: .*
|
||||
Priority: 3
|
||||
IncludeIsMainRegex: ([-_](test|unittest))?$
|
||||
IndentCaseLabels: true
|
||||
IndentWidth: 2
|
||||
InsertNewlineAtEOF: true
|
||||
MaxEmptyLinesToKeep: 2
|
||||
PointerAlignment: Left
|
||||
SpaceBeforeParensOptions:
|
||||
AfterOverloadedOperator: true
|
||||
SpacesInAngles: false
|
||||
SpacesInParens: Custom
|
||||
SpacesInParensOptions:
|
||||
InConditionalStatements: true
|
||||
InCStyleCasts: true
|
||||
Other: true
|
||||
TabWidth: 2
|
||||
Language: Cpp
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesInConditionalStatement: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
AlignArrayOfStructures: Right
|
||||
19
AppState.cpp
19
AppState.cpp
|
|
@ -24,31 +24,26 @@ void AppState::destroy()
|
|||
}
|
||||
|
||||
AppState::AppState( SDL_Window* window, RenderDevice* renderDevice, MiscData* miscData )
|
||||
: window{ window }
|
||||
, renderDevice{ renderDevice }
|
||||
, miscData{ miscData } {}
|
||||
: window{ window }, renderDevice{ renderDevice }, miscData{ miscData }, sprintfBuffer{ 0 }
|
||||
{}
|
||||
|
||||
AppState* CreateAppState( GlobalMemory* memory, uint32_t const width, uint32_t const height )
|
||||
AppState* AppState_Create( 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 )
|
||||
{
|
||||
SDL_LogError( SDL_LOG_CATEGORY_APPLICATION, "%s", SDL_GetError() );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto state = memory->getState();
|
||||
RenderDevice* renderDevice = CreateRenderDevice( memory, { .window = window } );
|
||||
RenderDevice* renderDevice = RenderDevice_Create( memory, { .window = window } );
|
||||
if ( !renderDevice->isInit() )
|
||||
{
|
||||
SDL_LogError( SDL_LOG_CATEGORY_APPLICATION, "RenderDevice failed to init" );
|
||||
SDL_DestroyWindow( window );
|
||||
return nullptr;
|
||||
}
|
||||
(void)state;
|
||||
|
||||
auto* miscDataAllocation = memory->allocate( sizeof( MiscData ) );
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
|
||||
struct SDL_Window;
|
||||
|
||||
|
|
@ -13,9 +13,9 @@ struct AppState
|
|||
SDL_Window* window;
|
||||
RenderDevice* renderDevice;
|
||||
MiscData* miscData;
|
||||
char sprintfBuffer[256];
|
||||
|
||||
[[nodiscard]]
|
||||
bool isInit() const;
|
||||
[[nodiscard]] bool isInit() const;
|
||||
void destroy();
|
||||
|
||||
AppState( SDL_Window* window, RenderDevice* renderDevice, MiscData* miscData );
|
||||
|
|
@ -29,4 +29,4 @@ struct AppState
|
|||
~AppState();
|
||||
};
|
||||
|
||||
AppState* CreateAppState( GlobalMemory* memory, uint32_t const width, uint32_t const height );
|
||||
AppState* AppState_Create( GlobalMemory* memory, uint32_t width, uint32_t height );
|
||||
|
|
|
|||
75
Blaze.cpp
75
Blaze.cpp
|
|
@ -9,68 +9,42 @@
|
|||
#include <volk.h>
|
||||
|
||||
#define SDL_MAIN_USE_CALLBACKS 1
|
||||
#include <memory>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <SDL3/SDL_filesystem.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <SDL3/SDL_vulkan.h>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <memory>
|
||||
|
||||
#include "AppState.h"
|
||||
#include "Frame.h"
|
||||
#include "GlobalMemory.h"
|
||||
#include "MacroUtils.h"
|
||||
#include "MathUtil.h"
|
||||
#include "RenderDevice.h"
|
||||
#include "MiscData.h"
|
||||
#include "RenderDevice.h"
|
||||
|
||||
constexpr uint32_t WIDTH = 1280;
|
||||
constexpr uint32_t HEIGHT = 720;
|
||||
constexpr uint32_t NUM_FRAMES = 3;
|
||||
|
||||
using Byte = uint8_t;
|
||||
|
||||
constexpr size_t operator ""_KiB( size_t const value )
|
||||
{
|
||||
return value * 1024;
|
||||
}
|
||||
|
||||
constexpr size_t operator ""_MiB( size_t const value )
|
||||
{
|
||||
return value * 1024_KiB;
|
||||
}
|
||||
|
||||
constexpr size_t operator ""_GiB( size_t const value )
|
||||
{
|
||||
return value * 1024_MiB;
|
||||
}
|
||||
|
||||
namespace Blaze::Global
|
||||
{
|
||||
GlobalMemory g_Memory;
|
||||
}
|
||||
|
||||
SDL_AppResult SDL_AppInit( void** pAppState, int, char** )
|
||||
SDL_AppResult SDL_AppInit( void** appstate, int, char** )
|
||||
{
|
||||
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_EVENTS );
|
||||
|
||||
Blaze::Global::g_Memory.init( 128_MiB );
|
||||
|
||||
*pAppState = CreateAppState( &Blaze::Global::g_Memory, WIDTH, HEIGHT );
|
||||
if ( !*pAppState ) return SDL_APP_FAILURE;
|
||||
|
||||
AppState& appState = *static_cast<AppState*>(*pAppState);
|
||||
|
||||
if ( !appState.isInit() )
|
||||
{
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
*appstate = AppState_Create( &Blaze::Global::g_Memory, WIDTH, HEIGHT );
|
||||
if ( !*appstate ) return SDL_APP_FAILURE;
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
char g_buf[1000];
|
||||
|
||||
SDL_AppResult SDL_AppIterate( void* appstate )
|
||||
{
|
||||
AppState& appState = *static_cast<AppState*>( appstate );
|
||||
|
|
@ -78,14 +52,11 @@ SDL_AppResult SDL_AppIterate( void* appstate )
|
|||
MiscData& misc = *appState.miscData;
|
||||
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.
|
||||
|
||||
// time calc
|
||||
uint64_t const previousCounter = misc.previousCounter;
|
||||
uint64_t const currentCounter = SDL_GetPerformanceCounter();
|
||||
uint64_t const deltaCount = currentCounter - previousCounter;
|
||||
|
|
@ -93,10 +64,13 @@ SDL_AppResult SDL_AppIterate( void* appstate )
|
|||
double const deltaTime = static_cast<double>( deltaCount ) / static_cast<double>( perfFreq );
|
||||
misc.previousCounter = currentCounter;
|
||||
|
||||
{
|
||||
double deltaTimeMs = deltaTime * 1000.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 );
|
||||
( void )sprintf_s<256>(
|
||||
appState.sprintfBuffer, "%.2f fps %.5fms %llu -> %llu", fps, deltaTimeMs, previousCounter, currentCounter );
|
||||
SDL_SetWindowTitle( appState.window, appState.sprintfBuffer );
|
||||
}
|
||||
|
||||
misc.cameraData.modelMatrix = glm::rotate(
|
||||
misc.cameraData.modelMatrix,
|
||||
|
|
@ -105,9 +79,13 @@ SDL_AppResult SDL_AppIterate( void* appstate )
|
|||
memcpy( misc.cameraUniformBufferPtr, &misc.cameraData, sizeof misc.cameraData );
|
||||
|
||||
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( vkResetCommandPool( renderDevice.device, currentFrame.commandPool, 0 ) );
|
||||
|
|
@ -179,14 +157,7 @@ SDL_AppResult SDL_AppIterate( void* appstate )
|
|||
VkDeviceSize constexpr offset = 0;
|
||||
vkCmdBindVertexBuffers( cmd, 0, 1, &misc.vertexBuffer, &offset );
|
||||
vkCmdBindDescriptorSets(
|
||||
cmd,
|
||||
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
misc.pipelineLayout,
|
||||
0,
|
||||
1,
|
||||
&misc.descriptorSet,
|
||||
0,
|
||||
nullptr );
|
||||
cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, misc.pipelineLayout, 0, 1, &misc.descriptorSet, 0, nullptr );
|
||||
vkCmdDraw( cmd, static_cast<uint32_t>( misc.vertices.size() ), 1, 0, 0 );
|
||||
}
|
||||
vkCmdEndRendering( cmd );
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@
|
|||
<ClCompile Include="VmaImpl.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include=".clang-format" />
|
||||
<None Include=".gitignore" />
|
||||
<None Include="PLAN.md">
|
||||
<SubType>
|
||||
|
|
|
|||
|
|
@ -56,6 +56,9 @@
|
|||
<None Include="PLAN.md">
|
||||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
<None Include=".clang-format">
|
||||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="Mesh.slang">
|
||||
|
|
|
|||
63
Frame.cpp
63
Frame.cpp
|
|
@ -10,7 +10,45 @@ bool Frame::isInit() const
|
|||
return static_cast<bool>( commandPool );
|
||||
}
|
||||
|
||||
Frame::Frame( VkDevice const device, uint32_t const directQueueFamilyIndex )
|
||||
Frame::Frame(
|
||||
VkCommandPool const commandPool,
|
||||
VkCommandBuffer const commandBuffer,
|
||||
VkSemaphore const imageAcquiredSemaphore,
|
||||
VkSemaphore const renderFinishedSemaphore,
|
||||
VkFence const frameReadyToReuse )
|
||||
: commandPool{ commandPool }
|
||||
, commandBuffer{ commandBuffer }
|
||||
, imageAcquiredSemaphore{ imageAcquiredSemaphore }
|
||||
, renderFinishedSemaphore{ renderFinishedSemaphore }
|
||||
, frameReadyToReuse{ frameReadyToReuse }
|
||||
{}
|
||||
|
||||
void Frame::destroy( RenderDevice const& renderDevice )
|
||||
{
|
||||
if ( !isInit() ) return;
|
||||
|
||||
VkDevice const device = renderDevice.device;
|
||||
|
||||
vkDestroyCommandPool( device, Take( commandPool ), nullptr );
|
||||
vkDestroyFence( device, Take( frameReadyToReuse ), nullptr );
|
||||
vkDestroySemaphore( device, Take( imageAcquiredSemaphore ), nullptr );
|
||||
vkDestroySemaphore( device, Take( renderFinishedSemaphore ), nullptr );
|
||||
}
|
||||
|
||||
Frame::~Frame()
|
||||
{
|
||||
// Manual Cleanup Required.
|
||||
ASSERT( !isInit() );
|
||||
}
|
||||
|
||||
void Frame_Create( Frame* frame, VkDevice const device, uint32_t const directQueueFamilyIndex )
|
||||
{
|
||||
VkCommandPool commandPool;
|
||||
VkCommandBuffer commandBuffer;
|
||||
VkSemaphore imageAcquiredSemaphore;
|
||||
VkSemaphore renderFinishedSemaphore;
|
||||
VkFence frameReadyToReuse;
|
||||
|
||||
{
|
||||
VkCommandPoolCreateInfo const commandPoolCreateInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
||||
|
|
@ -32,7 +70,7 @@ Frame::Frame( VkDevice const device, uint32_t const directQueueFamilyIndex )
|
|||
VkSemaphoreCreateInfo constexpr semaphoreCreateInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.flags = 0
|
||||
.flags = 0,
|
||||
};
|
||||
VK_CHECK( vkCreateSemaphore( device, &semaphoreCreateInfo, nullptr, &imageAcquiredSemaphore ) );
|
||||
VK_CHECK( vkCreateSemaphore( device, &semaphoreCreateInfo, nullptr, &renderFinishedSemaphore ) );
|
||||
|
|
@ -45,20 +83,9 @@ Frame::Frame( VkDevice const device, uint32_t const directQueueFamilyIndex )
|
|||
VK_CHECK( vkCreateFence( device, &fenceCreateInfo, nullptr, &frameReadyToReuse ) );
|
||||
}
|
||||
|
||||
void Frame::destroy( RenderDevice const& renderDevice )
|
||||
{
|
||||
if ( !isInit() ) return;
|
||||
|
||||
VkDevice const device = renderDevice.device;
|
||||
|
||||
vkDestroyCommandPool( device, Take( commandPool ), nullptr );
|
||||
vkDestroyFence( device, Take( frameReadyToReuse ), nullptr );
|
||||
vkDestroySemaphore( device, Take( imageAcquiredSemaphore ), nullptr );
|
||||
vkDestroySemaphore( device, Take( renderFinishedSemaphore ), nullptr );
|
||||
}
|
||||
|
||||
Frame::~Frame()
|
||||
{
|
||||
// Manual Cleanup Required.
|
||||
ASSERT( not isInit() );
|
||||
frame->commandPool = commandPool;
|
||||
frame->commandBuffer = commandBuffer;
|
||||
frame->imageAcquiredSemaphore = imageAcquiredSemaphore;
|
||||
frame->renderFinishedSemaphore = renderFinishedSemaphore;
|
||||
frame->frameReadyToReuse = frameReadyToReuse;
|
||||
}
|
||||
|
|
|
|||
14
Frame.h
14
Frame.h
|
|
@ -15,9 +15,21 @@ struct Frame
|
|||
|
||||
[[nodiscard]] bool isInit() const;
|
||||
|
||||
Frame( VkDevice device, uint32_t directQueueFamilyIndex );
|
||||
Frame(
|
||||
VkCommandPool commandPool,
|
||||
VkCommandBuffer commandBuffer,
|
||||
VkSemaphore imageAcquiredSemaphore,
|
||||
VkSemaphore renderFinishedSemaphore,
|
||||
VkFence frameReadyToReuse );
|
||||
|
||||
void destroy( RenderDevice const& renderDevice );
|
||||
|
||||
Frame( Frame const& other ) = delete;
|
||||
Frame( Frame&& other ) noexcept = delete;
|
||||
Frame& operator=( Frame const& other ) = delete;
|
||||
Frame& operator=( Frame&& other ) noexcept = delete;
|
||||
|
||||
~Frame();
|
||||
};
|
||||
|
||||
void Frame_Create( Frame* frame, VkDevice device, uint32_t directQueueFamilyIndex );
|
||||
|
|
|
|||
|
|
@ -4,25 +4,26 @@
|
|||
|
||||
void GlobalMemory::init( size_t const size )
|
||||
{
|
||||
memory = new Byte[size];
|
||||
memory = new std::byte[size];
|
||||
capacity = size;
|
||||
available = size;
|
||||
}
|
||||
|
||||
void GlobalMemory::destroy()
|
||||
{
|
||||
Byte const* originalMemory = memory - (capacity - available);
|
||||
std::byte const* originalMemory = memory - ( capacity - available );
|
||||
delete[] originalMemory;
|
||||
|
||||
memory = nullptr;
|
||||
available = 0;
|
||||
capacity = 0;
|
||||
}
|
||||
|
||||
Byte* GlobalMemory::allocate( size_t const size )
|
||||
std::byte* GlobalMemory::allocate( size_t const size )
|
||||
{
|
||||
assert( size <= available && "No enough space available" );
|
||||
|
||||
Byte* retVal = memory;
|
||||
std::byte* retVal = memory;
|
||||
memory += size;
|
||||
available -= size;
|
||||
SDL_LogInfo(
|
||||
|
|
@ -36,7 +37,7 @@ Byte* GlobalMemory::allocate( size_t const size )
|
|||
return retVal;
|
||||
}
|
||||
|
||||
Byte* GlobalMemory::allocate( size_t const size, size_t const alignment )
|
||||
std::byte* GlobalMemory::allocate( size_t const size, size_t const alignment )
|
||||
{
|
||||
uintptr_t const addr = reinterpret_cast<uintptr_t>( memory );
|
||||
uintptr_t const foundOffset = addr % alignment;
|
||||
|
|
|
|||
|
|
@ -4,31 +4,42 @@
|
|||
|
||||
#include "MacroUtils.h"
|
||||
|
||||
using Byte = uint8_t;
|
||||
consteval size_t operator""_KiB( size_t const value )
|
||||
{
|
||||
return value * 1024;
|
||||
}
|
||||
|
||||
consteval size_t operator""_MiB( size_t const value )
|
||||
{
|
||||
return value * 1024_KiB;
|
||||
}
|
||||
|
||||
consteval size_t operator""_GiB( size_t const value )
|
||||
{
|
||||
return value * 1024_MiB;
|
||||
}
|
||||
|
||||
struct GlobalMemory
|
||||
{
|
||||
struct State
|
||||
{
|
||||
Byte* memory;
|
||||
std::byte* memory;
|
||||
size_t available;
|
||||
};
|
||||
|
||||
Byte* memory;
|
||||
std::byte* memory;
|
||||
size_t available;
|
||||
size_t capacity;
|
||||
|
||||
void init( size_t size );
|
||||
|
||||
void destroy();
|
||||
|
||||
Byte* allocate( size_t size );
|
||||
[[nodiscard]]
|
||||
std::byte* allocate( size_t size );
|
||||
[[nodiscard]]
|
||||
std::byte* allocate( size_t size, size_t alignment );
|
||||
|
||||
Byte* allocate( size_t size, size_t alignment );
|
||||
|
||||
// Do not do any permanent allocations after calling this.
|
||||
[[nodiscard]] State getState() const;
|
||||
|
||||
// Call this before permanent allocations.
|
||||
void restoreState( State const& state );
|
||||
[[nodiscard]]
|
||||
State getState() const; //< Do not do any permanent allocations after calling this.
|
||||
void restoreState( State const& state ); //< Call this before permanent allocations.
|
||||
};
|
||||
|
|
|
|||
25
MacroUtils.h
25
MacroUtils.h
|
|
@ -1,29 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <utility>
|
||||
|
||||
#define G_ASSERT( COND ) \
|
||||
do { \
|
||||
do \
|
||||
{ \
|
||||
auto _result = ( COND ); \
|
||||
if (not _result) { \
|
||||
if ( not _result ) \
|
||||
{ \
|
||||
__debugbreak(); \
|
||||
assert( _result&& #COND ); \
|
||||
} \
|
||||
} while(false)
|
||||
} \
|
||||
while ( false )
|
||||
|
||||
#define ASSERT( COND ) G_ASSERT( COND )
|
||||
|
||||
#define VK_CHECK( RESULT ) \
|
||||
do { \
|
||||
do \
|
||||
{ \
|
||||
auto _result = ( RESULT ); \
|
||||
if (_result != VK_SUCCESS) { \
|
||||
SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, \
|
||||
"" #RESULT " failed with %d at %s:%d", \
|
||||
_result, __FILE__, __LINE__); \
|
||||
if ( _result != VK_SUCCESS ) \
|
||||
{ \
|
||||
SDL_LogError( SDL_LOG_CATEGORY_SYSTEM, "" #RESULT " failed with %d at %s:%d", _result, __FILE__, __LINE__ ); \
|
||||
__debugbreak(); \
|
||||
assert(_result == VK_SUCCESS); \
|
||||
exit( _result ); \
|
||||
} \
|
||||
} while(false)
|
||||
} \
|
||||
while ( false )
|
||||
|
||||
#define Take( OBJ ) std::exchange( OBJ, {} )
|
||||
|
|
|
|||
56
MiscData.cpp
56
MiscData.cpp
|
|
@ -1,7 +1,7 @@
|
|||
#include "MiscData.h"
|
||||
|
||||
#include <array>
|
||||
#include <SDL3/SDL_log.h>
|
||||
#include <array>
|
||||
|
||||
#include "MacroUtils.h"
|
||||
#include "RenderDevice.h"
|
||||
|
|
@ -25,9 +25,9 @@ void MiscData::init( RenderDevice const& renderDevice )
|
|||
SDL_LogError( SDL_LOG_CATEGORY_SYSTEM, "%s", SDL_GetError() );
|
||||
abort();
|
||||
}
|
||||
uint32_t const* data = static_cast<uint32_t const*>( rawData );
|
||||
|
||||
auto data = static_cast<uint32_t const*>(rawData);
|
||||
|
||||
// Create Shader Module
|
||||
VkShaderModuleCreateInfo const shaderModuleCreateInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
|
|
@ -88,6 +88,7 @@ void MiscData::init( RenderDevice const& renderDevice )
|
|||
}
|
||||
};
|
||||
|
||||
// Bindings
|
||||
VkVertexInputBindingDescription constexpr bindingDescription = {
|
||||
.binding = 0,
|
||||
.stride = sizeof( Vertex ),
|
||||
|
|
@ -195,10 +196,8 @@ void MiscData::init( RenderDevice const& renderDevice )
|
|||
.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,
|
||||
.colorWriteMask =
|
||||
VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
|
||||
};
|
||||
|
||||
VkPipelineColorBlendStateCreateInfo const colorBlendState = {
|
||||
|
|
@ -212,10 +211,7 @@ void MiscData::init( RenderDevice const& renderDevice )
|
|||
.blendConstants = { 0.0f, 0.0f, 0.0f, 0.0f },
|
||||
};
|
||||
|
||||
std::array constexpr dynamicStates = {
|
||||
VK_DYNAMIC_STATE_VIEWPORT,
|
||||
VK_DYNAMIC_STATE_SCISSOR
|
||||
};
|
||||
std::array constexpr dynamicStates = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
|
||||
|
||||
VkPipelineDynamicStateCreateInfo const dynamicStateCreateInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
||||
|
|
@ -308,8 +304,7 @@ void MiscData::init( RenderDevice const& renderDevice )
|
|||
};
|
||||
|
||||
VmaAllocationCreateInfo constexpr allocationCreateInfo = {
|
||||
.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT |
|
||||
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
|
||||
.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,
|
||||
|
|
@ -321,8 +316,7 @@ void MiscData::init( RenderDevice const& renderDevice )
|
|||
|
||||
VmaAllocationInfo allocationInfo;
|
||||
|
||||
VK_CHECK(
|
||||
vmaCreateBuffer(
|
||||
VK_CHECK( vmaCreateBuffer(
|
||||
renderDevice.gpuAllocator,
|
||||
&bufferCreateInfo,
|
||||
&allocationCreateInfo,
|
||||
|
|
@ -358,8 +352,7 @@ void MiscData::init( RenderDevice const& renderDevice )
|
|||
};
|
||||
|
||||
VmaAllocationCreateInfo constexpr allocationCreateInfo = {
|
||||
.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT |
|
||||
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
|
||||
.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,
|
||||
|
|
@ -371,8 +364,7 @@ void MiscData::init( RenderDevice const& renderDevice )
|
|||
|
||||
VmaAllocationInfo allocationInfo;
|
||||
|
||||
VK_CHECK(
|
||||
vmaCreateBuffer(
|
||||
VK_CHECK( vmaCreateBuffer(
|
||||
renderDevice.gpuAllocator,
|
||||
&bufferCreateInfo,
|
||||
&allocationCreateInfo,
|
||||
|
|
@ -438,6 +430,14 @@ void MiscData::init( RenderDevice const& renderDevice )
|
|||
|
||||
// Barrier Creation
|
||||
{
|
||||
VkImageSubresourceRange subresourceRange = {
|
||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
};
|
||||
|
||||
acquireToRenderBarrier = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
|
||||
.pNext = nullptr,
|
||||
|
|
@ -449,14 +449,9 @@ void MiscData::init( RenderDevice const& renderDevice )
|
|||
.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,
|
||||
}
|
||||
.subresourceRange = subresourceRange,
|
||||
};
|
||||
|
||||
acquireToRenderDependency = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
|
||||
.pNext = nullptr,
|
||||
|
|
@ -480,14 +475,9 @@ void MiscData::init( RenderDevice const& renderDevice )
|
|||
.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,
|
||||
}
|
||||
.subresourceRange = subresourceRange,
|
||||
};
|
||||
|
||||
renderToPresentDependency = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
|
||||
.pNext = nullptr,
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@ RenderDevice::~RenderDevice()
|
|||
}
|
||||
|
||||
// TODO: Failure Handling
|
||||
RenderDevice* CreateRenderDevice( GlobalMemory* mem, RenderDevice::CreateInfo const& createInfo )
|
||||
RenderDevice* RenderDevice_Create( GlobalMemory* mem, RenderDevice::CreateInfo const& createInfo )
|
||||
{
|
||||
ASSERT( mem );
|
||||
ASSERT( createInfo.window );
|
||||
|
||||
volkInitialize();
|
||||
|
|
@ -72,8 +73,8 @@ RenderDevice* CreateRenderDevice( GlobalMemory* mem, RenderDevice::CreateInfo co
|
|||
VK_CHECK( vkEnumeratePhysicalDevices( instance, &physicalDeviceCount, nullptr ) );
|
||||
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 ) );
|
||||
|
||||
for ( VkPhysicalDevice const physicalDevice : std::span{ physicalDevices, physicalDeviceCount } )
|
||||
|
|
@ -105,12 +106,11 @@ RenderDevice* CreateRenderDevice( GlobalMemory* mem, RenderDevice::CreateInfo co
|
|||
|
||||
uint32_t queueFamilyCount;
|
||||
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 );
|
||||
|
||||
for ( uint32_t queueFamilyIndex = 0; queueFamilyIndex != queueFamilyCount;
|
||||
++queueFamilyIndex )
|
||||
for ( uint32_t queueFamilyIndex = 0; queueFamilyIndex != queueFamilyCount; ++queueFamilyIndex )
|
||||
{
|
||||
VkQueueFamilyProperties const& qfp = queueFamilyProperties[queueFamilyIndex];
|
||||
|
||||
|
|
@ -182,9 +182,7 @@ RenderDevice* CreateRenderDevice( GlobalMemory* mem, RenderDevice::CreateInfo co
|
|||
.samplerAnisotropy = true,
|
||||
};
|
||||
|
||||
std::array enabledDeviceExtensions = {
|
||||
VK_KHR_SWAPCHAIN_EXTENSION_NAME
|
||||
};
|
||||
std::array enabledDeviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME };
|
||||
|
||||
VkDeviceCreateInfo const deviceCreateInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
||||
|
|
@ -258,8 +256,8 @@ RenderDevice* CreateRenderDevice( GlobalMemory* mem, RenderDevice::CreateInfo co
|
|||
|
||||
uint32_t surfaceFormatCount;
|
||||
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 );
|
||||
|
||||
VkSurfaceFormatKHR format = {
|
||||
|
|
@ -292,8 +290,8 @@ RenderDevice* CreateRenderDevice( GlobalMemory* mem, RenderDevice::CreateInfo co
|
|||
|
||||
uint32_t presentModeCount;
|
||||
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 );
|
||||
|
||||
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
|
||||
|
|
@ -375,10 +373,10 @@ RenderDevice* CreateRenderDevice( GlobalMemory* mem, RenderDevice::CreateInfo co
|
|||
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_Create( frames + i, device, directQueueFamilyIndex.value() );
|
||||
}
|
||||
|
||||
Byte* allocation = mem->allocate( sizeof( RenderDevice ), alignof( RenderDevice ) );
|
||||
std::byte* allocation = mem->allocate( sizeof( RenderDevice ), alignof( RenderDevice ) );
|
||||
return new ( allocation ) RenderDevice{
|
||||
instance,
|
||||
surface,
|
||||
|
|
@ -466,4 +464,5 @@ RenderDevice::RenderDevice(
|
|||
, swapchainImages{ swapchainImages }
|
||||
, swapchainViews{ swapchainViews }
|
||||
, frames{ frames }
|
||||
, swapchainImageCount{ swapchainImageCount } {}
|
||||
, swapchainImageCount{ swapchainImageCount }
|
||||
{}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ struct RenderDevice
|
|||
VmaAllocator gpuAllocator,
|
||||
VkQueue directQueue,
|
||||
uint32_t directQueueFamilyIndex,
|
||||
// TODO: Pack?
|
||||
|
||||
VkFormat swapchainFormat,
|
||||
VkExtent2D swapchainExtent,
|
||||
|
|
@ -65,8 +64,7 @@ struct RenderDevice
|
|||
VkImage* swapchainImages,
|
||||
VkImageView* swapchainViews,
|
||||
Frame* frames,
|
||||
uint32_t swapchainImageCount
|
||||
);
|
||||
uint32_t swapchainImageCount );
|
||||
|
||||
RenderDevice( RenderDevice const& ) = delete;
|
||||
RenderDevice& operator=( RenderDevice const& ) = delete;
|
||||
|
|
@ -77,4 +75,4 @@ struct RenderDevice
|
|||
~RenderDevice();
|
||||
};
|
||||
|
||||
RenderDevice* CreateRenderDevice( GlobalMemory* mem, RenderDevice::CreateInfo const& createInfo );
|
||||
RenderDevice* RenderDevice_Create( GlobalMemory* mem, RenderDevice::CreateInfo const& createInfo );
|
||||
|
|
|
|||
Loading…
Reference in New Issue