diff --git a/Juliet/include/Core/HAL/Filesystem/Filesystem.h b/Juliet/include/Core/HAL/Filesystem/Filesystem.h index 8fabbe5..69ac737 100644 --- a/Juliet/include/Core/HAL/Filesystem/Filesystem.h +++ b/Juliet/include/Core/HAL/Filesystem/Filesystem.h @@ -10,11 +10,11 @@ namespace Juliet // Returns the resolved base path to the compiled shaders directory. // In dev, this resolves to ../../Assets/compiled/ relative to the exe. // In shipping, this resolves to Assets/Shaders/ next to the exe. - [[nodiscard]] extern JULIET_API String GetAssetBasePath(); + [[nodiscard]] extern JULIET_API String GetAssetBasePath(); // Builds a full path to an asset file given its filename (e.g. "Triangle.vert.dxil"). // The caller owns the returned buffer and must free it. - [[nodiscard]] extern JULIET_API String GetAssetPath(String filename); + [[nodiscard]] extern JULIET_API String GetAssetPath(NonNullPtr arena, String filename); - [[nodiscard]]extern JULIET_API bool IsAbsolutePath(String path); + [[nodiscard]] extern JULIET_API bool IsAbsolutePath(String path); } // namespace Juliet diff --git a/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp b/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp index e5e8f66..8586b83 100644 --- a/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp +++ b/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp @@ -36,17 +36,14 @@ namespace Juliet return CachedAssetBasePath; } - [[nodiscard]] String GetAssetPath(String filename) + [[nodiscard]] String GetAssetPath(NonNullPtr arena, String filename) { Assert(IsValid(CachedAssetBasePath)); Assert(IsValid(filename)); size_t totalSize = CachedAssetBasePath.Size + filename.Size + 1; - auto* buffer = static_cast(Calloc(totalSize, sizeof(char))); - if (!buffer) - { - return {}; - } + char* buffer = ArenaPushArray(arena, totalSize); + Assert(buffer); juliet_snprintf(buffer, totalSize, "%s%s", CStr(CachedAssetBasePath), CStr(filename)); return { buffer, totalSize - 1 }; diff --git a/Juliet/src/Graphics/DebugDisplayRenderer.cpp b/Juliet/src/Graphics/DebugDisplayRenderer.cpp index 147bce2..ecd9183 100644 --- a/Juliet/src/Graphics/DebugDisplayRenderer.cpp +++ b/Juliet/src/Graphics/DebugDisplayRenderer.cpp @@ -1,9 +1,10 @@ #include +#include #include #include -#include #include +#include #include #include @@ -86,14 +87,18 @@ namespace Juliet ShaderCreateInfo shaderCI = {}; shaderCI.EntryPoint = entryPoint; - String vertPath = GetAssetPath(WrapString("Debug.vert.dxil")); + TempArena path = scratch_begin(0, 0); + + String vertPath = GetAssetPath(path.Arena, WrapString("Debug.vert.dxil")); shaderCI.Stage = ShaderStage::Vertex; Shader* vertexShader = CreateShader(device, vertPath, shaderCI); - String fragPath = GetAssetPath(WrapString("Debug.frag.dxil")); + String fragPath = GetAssetPath(path.Arena, WrapString("Debug.frag.dxil")); shaderCI.Stage = ShaderStage::Fragment; Shader* fragmentShader = CreateShader(device, fragPath, shaderCI); + scratch_end(path); + if (!vertexShader || !fragmentShader) { LogError(LogCategory::Graphics, "Failed to create debug shaders"); @@ -303,21 +308,23 @@ namespace Juliet BindGraphicsPipeline(renderPass, g_DebugState.DepthTestedPipeline); // Pack VP matrix + buffer index into push constants - PushData pushData = {}; - pushData.ViewProjection = Camera_GetViewProjectionMatrix(camera); - pushData.MeshIndex = 0; + PushData pushData = {}; + pushData.ViewProjection = Camera_GetViewProjectionMatrix(camera); + pushData.MeshIndex = 0; pushData.TransformsBufferIndex = 0; // Not used by debug shader but layout must match - pushData.BufferIndex = bufferIndex; - pushData.TextureIndex = 0; - pushData.VertexOffset = 0; // Depth-tested vertices start at 0 - pushData.Scale[0] = 1.0f; pushData.Scale[1] = 1.0f; - pushData.Translate[0] = 0.0f; pushData.Translate[1] = 0.0f; - + pushData.BufferIndex = bufferIndex; + pushData.TextureIndex = 0; + pushData.VertexOffset = 0; // Depth-tested vertices start at 0 + pushData.Scale[0] = 1.0f; + pushData.Scale[1] = 1.0f; + pushData.Translate[0] = 0.0f; + pushData.Translate[1] = 0.0f; + // Dummy light data as we don't light debug primitives - pushData.GlobalLightDirection = {0,0,-1}; - pushData.GlobalLightColor = {1,1,1}; + pushData.GlobalLightDirection = { 0, 0, -1 }; + pushData.GlobalLightColor = { 1, 1, 1 }; pushData.GlobalAmbientIntensity = 1.0f; - + SetPushConstants(cmdList, ShaderStage::Vertex, 0, sizeof(pushData) / sizeof(uint32), &pushData); DrawPrimitives(renderPass, g_DebugState.DepthTestedVertexCount, 1, 0, 0); @@ -329,21 +336,23 @@ namespace Juliet BindGraphicsPipeline(renderPass, g_DebugState.OverlayPipeline); // Pack VP matrix + buffer index into push constants - PushData pushData = {}; - pushData.ViewProjection = Camera_GetViewProjectionMatrix(camera); - pushData.MeshIndex = 0; + PushData pushData = {}; + pushData.ViewProjection = Camera_GetViewProjectionMatrix(camera); + pushData.MeshIndex = 0; pushData.TransformsBufferIndex = 0; - pushData.BufferIndex = bufferIndex; - pushData.TextureIndex = 0; - pushData.VertexOffset = kMaxDebugVertices / 2; // Overlay vertices start at half - pushData.Scale[0] = 1.0f; pushData.Scale[1] = 1.0f; - pushData.Translate[0] = 0.0f; pushData.Translate[1] = 0.0f; - + pushData.BufferIndex = bufferIndex; + pushData.TextureIndex = 0; + pushData.VertexOffset = kMaxDebugVertices / 2; // Overlay vertices start at half + pushData.Scale[0] = 1.0f; + pushData.Scale[1] = 1.0f; + pushData.Translate[0] = 0.0f; + pushData.Translate[1] = 0.0f; + // Dummy light data as we don't light debug primitives - pushData.GlobalLightDirection = {0,0,-1}; - pushData.GlobalLightColor = {1,1,1}; + pushData.GlobalLightDirection = { 0, 0, -1 }; + pushData.GlobalLightColor = { 1, 1, 1 }; pushData.GlobalAmbientIntensity = 1.0f; - + SetPushConstants(cmdList, ShaderStage::Vertex, 0, sizeof(pushData) / sizeof(uint32), &pushData); DrawPrimitives(renderPass, g_DebugState.OverlayVertexCount, 1, 0, 0); diff --git a/Juliet/src/Graphics/ImGuiRenderer.cpp b/Juliet/src/Graphics/ImGuiRenderer.cpp index 80f365e..42c6f2e 100644 --- a/Juliet/src/Graphics/ImGuiRenderer.cpp +++ b/Juliet/src/Graphics/ImGuiRenderer.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -130,14 +131,18 @@ namespace Juliet ShaderCreateInfo shaderCI = {}; shaderCI.EntryPoint = entryPoint; - String vertPath = GetAssetPath(WrapString("ImGui.vert.dxil")); + TempArena path = scratch_begin(0, 0); + + String vertPath = GetAssetPath(path.Arena, WrapString("ImGui.vert.dxil")); shaderCI.Stage = ShaderStage::Vertex; g_ImGuiState.VertexShader = CreateShader(device, vertPath, shaderCI); - String fragPath = GetAssetPath(WrapString("ImGui.frag.dxil")); + String fragPath = GetAssetPath(path.Arena, WrapString("ImGui.frag.dxil")); shaderCI.Stage = ShaderStage::Fragment; g_ImGuiState.FragmentShader = CreateShader(device, fragPath, shaderCI); + scratch_end(path); + if (!g_ImGuiState.VertexShader || !g_ImGuiState.FragmentShader) { LogError(LogCategory::Graphics, "Failed to load ImGui shaders"); diff --git a/Juliet/src/Graphics/MeshRenderer.cpp b/Juliet/src/Graphics/MeshRenderer.cpp index c0ca3dc..39336ca 100644 --- a/Juliet/src/Graphics/MeshRenderer.cpp +++ b/Juliet/src/Graphics/MeshRenderer.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -80,14 +81,18 @@ namespace Juliet ShaderCreateInfo shaderCI = {}; shaderCI.EntryPoint = entryPoint; - String shaderPath = GetAssetPath(WrapString("Triangle.vert.dxil")); + TempArena path = scratch_begin(0, 0); + + String shaderPath = GetAssetPath(path.Arena, WrapString("Triangle.vert.dxil")); shaderCI.Stage = ShaderStage::Vertex; Shader* vertexShader = CreateShader(graphicsDevice, shaderPath, shaderCI); - shaderPath = GetAssetPath(WrapString("SolidColor.frag.dxil")); + shaderPath = GetAssetPath(path.Arena, WrapString("SolidColor.frag.dxil")); shaderCI.Stage = ShaderStage::Fragment; Shader* fragmentShader = CreateShader(graphicsDevice, shaderPath, shaderCI); + scratch_end(path); + ColorTargetDescription colorTargetDescription = {}; colorTargetDescription.Format = GetSwapChainTextureFormat(graphicsDevice, window); @@ -304,7 +309,7 @@ namespace Juliet g_MeshRenderer.MappedTransforms[meshIndex] = instance.Transform; } - MeshAsset& meshAsset = g_MeshRenderer.MeshAssets.Data[instance.MeshAsset]; + MeshAsset& meshAsset = g_MeshRenderer.MeshAssets.Data[instance.MeshAsset]; MaterialAsset& materialAsset = g_MeshRenderer.MaterialAssets.Data[instance.MaterialAsset]; pushData.MeshIndex = meshIndex; @@ -543,17 +548,21 @@ namespace Juliet auto* pipeline = g_MeshRenderer.Pipeline; auto* device = g_MeshRenderer.Device; + TempArena path = scratch_begin(0, 0); + String entryPoint = WrapString("main"); ShaderCreateInfo shaderCI = {}; shaderCI.EntryPoint = entryPoint; - String shaderPath = GetAssetPath(WrapString("Triangle.vert.dxil")); + String shaderPath = GetAssetPath(path.Arena, WrapString("Triangle.vert.dxil")); shaderCI.Stage = ShaderStage::Vertex; Shader* vertexShader = CreateShader(device, shaderPath, shaderCI); - shaderPath = GetAssetPath(WrapString("SolidColor.frag.dxil")); + shaderPath = GetAssetPath(path.Arena, WrapString("SolidColor.frag.dxil")); shaderCI.Stage = ShaderStage::Fragment; Shader* fragmentShader = CreateShader(device, shaderPath, shaderCI); + scratch_end(path); + UpdateGraphicsPipelineShaders(device, pipeline, vertexShader, fragmentShader); if (vertexShader) diff --git a/Juliet/src/Graphics/SkyboxRenderer.cpp b/Juliet/src/Graphics/SkyboxRenderer.cpp index 07601a2..dacf06d 100644 --- a/Juliet/src/Graphics/SkyboxRenderer.cpp +++ b/Juliet/src/Graphics/SkyboxRenderer.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -19,20 +20,24 @@ namespace Juliet GraphicsDevice* graphicsDevice = g_SkyboxRenderer.Device = device.Get(); + TempArena path = scratch_begin(0, 0); + String skyboxVSEntry = WrapString("main"); ShaderCreateInfo skyboxVSCI = {}; skyboxVSCI.EntryPoint = skyboxVSEntry; skyboxVSCI.Stage = ShaderStage::Vertex; - String vsPath = GetAssetPath(WrapString("Skybox.vert.dxil")); + String vsPath = GetAssetPath(path.Arena, WrapString("Skybox.vert.dxil")); Shader* skyboxVS = CreateShader(graphicsDevice, vsPath, skyboxVSCI); String skyboxFSEntry = WrapString("main"); ShaderCreateInfo skyboxFSCI = {}; skyboxFSCI.EntryPoint = skyboxFSEntry; skyboxFSCI.Stage = ShaderStage::Fragment; - String fsPath = GetAssetPath(WrapString("Skybox.frag.dxil")); + String fsPath = GetAssetPath(path.Arena, WrapString("Skybox.frag.dxil")); Shader* skyboxFS = CreateShader(graphicsDevice, fsPath, skyboxFSCI); + scratch_end(path); + ColorTargetDescription colorTargetDesc = {}; colorTargetDesc.Format = GetSwapChainTextureFormat(graphicsDevice, window); @@ -58,8 +63,14 @@ namespace Juliet result = false; } - if (skyboxVS) DestroyShader(graphicsDevice, skyboxVS); - if (skyboxFS) DestroyShader(graphicsDevice, skyboxFS); + if (skyboxVS) + { + DestroyShader(graphicsDevice, skyboxVS); + } + if (skyboxFS) + { + DestroyShader(graphicsDevice, skyboxFS); + } return result; }