mirror of
https://github.com/johndoe6345789/SDL3CPlusPlus.git
synced 2026-04-24 21:55:09 +00:00
improve trace
This commit is contained in:
@@ -56,6 +56,7 @@ void Sdl3App::LoadSceneData() {
|
||||
void Sdl3App::CreateVertexBuffer() {
|
||||
TRACE_FUNCTION();
|
||||
VkDeviceSize bufferSize = sizeof(vertices_[0]) * vertices_.size();
|
||||
TRACE_VAR(bufferSize);
|
||||
vulkan::CreateBuffer(device_, physicalDevice_, bufferSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, vertexBuffer_,
|
||||
vertexBufferMemory_);
|
||||
@@ -69,6 +70,7 @@ void Sdl3App::CreateVertexBuffer() {
|
||||
void Sdl3App::CreateIndexBuffer() {
|
||||
TRACE_FUNCTION();
|
||||
VkDeviceSize bufferSize = sizeof(indices_[0]) * indices_.size();
|
||||
TRACE_VAR(bufferSize);
|
||||
vulkan::CreateBuffer(device_, physicalDevice_, bufferSize, VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, indexBuffer_,
|
||||
indexBufferMemory_);
|
||||
|
||||
@@ -83,6 +83,7 @@ void ThrowSdlErrorIfFailed(int result, const char* context) {
|
||||
|
||||
Sdl3App::Sdl3App(const std::filesystem::path& scriptPath) : cubeScript_(scriptPath) {
|
||||
TRACE_FUNCTION();
|
||||
TRACE_VAR(scriptPath);
|
||||
}
|
||||
|
||||
void Sdl3App::Run() {
|
||||
@@ -95,12 +96,15 @@ void Sdl3App::Run() {
|
||||
|
||||
void Sdl3App::InitSDL() {
|
||||
TRACE_FUNCTION();
|
||||
TRACE_VAR(kWidth);
|
||||
TRACE_VAR(kHeight);
|
||||
ThrowSdlErrorIfFailed(SDL_Init(SDL_INIT_VIDEO), "SDL_Init failed");
|
||||
ThrowSdlErrorIfFailed(SDL_Vulkan_LoadLibrary(nullptr), "SDL_Vulkan_LoadLibrary failed");
|
||||
window_ = SDL_CreateWindow("SDL3 Vulkan Demo", kWidth, kHeight, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
|
||||
if (!window_) {
|
||||
throw std::runtime_error(BuildSdlErrorMessage("SDL_CreateWindow failed"));
|
||||
}
|
||||
TRACE_VAR(window_);
|
||||
SDL_StartTextInput(window_);
|
||||
}
|
||||
|
||||
@@ -126,6 +130,7 @@ void Sdl3App::InitVulkan() {
|
||||
|
||||
void Sdl3App::MainLoop() {
|
||||
TRACE_FUNCTION();
|
||||
TRACE_VAR(guiHasCommands_);
|
||||
bool running = true;
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
while (running) {
|
||||
|
||||
@@ -24,6 +24,8 @@ void Sdl3App::CreateInstance() {
|
||||
}
|
||||
|
||||
std::vector<const char*> extensionList(extensions, extensions + extensionCount);
|
||||
TRACE_VAR(extensionCount);
|
||||
TRACE_VAR(extensionList.size());
|
||||
|
||||
VkInstanceCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
|
||||
@@ -39,6 +39,8 @@ void Sdl3App::CreateCommandBuffers() {
|
||||
void Sdl3App::RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex, float time,
|
||||
const std::array<float, 16>& viewProj) {
|
||||
TRACE_FUNCTION();
|
||||
TRACE_VAR(imageIndex);
|
||||
TRACE_FUNCTION();
|
||||
VkCommandBufferBeginInfo beginInfo{};
|
||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||
|
||||
@@ -147,6 +149,7 @@ void Sdl3App::DrawFrame(float time) {
|
||||
} else if (result != VK_SUCCESS) {
|
||||
throw std::runtime_error("Failed to acquire swap chain image");
|
||||
}
|
||||
TRACE_VAR(imageIndex);
|
||||
|
||||
float aspect = static_cast<float>(swapChainExtent_.width) / static_cast<float>(swapChainExtent_.height);
|
||||
auto viewProj = cubeScript_.GetViewProjectionMatrix(aspect);
|
||||
|
||||
@@ -18,6 +18,7 @@ void Sdl3App::CreateSwapChain() {
|
||||
if (support.capabilities.maxImageCount > 0 && imageCount > support.capabilities.maxImageCount) {
|
||||
imageCount = support.capabilities.maxImageCount;
|
||||
}
|
||||
TRACE_VAR(imageCount);
|
||||
|
||||
VkSwapchainCreateInfoKHR createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace sdl3cpp::app {
|
||||
|
||||
@@ -22,6 +23,16 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void LogVariable(const char* name, const T& value) {
|
||||
if (!Enabled()) {
|
||||
return;
|
||||
}
|
||||
std::ostringstream oss;
|
||||
oss << "[TRACE] " << name << " = " << value;
|
||||
std::cout << oss.str() << '\n';
|
||||
}
|
||||
|
||||
private:
|
||||
static inline std::atomic_bool enabled_{false};
|
||||
};
|
||||
@@ -39,5 +50,6 @@ private:
|
||||
} // namespace sdl3cpp::app
|
||||
|
||||
#define TRACE_FUNCTION() sdl3cpp::app::TraceScope traceScope##__COUNTER__{__func__}
|
||||
#define TRACE_VAR(var) sdl3cpp::app::TraceLogger::LogVariable(#var, var)
|
||||
|
||||
#endif // SDL3CPP_APP_TRACE_HPP
|
||||
|
||||
@@ -222,6 +222,12 @@ AppOptions ParseCommandLine(int argc, char** argv) {
|
||||
return options;
|
||||
}
|
||||
|
||||
void LogRuntimeConfig(const RuntimeConfig& config) {
|
||||
TRACE_VAR(config.width);
|
||||
TRACE_VAR(config.height);
|
||||
TRACE_VAR(config.scriptPath);
|
||||
}
|
||||
|
||||
void WriteRuntimeConfigJson(const RuntimeConfig& runtimeConfig,
|
||||
const std::filesystem::path& configPath) {
|
||||
rapidjson::Document document;
|
||||
@@ -281,6 +287,7 @@ int main(int argc, char** argv) {
|
||||
try {
|
||||
AppOptions options = ParseCommandLine(argc, argv);
|
||||
sdl3cpp::app::TraceLogger::SetEnabled(options.traceEnabled);
|
||||
LogRuntimeConfig(options.runtimeConfig);
|
||||
if (options.seedOutput) {
|
||||
WriteRuntimeConfigJson(options.runtimeConfig, *options.seedOutput);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user