conversion to arena, missing get asset filename

This commit is contained in:
2026-08-16 22:37:31 -04:00
parent a50e3c75cb
commit 4d803fdf77
6 changed files with 78 additions and 47 deletions
@@ -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> arena, String filename);
[[nodiscard]]extern JULIET_API bool IsAbsolutePath(String path);
[[nodiscard]] extern JULIET_API bool IsAbsolutePath(String path);
} // namespace Juliet
@@ -36,17 +36,14 @@ namespace Juliet
return CachedAssetBasePath;
}
[[nodiscard]] String GetAssetPath(String filename)
[[nodiscard]] String GetAssetPath(NonNullPtr<Arena> arena, String filename)
{
Assert(IsValid(CachedAssetBasePath));
Assert(IsValid(filename));
size_t totalSize = CachedAssetBasePath.Size + filename.Size + 1;
auto* buffer = static_cast<char*>(Calloc(totalSize, sizeof(char)));
if (!buffer)
{
return {};
}
char* buffer = ArenaPushArray<char>(arena, totalSize);
Assert(buffer);
juliet_snprintf(buffer, totalSize, "%s%s", CStr(CachedAssetBasePath), CStr(filename));
return { buffer, totalSize - 1 };
+32 -23
View File
@@ -1,9 +1,10 @@
#include <Graphics/DebugDisplay.h>
#include <Core/HAL/Filesystem/Filesystem.h>
#include <Core/Logging/LogManager.h>
#include <Core/Logging/LogTypes.h>
#include <Core/HAL/Filesystem/Filesystem.h>
#include <Core/Memory/Allocator.h>
#include <Core/Thread/ThreadContext.h>
#include <Graphics/GraphicsPipeline.h>
#include <Graphics/PushConstants.h>
@@ -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,19 +308,21 @@ 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);
@@ -329,19 +336,21 @@ 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);
+7 -2
View File
@@ -10,6 +10,7 @@
#include <Core/Logging/LogManager.h>
#include <Core/Logging/LogTypes.h>
#include <Core/Memory/MemoryArena.h>
#include <Core/Thread/ThreadContext.h>
#include <Graphics/GraphicsPipeline.h>
#include <Graphics/PushConstants.h>
#include <imgui.h>
@@ -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");
+14 -5
View File
@@ -4,6 +4,7 @@
#include <Core/Logging/LogManager.h>
#include <Core/Logging/LogTypes.h>
#include <Core/Math/Matrix.h>
#include <Core/Thread/ThreadContext.h>
#include <Engine/Asset.h>
#include <Graphics/GraphicsDevice.h>
#include <Graphics/Mesh.h>
@@ -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)
+15 -4
View File
@@ -3,6 +3,7 @@
#include <Core/HAL/Filesystem/Filesystem.h>
#include <Core/Logging/LogManager.h>
#include <Core/Logging/LogTypes.h>
#include <Core/Thread/ThreadContext.h>
#include <Graphics/GraphicsDevice.h>
#include <Graphics/PushConstants.h>
@@ -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;
}