Permalink
Browse files

Debugger: Add APIs for texture and CLUT.

  • Loading branch information...
unknownbrackets committed Jul 1, 2018
1 parent 1d430ff commit 2133b18198468cd8f200fe9f6c4f120dfb09586f
Showing with 69 additions and 2 deletions.
  1. +67 −2 Core/Debugger/WebSocket/GPUBufferSubscriber.cpp
  2. +2 −0 Core/Debugger/WebSocket/GPUBufferSubscriber.h
@@ -34,12 +34,14 @@ void *WebSocketGPUBufferInit(DebuggerEventHandlerMap &map) {
map["gpu.buffer.renderColor"] = &WebSocketGPUBufferRenderColor;
map["gpu.buffer.renderDepth"] = &WebSocketGPUBufferRenderDepth;
map["gpu.buffer.renderStencil"] = &WebSocketGPUBufferRenderStencil;
map["gpu.buffer.texture"] = &WebSocketGPUBufferTexture;
map["gpu.buffer.clut"] = &WebSocketGPUBufferClut;
return nullptr;
}
// Note: Calls req.Respond(). Other data can be added afterward.
static bool StreamBufferToDataURI(DebuggerRequest &req, const GPUDebugBuffer &buf, bool includeAlpha) {
static bool StreamBufferToDataURI(DebuggerRequest &req, const GPUDebugBuffer &buf, bool includeAlpha, int stackWidth) {
#ifdef USING_QT_UI
req.Fail("Not supported on Qt yet, pull requests accepted");
return false;
@@ -53,6 +55,14 @@ static bool StreamBufferToDataURI(DebuggerRequest &req, const GPUDebugBuffer &bu
return false;
}
if (stackWidth > 0) {
u32 totalPixels = w * h;
w = stackWidth;
while ((totalPixels % w) != 0)
--w;
h = totalPixels / w;
}
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (!png_ptr) {
req.Fail("Internal error setting up PNG encoder (png_ptr)");
@@ -218,6 +228,9 @@ static void GenericStreamBuffer(DebuggerRequest &req, std::function<bool(const G
bool includeAlpha = false;
if (!req.ParamBool("alpha", &includeAlpha, DebuggerParamType::OPTIONAL))
return;
u32 stackWidth = 0;
if (!req.ParamU32("stackWidth", &stackWidth, false, DebuggerParamType::OPTIONAL))
return;
std::string type = "uri";
if (!req.ParamString("type", &type, DebuggerParamType::OPTIONAL))
return;
@@ -233,7 +246,7 @@ static void GenericStreamBuffer(DebuggerRequest &req, std::function<bool(const G
if (type == "base64") {
StreamBufferToBase64(req, *buf);
} else if (type == "uri") {
StreamBufferToDataURI(req, *buf, includeAlpha);
StreamBufferToDataURI(req, *buf, includeAlpha, stackWidth);
} else {
_assert_(false);
}
@@ -330,3 +343,55 @@ void WebSocketGPUBufferRenderStencil(DebuggerRequest &req) {
return GPUStepping::GPU_GetCurrentStencilbuffer(buf);
});
}
// Retrieve current stencil texture (gpu.buffer.texture)
//
// Parameters:
// - type: either 'uri' or 'base64'.
// - alpha: boolean to include the alpha channel for 'uri' type.
// - level: texture mip level, default 0.
//
// Response (same event name) for 'uri' type:
// - width: numeric width of the texture (often wider than visual.)
// - height: numeric height of the texture (often wider than visual.)
// - uri: data: URI of PNG image for display.
//
// Response (same event name) for 'base64' type:
// - width: numeric width and stride of the texture (often wider than visual.)
// - height: numeric height of the texture (often wider than visual.)
// - flipped: boolean to indicate whether buffer is vertically flipped.
// - format: string indicating format, such as 'R8G8B8A8_UNORM' or 'B8G8R8A8_UNORM'.
// - base64: base64 encode of binary data.
void WebSocketGPUBufferTexture(DebuggerRequest &req) {
u32 level = 0;
if (!req.ParamU32("level", &level, false, DebuggerParamType::OPTIONAL))
return;
GenericStreamBuffer(req, [level](const GPUDebugBuffer *&buf) {
return GPUStepping::GPU_GetCurrentTexture(buf, level);
});
}
// Retrieve current stencil texture (gpu.buffer.texture)
//
// Parameters:
// - type: either 'uri' or 'base64'.
// - alpha: boolean to include the alpha channel for 'uri' type.
// - stackWidth: forced width for 'uri' type (increases height.)
//
// Response (same event name) for 'uri' type:
// - width: numeric width of CLUT.
// - height: numeric height of CLUT.
// - uri: data: URI of PNG image for display.
//
// Response (same event name) for 'base64' type:
// - width: number of pixels in CLUT.
// - height: always 1.
// - flipped: boolean to indicate whether buffer is vertically flipped.
// - format: string indicating format, such as 'R8G8B8A8_UNORM' or 'B8G8R8A8_UNORM'.
// - base64: base64 encode of binary data.
void WebSocketGPUBufferClut(DebuggerRequest &req) {
GenericStreamBuffer(req, [](const GPUDebugBuffer *&buf) {
return GPUStepping::GPU_GetCurrentClut(buf);
});
}
@@ -25,3 +25,5 @@ void WebSocketGPUBufferScreenshot(DebuggerRequest &req);
void WebSocketGPUBufferRenderColor(DebuggerRequest &req);
void WebSocketGPUBufferRenderDepth(DebuggerRequest &req);
void WebSocketGPUBufferRenderStencil(DebuggerRequest &req);
void WebSocketGPUBufferTexture(DebuggerRequest &req);
void WebSocketGPUBufferClut(DebuggerRequest &req);

0 comments on commit 2133b18

Please sign in to comment.