From daa6d6236f435e26383320d9a907b8e9fcddbf04 Mon Sep 17 00:00:00 2001 From: capehill Date: Sun, 28 Apr 2019 16:22:52 +0300 Subject: [PATCH] Trace FBO calls --- filters | 19 ++++- ogles2_module.c | 127 ++++++++++++++++++++++++++++- warp3dnova_module.c | 191 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 320 insertions(+), 17 deletions(-) diff --git a/filters b/filters index 94d8785..b998376 100755 --- a/filters +++ b/filters @@ -25,12 +25,19 @@ glTexParameteriv #glTexSubImage2D #glTexImage2D glDeleteTextures +glGenFramebuffers +#glBindFramebuffer +glCheckFramebufferStatus +glFramebufferRenderbuffer +glFramebufferTexture2D +glGetFramebufferAttachmentParameteriv +glDeleteFramebuffers # WARP3D Nova functions W3DN_Destroy # Keep always active W3DN_CreateVertexBufferObject -W3DN_DestroyVertexBufferObject +#W3DN_DestroyVertexBufferObject #W3DN_VBOSetArray #W3DN_VBOGetArray #W3DN_VBOGetAttr @@ -39,5 +46,13 @@ W3DN_DestroyVertexBufferObject #W3DN_BindVertexAttribArray #W3DN_DrawArrays #W3DN_DrawElements - +W3DN_CreateFrameBuffer +W3DN_DestroyFrameBuffer +#W3DN_FBBindBuffer +#W3DN_FBGetBufferBM +#W3DN_FBGetBufferTex +W3DN_FBGetStatus +#W3DN_SetRenderTarget +#W3DN_GetRenderTarget +W3DN_FBGetAttr diff --git a/ogles2_module.c b/ogles2_module.c index 180ff22..2a3d88f 100644 --- a/ogles2_module.c +++ b/ogles2_module.c @@ -45,6 +45,14 @@ struct Ogles2Context void (*old_glTexSubImage2D)(struct OGLES2IFace *Self, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * pixels); void (*old_glTexImage2D)(struct OGLES2IFace *Self, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void * pixels); void (*old_glDeleteTextures)(struct OGLES2IFace *Self, GLsizei n, const GLuint * textures); + + void (*old_glGenFramebuffers)(struct OGLES2IFace *Self, GLsizei n, GLuint * framebuffers); + void (*old_glBindFramebuffer)(struct OGLES2IFace *Self, GLenum target, GLuint framebuffer); + GLenum (*old_glCheckFramebufferStatus)(struct OGLES2IFace *Self, GLenum target); + void (*old_glFramebufferRenderbuffer)(struct OGLES2IFace *Self, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); + void (*old_glFramebufferTexture2D)(struct OGLES2IFace *Self, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); + void (*old_glGetFramebufferAttachmentParameteriv)(struct OGLES2IFace *Self, GLenum target, GLenum attachment, GLenum pname, GLint * params); + void (*old_glDeleteFramebuffers)(struct OGLES2IFace *Self, GLsizei n, const GLuint * framebuffers); }; static struct Ogles2Context* contexts[MAX_CLIENTS]; @@ -196,6 +204,11 @@ PRE_CHECK \ x; \ POST_CHECK +#define CHECK_STATUS(x) \ +PRE_CHECK \ +status = x; \ +POST_CHECK + // Wrap traced function calls static void OGLES2_aglSwapBuffers(struct OGLES2IFace *Self) @@ -505,6 +518,104 @@ static void OGLES2_glDeleteTextures(struct OGLES2IFace *Self, GLsizei n, const G } } +static void OGLES2_glGenFramebuffers(struct OGLES2IFace *Self, GLsizei n, GLuint * framebuffers) +{ + GET_CONTEXT + + logLine("%s: %s: n %u, framebuffers %p", context->name, __func__, + n, framebuffers); + + if (context->old_glGenFramebuffers) { + CHECK(context->old_glGenFramebuffers(Self, n, framebuffers)) + } + + GLsizei i; + for (i = 0; i < n; i++) { + logLine("Framebuffer[%u] = %u", i, framebuffers[i]); + } +} + +static void OGLES2_glBindFramebuffer(struct OGLES2IFace *Self, GLenum target, GLuint framebuffer) +{ + GET_CONTEXT + + logLine("%s: %s: target %u, framebuffer %u", context->name, __func__, + target, framebuffer); + + if (context->old_glBindFramebuffer) { + CHECK(context->old_glBindFramebuffer(Self, target, framebuffer)) + } +} + +static GLenum OGLES2_glCheckFramebufferStatus(struct OGLES2IFace *Self, GLenum target) +{ + GET_CONTEXT + + GLenum status = 0; + + if (context->old_glCheckFramebufferStatus) { + CHECK_STATUS(context->old_glCheckFramebufferStatus(Self, target)) + } + + logLine("%s: %s: status %u", context->name, __func__, + status); + + return status; +} + +static void OGLES2_glFramebufferRenderbuffer(struct OGLES2IFace *Self, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) +{ + GET_CONTEXT + + logLine("%s: %s: target %u, attachment %u, renderbuffertarget %u, renderbuffer %u", context->name, __func__, + target, attachment, renderbuffertarget, renderbuffer); + + if (context->old_glFramebufferRenderbuffer) { + CHECK(context->old_glFramebufferRenderbuffer(Self, target, attachment, renderbuffertarget, renderbuffer)) + } +} + +static void OGLES2_glFramebufferTexture2D(struct OGLES2IFace *Self, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) +{ + GET_CONTEXT + + logLine("%s: %s: target %u, attachment %u, textarget %u, texture %u, level %d", context->name, __func__, + target, attachment, textarget, texture, level); + + if (context->old_glFramebufferTexture2D) { + CHECK(context->old_glFramebufferTexture2D(Self, target, attachment, textarget, texture, level)) + } +} + +static void OGLES2_glGetFramebufferAttachmentParameteriv(struct OGLES2IFace *Self, GLenum target, GLenum attachment, GLenum pname, GLint * params) +{ + GET_CONTEXT + + logLine("%s: %s: target %u, attachment %u pname %u, params %p", context->name, __func__, + target, attachment, pname, params); + + if (context->old_glGetFramebufferAttachmentParameteriv) { + CHECK(context->old_glGetFramebufferAttachmentParameteriv(Self, target, attachment, pname, params)) + } +} + +static void OGLES2_glDeleteFramebuffers(struct OGLES2IFace *Self, GLsizei n, const GLuint * framebuffers) +{ + GET_CONTEXT + + logLine("%s: %s: n %u, framebuffers %p", context->name, __func__, + n, framebuffers); + + GLsizei i; + for (i = 0; i < n; i++) { + logLine("Deleting framebuffer[%u] = %u", i, framebuffers[i]); + } + + if (context->old_glDeleteFramebuffers) { + CHECK(context->old_glDeleteFramebuffers(Self, n, framebuffers)) + } +} + GENERATE_FILTERED_PATCH(OGLES2IFace, aglSwapBuffers, OGLES2, Ogles2Context) GENERATE_FILTERED_PATCH(OGLES2IFace, glCompileShader, OGLES2, Ogles2Context) GENERATE_FILTERED_PATCH(OGLES2IFace, glGenBuffers, OGLES2, Ogles2Context) @@ -528,6 +639,13 @@ GENERATE_FILTERED_PATCH(OGLES2IFace, glTexParameteriv, OGLES2, Ogles2Context) GENERATE_FILTERED_PATCH(OGLES2IFace, glTexSubImage2D, OGLES2, Ogles2Context) GENERATE_FILTERED_PATCH(OGLES2IFace, glTexImage2D, OGLES2, Ogles2Context) GENERATE_FILTERED_PATCH(OGLES2IFace, glDeleteTextures, OGLES2, Ogles2Context) +GENERATE_FILTERED_PATCH(OGLES2IFace, glGenFramebuffers, OGLES2, Ogles2Context) +GENERATE_FILTERED_PATCH(OGLES2IFace, glBindFramebuffer, OGLES2, Ogles2Context) +GENERATE_FILTERED_PATCH(OGLES2IFace, glCheckFramebufferStatus, OGLES2, Ogles2Context) +GENERATE_FILTERED_PATCH(OGLES2IFace, glFramebufferRenderbuffer, OGLES2, Ogles2Context) +GENERATE_FILTERED_PATCH(OGLES2IFace, glFramebufferTexture2D, OGLES2, Ogles2Context) +GENERATE_FILTERED_PATCH(OGLES2IFace, glGetFramebufferAttachmentParameteriv, OGLES2, Ogles2Context) +GENERATE_FILTERED_PATCH(OGLES2IFace, glDeleteFramebuffers, OGLES2, Ogles2Context) static void (*patches[])(BOOL, struct Ogles2Context *) = { patch_aglSwapBuffers, @@ -552,7 +670,14 @@ static void (*patches[])(BOOL, struct Ogles2Context *) = { patch_glTexParameteriv, patch_glTexSubImage2D, patch_glTexImage2D, - patch_glDeleteTextures + patch_glDeleteTextures, + patch_glGenFramebuffers, + patch_glBindFramebuffer, + patch_glCheckFramebufferStatus, + patch_glFramebufferRenderbuffer, + patch_glFramebufferTexture2D, + patch_glGetFramebufferAttachmentParameteriv, + patch_glDeleteFramebuffers, }; void ogles2_install_patches(void) diff --git a/warp3dnova_module.c b/warp3dnova_module.c index d33ed76..223199c 100644 --- a/warp3dnova_module.c +++ b/warp3dnova_module.c @@ -50,6 +50,30 @@ struct NovaContext { W3DN_ErrorCode (*old_DrawElements)(struct W3DN_Context_s *self, W3DN_RenderState *renderState, W3DN_Primitive primitive, uint32 baseVertex, uint32 count, W3DN_VertexBuffer *indexBuffer, uint32 arrayIdx); + + W3DN_FrameBuffer* (*old_CreateFrameBuffer)(struct W3DN_Context_s *self, W3DN_ErrorCode *errCode); + + void (*old_DestroyFrameBuffer)(struct W3DN_Context_s *self, W3DN_FrameBuffer *frameBuffer); + + W3DN_ErrorCode (*old_FBBindBuffer)(struct W3DN_Context_s *self, + W3DN_FrameBuffer *frameBuffer, int32 attachmentPt, struct TagItem *tags); + + struct BitMap* (*old_FBGetBufferBM)(struct W3DN_Context_s *self, + W3DN_FrameBuffer *frameBuffer, uint32 attachmentPt, W3DN_ErrorCode *errCode); + + W3DN_Texture* (*old_FBGetBufferTex)(struct W3DN_Context_s *self, + W3DN_FrameBuffer *frameBuffer, uint32 attachmentPt, W3DN_ErrorCode *errCode); + + W3DN_ErrorCode (*old_FBGetStatus)(struct W3DN_Context_s *self, W3DN_FrameBuffer *frameBuffer); + + W3DN_ErrorCode (*old_SetRenderTarget)(struct W3DN_Context_s *self, + W3DN_RenderState *renderState, W3DN_FrameBuffer *frameBuffer); + + W3DN_FrameBuffer* (*old_GetRenderTarget)( + struct W3DN_Context_s *self, W3DN_RenderState *renderState); + + uint64 (*old_FBGetAttr)(struct W3DN_Context_s *self, + W3DN_FrameBuffer *frameBuffer, W3DN_FrameBufferAttribute attrib); }; static struct NovaContext* contexts[MAX_CLIENTS]; @@ -122,8 +146,8 @@ static W3DN_VertexBuffer* W3DN_CreateVertexBufferObject(struct W3DN_Context_s *s W3DN_VertexBuffer* result = context->old_CreateVertexBufferObject(self, errCode, size, usage, maxArrays, tags); - logLine("%s: %s: size %u, usage %d, maxArrays %u, tags %p. Buffer address %p, errCode %d", context->name, __func__, - (unsigned)size, usage, (unsigned)maxArrays, tags, result, *errCode); + logLine("%s: %s: size %llu, usage %d, maxArrays %u, tags %p. Buffer address %p, errCode %d", context->name, __func__, + size, usage, (unsigned)maxArrays, tags, result, *errCode); return result; } @@ -144,8 +168,8 @@ static uint64 W3DN_VBOGetAttr(struct W3DN_Context_s *self, W3DN_VertexBuffer *ve const uint64 result = context->old_VBOGetAttr(self, vertexBuffer, attr); - logLine("%s: %s: vertexBuffer %p, attr %d. Result %u", context->name, __func__, - vertexBuffer, attr, (unsigned)result); + logLine("%s: %s: vertexBuffer %p, attr %d. Result %llu", context->name, __func__, + vertexBuffer, attr, result); return result; } @@ -158,9 +182,9 @@ static W3DN_ErrorCode W3DN_VBOSetArray(struct W3DN_Context_s *self, W3DN_VertexB const W3DN_ErrorCode result = context->old_VBOSetArray(self, buffer, arrayIdx, elementType, normalized, numElements, stride, offset, count); - logLine("%s: %s: buffer %p, arrayIdx %u, elementType %d, normalized %d, numElements %u, stride %u, offset %u, count %u. Result %d", + logLine("%s: %s: buffer %p, arrayIdx %u, elementType %d, normalized %d, numElements %llu, stride %llu, offset %llu, count %llu. Result %d", context->name, __func__, - buffer, (unsigned)arrayIdx, elementType, normalized, (unsigned)numElements, (unsigned)stride, (unsigned)offset, (unsigned)count, result); + buffer, (unsigned)arrayIdx, elementType, normalized, numElements, stride, offset, count, result); return result; } @@ -173,9 +197,9 @@ static W3DN_ErrorCode W3DN_VBOGetArray(struct W3DN_Context_s *self, W3DN_VertexB const W3DN_ErrorCode result = context->old_VBOGetArray(self, buffer, arrayIdx, elementType, normalized, numElements, stride, offset, count); - logLine("%s: %s: buffer %p, arrayIdx %u, elementType %d, normalized %d, numElements %u, stride %u, offset %u, count %u. Result %d", + logLine("%s: %s: buffer %p, arrayIdx %u, elementType %d, normalized %d, numElements %llu, stride %llu, offset %llu, count %llu. Result %d", context->name, __func__, - buffer, (unsigned)arrayIdx, *elementType, *normalized, (unsigned)*numElements, (unsigned)*stride, (unsigned)*offset, (unsigned)*count, result); + buffer, (unsigned)arrayIdx, *elementType, *normalized, *numElements, *stride, *offset, *count, result); return result; } @@ -187,8 +211,8 @@ static W3DN_BufferLock* W3DN_VBOLock(struct W3DN_Context_s *self, W3DN_ErrorCode W3DN_BufferLock* result = context->old_VBOLock(self, errCode, buffer, readOffset, readSize); - logLine("%s: %s: buffer %p, readOffset %u, readSize %u. Lock address %p, errCode %d", context->name, __func__, - buffer, (unsigned)readOffset, (unsigned)readSize, result, *errCode); + logLine("%s: %s: buffer %p, readOffset %llu, readSize %llu. Lock address %p, errCode %u", context->name, __func__, + buffer, readOffset, readSize, result, *errCode); return result; } @@ -200,8 +224,8 @@ static W3DN_ErrorCode W3DN_BufferUnlock(struct W3DN_Context_s *self, const W3DN_ErrorCode result = context->old_BufferUnlock(self, bufferLock, writeOffset, writeSize); - logLine("%s: %s: bufferLock %p, writeOffset %u, writeSize %u. Result %d", context->name, __func__, - bufferLock, (unsigned)writeOffset, (unsigned)writeSize, result); + logLine("%s: %s: bufferLock %p, writeOffset %llu, writeSize %llu. Result %d", context->name, __func__, + bufferLock, writeOffset, writeSize, result); return result; } @@ -250,7 +274,7 @@ static W3DN_ErrorCode W3DN_DrawElements(struct W3DN_Context_s *self, static void W3DN_Destroy(struct W3DN_Context_s *self) { - GET_CONTEXT; + GET_CONTEXT logLine("%s: %s", context->name, __func__); @@ -274,6 +298,127 @@ static void W3DN_Destroy(struct W3DN_Context_s *self) IExec->MutexRelease(mutex); } +static W3DN_FrameBuffer* W3DN_CreateFrameBuffer(struct W3DN_Context_s *self, W3DN_ErrorCode *errCode) +{ + GET_CONTEXT + + W3DN_FrameBuffer* buffer = context->old_CreateFrameBuffer(self, errCode); + + logLine("%s: %s: Frame buffer address %p. Result %d", + context->name, __func__, + buffer, *errCode); + + return buffer; +} + +static void W3DN_DestroyFrameBuffer(struct W3DN_Context_s *self, W3DN_FrameBuffer *frameBuffer) +{ + GET_CONTEXT + + logLine("%s: %s: frameBuffer %p", + context->name, __func__, + frameBuffer); + + context->old_DestroyFrameBuffer(self, frameBuffer); +} + +static W3DN_ErrorCode W3DN_FBBindBuffer(struct W3DN_Context_s *self, + W3DN_FrameBuffer *frameBuffer, int32 attachmentPt, struct TagItem *tags) +{ + GET_CONTEXT + + const W3DN_ErrorCode result = context->old_FBBindBuffer(self, frameBuffer, attachmentPt, tags); + + logLine("%s: %s: frameBuffer %p, attachmentPt %d, tags %p. Result %d", + context->name, __func__, + frameBuffer, (int)attachmentPt, tags, result); + + return result; +} + +static struct BitMap* W3DN_FBGetBufferBM(struct W3DN_Context_s *self, + W3DN_FrameBuffer *frameBuffer, uint32 attachmentPt, W3DN_ErrorCode *errCode) +{ + GET_CONTEXT + + struct BitMap* bitmap = context->old_FBGetBufferBM(self, frameBuffer, attachmentPt, errCode); + + logLine("%s: %s: frameBuffer %p, attachmentPt %u. Bitmap address %p. Result %d", + context->name, __func__, + frameBuffer, (unsigned)attachmentPt, bitmap, *errCode); + + return bitmap; +} + +static W3DN_Texture* W3DN_FBGetBufferTex(struct W3DN_Context_s *self, + W3DN_FrameBuffer *frameBuffer, uint32 attachmentPt, W3DN_ErrorCode *errCode) +{ + GET_CONTEXT + + W3DN_Texture * texture = context->old_FBGetBufferTex(self, frameBuffer, attachmentPt, errCode); + + logLine("%s: %s: frameBuffer %p, attachmentPt %u. Texture address %p. Result %d", + context->name, __func__, + frameBuffer, (unsigned)attachmentPt, texture, *errCode); + + return texture; +} + +static W3DN_ErrorCode W3DN_FBGetStatus(struct W3DN_Context_s *self, W3DN_FrameBuffer *frameBuffer) +{ + GET_CONTEXT + + const W3DN_ErrorCode result = context->old_FBGetStatus(self, frameBuffer); + + logLine("%s: %s: frameBuffer %p. Result %d", + context->name, __func__, + frameBuffer, result); + + return result; +} + +static W3DN_ErrorCode W3DN_SetRenderTarget(struct W3DN_Context_s *self, + W3DN_RenderState *renderState, W3DN_FrameBuffer *frameBuffer) +{ + GET_CONTEXT + + const W3DN_ErrorCode result = context->old_SetRenderTarget(self, renderState, frameBuffer); + + logLine("%s: %s: renderState %p, frameBuffer %p. Result %d", + context->name, __func__, + renderState, frameBuffer, result); + + return result; +} + +static W3DN_FrameBuffer* W3DN_GetRenderTarget( + struct W3DN_Context_s *self, W3DN_RenderState *renderState) +{ + GET_CONTEXT + + W3DN_FrameBuffer* buffer = context->old_GetRenderTarget(self, renderState); + + logLine("%s: %s: renderState %p. Frame buffer address %p", + context->name, __func__, + renderState, buffer); + + return buffer; +} + +static uint64 W3DN_FBGetAttr(struct W3DN_Context_s *self, + W3DN_FrameBuffer *frameBuffer, W3DN_FrameBufferAttribute attrib) +{ + GET_CONTEXT + + const uint64 result = context->old_FBGetAttr(self, frameBuffer, attrib); + + logLine("%s: %s: frameBuffer %p, attrib %d. Result %llu", + context->name, __func__, + frameBuffer, attrib, result); + + return result; +} + #define GENERATE_NOVA_PATCH(function) \ static void patch_##function(BOOL patching, struct NovaContext* nova) \ { \ @@ -302,6 +447,15 @@ GENERATE_NOVA_PATCH(BufferUnlock) GENERATE_NOVA_PATCH(BindVertexAttribArray) GENERATE_NOVA_PATCH(DrawArrays) GENERATE_NOVA_PATCH(DrawElements) +GENERATE_NOVA_PATCH(CreateFrameBuffer) +GENERATE_NOVA_PATCH(DestroyFrameBuffer) +GENERATE_NOVA_PATCH(FBBindBuffer) +GENERATE_NOVA_PATCH(FBGetBufferBM) +GENERATE_NOVA_PATCH(FBGetBufferTex) +GENERATE_NOVA_PATCH(FBGetStatus) +GENERATE_NOVA_PATCH(SetRenderTarget) +GENERATE_NOVA_PATCH(GetRenderTarget) +GENERATE_NOVA_PATCH(FBGetAttr) static void (*patches[])(BOOL, struct NovaContext *) = { patch_Destroy, @@ -314,7 +468,16 @@ static void (*patches[])(BOOL, struct NovaContext *) = { patch_BufferUnlock, patch_BindVertexAttribArray, patch_DrawArrays, - patch_DrawElements + patch_DrawElements, + patch_CreateFrameBuffer, + patch_DestroyFrameBuffer, + patch_FBBindBuffer, + patch_FBGetBufferBM, + patch_FBGetBufferTex, + patch_FBGetStatus, + patch_SetRenderTarget, + patch_GetRenderTarget, + patch_FBGetAttr, }; static void patch_context_functions(struct NovaContext* nova)