Meshrenderer first step. Adding logs to debug a weird crash since the add of mesh renderer and some clean up.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <Graphics/GraphicsConfig.h>
|
||||
#include <Graphics/GraphicsPipeline.h>
|
||||
#include <Graphics/Mesh.h>
|
||||
#include <Graphics/MeshRenderer.h>
|
||||
#include <Graphics/RenderPass.h>
|
||||
#include <Graphics/VertexData.h>
|
||||
#include <Juliet.h>
|
||||
@@ -63,6 +64,8 @@ namespace
|
||||
} Game;
|
||||
|
||||
const char* GameFunctionTable[] = { "GameInit", "GameShutdown", "GameUpdate" };
|
||||
|
||||
Arena* PlatformArena = nullptr;
|
||||
} // namespace
|
||||
|
||||
void JulietApplication::Init()
|
||||
@@ -71,6 +74,8 @@ void JulietApplication::Init()
|
||||
|
||||
Log(LogLevel::Message, LogCategory::Tool, "%s", CStr(GetBasePath()));
|
||||
|
||||
PlatformArena = ArenaAllocate({ .AllowRealloc = true } JULIET_DEBUG_PARAM("Platform Arena"));
|
||||
|
||||
GraphicsConfig config;
|
||||
#if JULIET_DEBUG
|
||||
config.EnableDebug = true;
|
||||
@@ -85,42 +90,7 @@ void JulietApplication::Init()
|
||||
{
|
||||
AttachToWindow(GraphicsDevice, MainWindow);
|
||||
{
|
||||
// Create graphics pipeline
|
||||
String entryPoint = WrapString("main");
|
||||
ShaderCreateInfo shaderCI = {};
|
||||
shaderCI.EntryPoint = entryPoint;
|
||||
|
||||
// TODO: Assets management that handles path to assets or something.
|
||||
String shaderPath = WrapString("../../Assets/compiled/Triangle.vert.dxil");
|
||||
shaderCI.Stage = ShaderStage::Vertex;
|
||||
Shader* vertexShader = CreateShader(GraphicsDevice, shaderPath, shaderCI);
|
||||
|
||||
shaderPath = WrapString("../../Assets/compiled/SolidColor.frag.dxil");
|
||||
shaderCI.Stage = ShaderStage::Fragment;
|
||||
Shader* fragmentShader = CreateShader(GraphicsDevice, shaderPath, shaderCI);
|
||||
|
||||
ColorTargetDescription colorTargetDescription = {};
|
||||
colorTargetDescription.Format = GetSwapChainTextureFormat(GraphicsDevice, MainWindow);
|
||||
|
||||
GraphicsPipelineCreateInfo pipelineCI = {};
|
||||
pipelineCI.VertexShader = vertexShader;
|
||||
pipelineCI.FragmentShader = fragmentShader;
|
||||
pipelineCI.PrimitiveType = PrimitiveType::TriangleList;
|
||||
pipelineCI.TargetInfo = { .ColorTargetDescriptions = &colorTargetDescription,
|
||||
.NumColorTargets = 1,
|
||||
.DepthStencilFormat = TextureFormat::D32_FLOAT,
|
||||
.HasDepthStencilTarget = true };
|
||||
pipelineCI.RasterizerState.FillMode = FillMode::Solid;
|
||||
pipelineCI.DepthStencilState.EnableDepthTest = true;
|
||||
pipelineCI.DepthStencilState.EnableDepthWrite = true;
|
||||
pipelineCI.DepthStencilState.CompareOperation = CompareOperation::Less;
|
||||
|
||||
GraphicsPipeline = CreateGraphicsPipeline(GraphicsDevice, pipelineCI);
|
||||
if (GraphicsPipeline == nullptr)
|
||||
{
|
||||
LogError(LogCategory::Game, "Failed to create graphics pipeline!");
|
||||
Running = false;
|
||||
}
|
||||
Running = InitializeMeshRenderer(PlatformArena, GraphicsDevice, MainWindow);
|
||||
|
||||
// Create Depth Buffer
|
||||
TextureCreateInfo depthCI = {};
|
||||
@@ -139,50 +109,11 @@ void JulietApplication::Init()
|
||||
Running = false;
|
||||
}
|
||||
|
||||
// Create Buffers - Using StructuredBuffer for bindless SRV access in shader
|
||||
BufferCreateInfo bufferCI = {};
|
||||
bufferCI.Size = 1024;
|
||||
bufferCI.Usage = BufferUsage::StructuredBuffer; // SRV for ResourceDescriptorHeap access
|
||||
StructuredBuffer = CreateGraphicsBuffer(GraphicsDevice, bufferCI);
|
||||
|
||||
TransferBufferCreateInfo transferCI = {};
|
||||
transferCI.Size = 1024;
|
||||
transferCI.Usage = TransferBufferUsage::Upload;
|
||||
TransferBuffer = CreateGraphicsTransferBuffer(GraphicsDevice, transferCI);
|
||||
|
||||
// Upload Static Data for Test
|
||||
if (TransferBuffer && StructuredBuffer)
|
||||
{
|
||||
void* data = MapGraphicsTransferBuffer(GraphicsDevice, TransferBuffer);
|
||||
if (data)
|
||||
{
|
||||
Matrix projection = PerspectiveFov(60.0f * (3.14159f / 180.0f), 1200.0f / 800.0f, 0.1f, 1000.0f);
|
||||
Matrix view = LookAt({ 30.0f, 0.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f });
|
||||
Matrix model = Matrix::Identity();
|
||||
Matrix mvp = projection * view * model;
|
||||
|
||||
MemCopy(data, &mvp, sizeof(Matrix));
|
||||
UnmapGraphicsTransferBuffer(GraphicsDevice, TransferBuffer);
|
||||
|
||||
CommandList* initCmd = AcquireCommandList(GraphicsDevice);
|
||||
CopyBuffer(initCmd, StructuredBuffer, TransferBuffer, 256);
|
||||
TransitionBufferToReadable(initCmd, StructuredBuffer);
|
||||
SubmitCommandLists(initCmd);
|
||||
}
|
||||
}
|
||||
|
||||
CubeArena = ArenaAllocate({ .ReserveSize = Kilobytes(1llu), .CommitSize = Kilobytes(1llu) } JULIET_DEBUG_PARAM("CubeArena"));
|
||||
CubeMesh = CreateCubeMesh(CubeArena);
|
||||
// CubeMesh = CreateQuadMesh(CubeArena);
|
||||
|
||||
if (vertexShader)
|
||||
{
|
||||
DestroyShader(GraphicsDevice, vertexShader);
|
||||
}
|
||||
if (fragmentShader)
|
||||
{
|
||||
DestroyShader(GraphicsDevice, fragmentShader);
|
||||
}
|
||||
// std::ignore = AddCube();
|
||||
//
|
||||
// CommandList* loadCmd = AcquireCommandList(GraphicsDevice);
|
||||
// LoadMeshesOnGPU(loadCmd);
|
||||
// SubmitCommandLists(loadCmd);
|
||||
|
||||
if (Running == false)
|
||||
{
|
||||
@@ -208,8 +139,6 @@ void JulietApplication::Shutdown()
|
||||
{
|
||||
Log(LogLevel::Message, LogCategory::Tool, "Shutting down Juliet Application...");
|
||||
|
||||
ArenaRelease(CubeArena);
|
||||
|
||||
if (GameCode.IsValid)
|
||||
{
|
||||
Game.Shutdown();
|
||||
@@ -220,19 +149,14 @@ void JulietApplication::Shutdown()
|
||||
{
|
||||
DestroyGraphicsPipeline(GraphicsDevice, GraphicsPipeline);
|
||||
}
|
||||
if (StructuredBuffer)
|
||||
{
|
||||
DestroyGraphicsBuffer(GraphicsDevice, StructuredBuffer);
|
||||
}
|
||||
if (TransferBuffer)
|
||||
{
|
||||
DestroyGraphicsTransferBuffer(GraphicsDevice, TransferBuffer);
|
||||
}
|
||||
|
||||
if (DepthBuffer)
|
||||
{
|
||||
DestroyTexture(GraphicsDevice, DepthBuffer);
|
||||
}
|
||||
|
||||
ShutdownMeshRenderer();
|
||||
|
||||
if (MainWindow && GraphicsDevice)
|
||||
{
|
||||
DetachFromWindow(GraphicsDevice, MainWindow);
|
||||
@@ -248,6 +172,8 @@ void JulietApplication::Shutdown()
|
||||
DestroyGraphicsDevice(GraphicsDevice);
|
||||
}
|
||||
|
||||
ArenaRelease(PlatformArena);
|
||||
|
||||
Log(LogLevel::Message, LogCategory::Tool, "Juliet App shutdown Completed");
|
||||
}
|
||||
|
||||
@@ -281,7 +207,7 @@ void JulietApplication::Update()
|
||||
}
|
||||
|
||||
#ifdef JULIET_ENABLE_IMGUI
|
||||
ImGui::ShowDemoWindow();
|
||||
// ImGui::ShowDemoWindow();
|
||||
#endif
|
||||
|
||||
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f }, false);
|
||||
@@ -301,27 +227,7 @@ void JulietApplication::Update()
|
||||
WaitUntilGPUIsIdle(GraphicsDevice);
|
||||
|
||||
#if ALLOW_SHADER_HOT_RELOAD
|
||||
String entryPoint = WrapString("main");
|
||||
ShaderCreateInfo shaderCI = {};
|
||||
shaderCI.EntryPoint = entryPoint;
|
||||
String shaderPath = WrapString("../../Assets/compiled/Triangle.vert.dxil");
|
||||
shaderCI.Stage = ShaderStage::Vertex;
|
||||
Shader* vertexShader = CreateShader(GraphicsDevice, shaderPath, shaderCI);
|
||||
|
||||
shaderPath = WrapString("../../Assets/compiled/SolidColor.frag.dxil");
|
||||
shaderCI.Stage = ShaderStage::Fragment;
|
||||
Shader* fragmentShader = CreateShader(GraphicsDevice, shaderPath, shaderCI);
|
||||
|
||||
UpdateGraphicsPipelineShaders(GraphicsDevice, GraphicsPipeline, vertexShader, fragmentShader);
|
||||
|
||||
if (vertexShader)
|
||||
{
|
||||
DestroyShader(GraphicsDevice, vertexShader);
|
||||
}
|
||||
if (fragmentShader)
|
||||
{
|
||||
DestroyShader(GraphicsDevice, fragmentShader);
|
||||
}
|
||||
ReloadMeshRendererShaders();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -361,76 +267,16 @@ void JulietApplication::Update()
|
||||
ArenaClear(GameScratchArena);
|
||||
}
|
||||
|
||||
void JulietApplication::OnPreRender(CommandList* cmd)
|
||||
void JulietApplication::OnPreRender(CommandList* /*cmd*/) {}
|
||||
|
||||
void JulietApplication::OnRender(RenderPass*, CommandList*)
|
||||
{
|
||||
index_t index = 0;
|
||||
// PushData pushData = {};
|
||||
// pushData.ViewProjection = Camera_GetViewProjectionMatrix(GetDebugCamera());
|
||||
|
||||
// Buffer uploads
|
||||
if (StructuredBuffer && TransferBuffer)
|
||||
{
|
||||
void* ptr = MapGraphicsTransferBuffer(GraphicsDevice, TransferBuffer);
|
||||
if (ptr)
|
||||
{
|
||||
Vertex* vertices = static_cast<Vertex*>(ptr);
|
||||
// RenderMeshes(pass, cmd, pushData);
|
||||
|
||||
// // Triangle 1
|
||||
// vertices[index++] = { { -0.5f, -0.5f, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } }; // Red
|
||||
// vertices[index++] = { { 0.0f, 0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } }; // Green
|
||||
// vertices[index++] = { { 0.5f, -0.5f, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } }; // Blue
|
||||
//
|
||||
// // Triangle 2
|
||||
// vertices[index++] = { { -0.5f, 0.5f, 0.0f }, { 1.0f, 1.0f, 0.0f, 1.0f } }; // Yellow
|
||||
// vertices[index++] = { { 0.0f, 0.8f, 0.0f }, { 0.0f, 1.0f, 1.0f, 1.0f } }; // Cyan
|
||||
// vertices[index++] = { { 0.5f, 0.5f, 0.0f }, { 1.0f, 0.0f, 1.0f, 1.0f } }; // Magenta
|
||||
|
||||
if (CubeMesh)
|
||||
{
|
||||
CubeMesh->VertexOffset = index;
|
||||
size_t vertexSize = CubeMesh->VertexCount * sizeof(Vertex);
|
||||
MemCopy(vertices + index, CubeMesh->Vertices, vertexSize);
|
||||
|
||||
CubeMesh->IndexByteOffset = (index + CubeMesh->VertexCount) * sizeof(Vertex);
|
||||
// Align
|
||||
CubeMesh->IndexByteOffset = (CubeMesh->IndexByteOffset + 255) & static_cast<size_t>(~255);
|
||||
|
||||
size_t indexSize = CubeMesh->IndexCount * sizeof(uint16);
|
||||
|
||||
CubeMesh->IndexOffset = 0;
|
||||
|
||||
uint8* ptrOneByte = static_cast<uint8*>(ptr);
|
||||
uint16* dst = reinterpret_cast<uint16*>(ptrOneByte + CubeMesh->IndexByteOffset);
|
||||
MemCopy(dst, CubeMesh->Indices, indexSize);
|
||||
}
|
||||
|
||||
UnmapGraphicsTransferBuffer(GraphicsDevice, TransferBuffer);
|
||||
}
|
||||
|
||||
CopyBuffer(cmd, StructuredBuffer, TransferBuffer, CubeMesh->IndexByteOffset + (CubeMesh->IndexCount * sizeof(uint16)));
|
||||
TransitionBufferToReadable(cmd, StructuredBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void JulietApplication::OnRender(RenderPass* pass, CommandList* cmd)
|
||||
{
|
||||
BindGraphicsPipeline(pass, GraphicsPipeline);
|
||||
|
||||
uint32 descriptorIndex = GetDescriptorIndex(GraphicsDevice, StructuredBuffer);
|
||||
|
||||
struct PushData
|
||||
{
|
||||
Matrix ViewProjection;
|
||||
uint32 BufferIndex;
|
||||
} pushData = {};
|
||||
pushData.BufferIndex = descriptorIndex;
|
||||
pushData.ViewProjection = Camera_GetViewProjectionMatrix(GetDebugCamera());
|
||||
|
||||
SetPushConstants(cmd, ShaderStage::Vertex, 0, sizeof(pushData) / 4, &pushData);
|
||||
|
||||
SetIndexBuffer(cmd, StructuredBuffer, IndexFormat::UInt16, CubeMesh->IndexCount, CubeMesh->IndexByteOffset);
|
||||
// DrawIndexedPrimitives(pass, static_cast<uint32>(CubeMesh->IndexCount), 1, 0, 0, 0);
|
||||
|
||||
DrawIndexedPrimitives(pass, static_cast<uint32>(CubeMesh->IndexCount), 1,
|
||||
static_cast<uint32>(CubeMesh->IndexOffset), static_cast<uint32>(CubeMesh->VertexOffset), 0);
|
||||
// SetPushConstants(cmd, ShaderStage::Vertex, 0, sizeof(pushData) / 4, &pushData);
|
||||
}
|
||||
|
||||
ColorTargetInfo JulietApplication::GetColorTargetInfo(Texture* swapchainTexture)
|
||||
|
||||
@@ -38,19 +38,13 @@ class JulietApplication : public Juliet::IApplication
|
||||
int GetAutoCloseFrameCount() const { return AutoCloseFrameCount; }
|
||||
|
||||
private:
|
||||
Juliet::Window* MainWindow = {};
|
||||
Juliet::GraphicsDevice* GraphicsDevice = {};
|
||||
Juliet::HotReloadCode GameCode = {};
|
||||
Juliet::GraphicsPipeline* GraphicsPipeline = {};
|
||||
Juliet::GraphicsBuffer* StructuredBuffer = {};
|
||||
Juliet::GraphicsTransferBuffer* TransferBuffer = {};
|
||||
Juliet::Texture* DepthBuffer = {};
|
||||
|
||||
Juliet::Mesh* CubeMesh = {};
|
||||
Juliet::Arena* CubeArena = nullptr;
|
||||
|
||||
Juliet::Arena* GameArena = nullptr;
|
||||
Juliet::Arena* GameScratchArena = nullptr;
|
||||
Juliet::Window* MainWindow = {};
|
||||
Juliet::GraphicsDevice* GraphicsDevice = {};
|
||||
Juliet::HotReloadCode GameCode = {};
|
||||
Juliet::GraphicsPipeline* GraphicsPipeline = {};
|
||||
Juliet::Texture* DepthBuffer = {};
|
||||
Juliet::Arena* GameArena = nullptr;
|
||||
Juliet::Arena* GameScratchArena = nullptr;
|
||||
|
||||
int AutoCloseFrameCount = -1;
|
||||
bool Running = false;
|
||||
|
||||
Reference in New Issue
Block a user