include debug information

This commit is contained in:
Samuliak 2024-07-07 12:12:34 +02:00
parent 1353af5af4
commit 3431f6d192
8 changed files with 37 additions and 1 deletions

View file

@ -43,6 +43,7 @@ public:
desc->setDepthAttachmentPixelFormat(toMTLPixelFormatDepth(hash.depthFmt));
NS::Error* error = nullptr;
desc->setLabel(toNSString("Blit pipeline"));
pipeline = device->newRenderPipelineState(desc, &error);
if (error) {
Helpers::panic("Error creating blit pipeline state: %s", error->description()->cString(NS::ASCIIStringEncoding));

View file

@ -95,6 +95,7 @@ public:
desc->setDepthAttachmentPixelFormat(toMTLPixelFormatDepth(hash.depthFmt));
NS::Error* error = nullptr;
desc->setLabel(toNSString("Draw pipeline"));
pipeline = device->newRenderPipelineState(desc, &error);
if (error) {
Helpers::panic("Error creating draw pipeline state: %s", error->description()->cString(NS::ASCIIStringEncoding));

View file

@ -7,6 +7,7 @@
#include "math_util.hpp"
#include "opengl.hpp"
#include "pica_to_mtl.hpp"
#include "objc_helper.hpp"
template <typename T>
using Interval = boost::icl::right_open_interval<T>;
@ -68,6 +69,7 @@ struct RenderTarget {
descriptor->setUsage(MTL::TextureUsageRenderTarget | MTL::TextureUsageShaderRead);
descriptor->setStorageMode(MTL::StorageModePrivate);
texture = device->newTexture(descriptor);
texture->setLabel(toNSString(std::string(std::is_same<Format_t, PICA::ColorFmt>::value ? "Color" : "Depth") + " render target " + std::to_string(size.u()) + "x" + std::to_string(size.v())));
}
void free() {

View file

@ -26,6 +26,7 @@ public:
void set(MTL::Device* dev) {
device = dev;
buffer = device->newBuffer(CACHE_BUFFER_SIZE, MTL::ResourceStorageModeShared);
buffer->setLabel(toNSString("Shared vertex buffer"));
}
void endFrame() {
@ -40,6 +41,7 @@ public:
// If the vertex buffer is too large, just create a new one
if (ptr + vertices.size_bytes() > CACHE_BUFFER_SIZE) {
MTL::Buffer* newBuffer = device->newBuffer(vertices.data(), vertices.size_bytes(), MTL::ResourceStorageModeShared);
newBuffer->setLabel(toNSString("Additional vertex buffer"));
additionalAllocations.push_back(newBuffer);
Helpers::warn("Vertex buffer doesn't have enough space, creating a new buffer");

View file

@ -7,3 +7,8 @@ namespace Metal {
dispatch_data_t createDispatchData(const void* data, size_t size);
} // namespace Metal
// Cast from std::string to NS::String*
inline NS::String* toNSString(const std::string& str) {
return NS::String::string(str.c_str(), NS::ASCIIStringEncoding);
}

View file

@ -72,6 +72,9 @@ class RendererMTL final : public Renderer {
MTL::Texture* lastColorTexture = nullptr;
MTL::Texture* lastDepthTexture = nullptr;
// Debug
std::string nextRenderPassName;
void createCommandBufferIfNeeded() {
if (!commandBuffer) {
commandBuffer = commandQueue->commandBuffer();
@ -92,6 +95,7 @@ class RendererMTL final : public Renderer {
endRenderPass();
renderCommandEncoder = commandBuffer->renderCommandEncoder(renderPassDescriptor);
renderCommandEncoder->setLabel(toNSString(nextRenderPassName));
lastColorTexture = colorTexture;
lastDepthTexture = depthTexture;