GLES2Dbg: use 256KB chunks for lzf compression

Data format is uint32_t totalDecompressedSize, then repeat:
uint32_t chunkDecompressedSize, chunkCompressedSize, chunk data.
If chunkCompressedSize == 0, then chunk is not compressed.

Also start fixing integer sizes on server.
On client, set endianness to match server.

Change-Id: I0d5afa16976ea6019b91c4e21d284605da7e135e
Signed-off-by: David Li <davidxli@google.com>
This commit is contained in:
David Li 2011-03-22 18:48:31 -07:00
parent c9832f271f
commit 7a52015696
4 changed files with 43 additions and 39 deletions

View File

@ -22,8 +22,7 @@
unsigned readSize = GetBytesPerPixel(readFormat, readType) * width * height; \
void * readData = dbg->GetReadPixelsBuffer(readSize); \
dbg->hooks->gl.glReadPixels(x, y, width, height, readFormat, readType, readData); \
const unsigned compressedSize = dbg->CompressReadPixelBuffer(); \
msg.set_data(dbg->lzf_buf, compressedSize); \
dbg->CompressReadPixelBuffer(msg.mutable_data()); \
msg.set_data_type(msg.ReferencedImage); \
msg.set_pixel_format(readFormat); \
msg.set_pixel_type(readType);
@ -43,8 +42,7 @@
DbgContext * const dbg = getDbgContextThreadSpecific(); \
const unsigned size = GetBytesPerPixel(format, type) * width * height; \
assert(0 < size); \
unsigned compressedSize = dbg->Compress(pixels, size); \
msg.set_data(dbg->lzf_buf, compressedSize); \
dbg->Compress(pixels, size, msg.mutable_data()); \
}
#define EXTEND_Debug_glTexSubImage2D EXTEND_Debug_glTexImage2D

View File

@ -26,8 +26,7 @@ namespace android
DbgContext::DbgContext(const unsigned version, const gl_hooks_t * const hooks,
const unsigned MAX_VERTEX_ATTRIBS)
: lzf_buf(NULL), lzf_bufSize(0)
, lzf_readIndex(0), lzf_refSize(0), lzf_refBufSize(0)
: lzf_buf(NULL), lzf_readIndex(0), lzf_refSize(0), lzf_refBufSize(0)
, version(version), hooks(hooks)
, MAX_VERTEX_ATTRIBS(MAX_VERTEX_ATTRIBS)
, vertexAttribs(new VertexAttrib[MAX_VERTEX_ATTRIBS])
@ -109,16 +108,26 @@ void DbgContext::Fetch(const unsigned index, std::string * const data) const
}
}
unsigned DbgContext::Compress(const void * in_data, unsigned in_len)
void DbgContext::Compress(const void * in_data, unsigned int in_len,
std::string * const outStr)
{
if (lzf_bufSize < in_len * 1.05f) {
lzf_bufSize = in_len * 1.05f;
lzf_buf = (char *)realloc(lzf_buf, lzf_bufSize);
if (!lzf_buf)
lzf_buf = (char *)malloc(LZF_CHUNK_SIZE);
const uint32_t totalDecompSize = in_len;
outStr->append((const char *)&totalDecompSize, sizeof(totalDecompSize));
for (unsigned int i = 0; i < in_len; i += LZF_CHUNK_SIZE) {
uint32_t chunkSize = LZF_CHUNK_SIZE;
if (i + LZF_CHUNK_SIZE > in_len)
chunkSize = in_len - i;
const uint32_t compSize = lzf_compress((const char *)in_data + i, chunkSize,
lzf_buf, LZF_CHUNK_SIZE);
outStr->append((const char *)&chunkSize, sizeof(chunkSize));
outStr->append((const char *)&compSize, sizeof(compSize));
if (compSize > 0)
outStr->append(lzf_buf, compSize);
else // compressed chunk bigger than LZF_CHUNK_SIZE (and uncompressed)
outStr->append((const char *)in_data + i, chunkSize);
}
unsigned compressedSize = lzf_compress((const char *)in_data,
in_len, lzf_buf, lzf_bufSize);
assert (0 < compressedSize);
return compressedSize;
}
void * DbgContext::GetReadPixelsBuffer(const unsigned size)
@ -140,13 +149,13 @@ void * DbgContext::GetReadPixelsBuffer(const unsigned size)
return lzf_ref[lzf_readIndex];
}
unsigned DbgContext::CompressReadPixelBuffer()
void DbgContext::CompressReadPixelBuffer(std::string * const outStr)
{
unsigned * const ref = lzf_ref[lzf_readIndex ^ 1];
unsigned * const src = lzf_ref[lzf_readIndex];
for (unsigned i = 0; i < lzf_refSize / sizeof(*ref) + 1; i++)
ref[i] ^= src[i];
return Compress(ref, lzf_refSize);
Compress(ref, lzf_refSize, outStr);
}
void DbgContext::glUseProgram(GLuint program)

View File

@ -56,12 +56,10 @@ using namespace com::android;
namespace android
{
struct GLFunctionBitfield
{
struct GLFunctionBitfield {
unsigned char field [24]; // 8 * 24 = 192
void Bit(const glesv2debugger::Message_Function function, bool bit)
{
void Bit(const glesv2debugger::Message_Function function, bool bit) {
const unsigned byte = function / 8, mask = 1 << (function % 8);
if (bit)
field[byte] |= mask;
@ -69,8 +67,7 @@ struct GLFunctionBitfield
field[byte] &= ~mask;
}
bool Bit(const glesv2debugger::Message_Function function) const
{
bool Bit(const glesv2debugger::Message_Function function) const {
const unsigned byte = function / 8, mask = 1 << (function % 8);
return field[byte] & mask;
}
@ -78,7 +75,8 @@ struct GLFunctionBitfield
struct DbgContext {
private:
unsigned lzf_bufSize;
static const unsigned int LZF_CHUNK_SIZE = 256 * 1024;
char * lzf_buf; // malloc / free; for lzf chunk compression
// used as buffer and reference frame for ReadPixels; malloc/free
unsigned * lzf_ref [2];
@ -86,8 +84,6 @@ private:
unsigned lzf_refSize, lzf_refBufSize; // bytes
public:
char * lzf_buf; // auto malloc/free; output of lzf_compress
const unsigned version; // 0 is GLES1, 1 is GLES2
const gl_hooks_t * const hooks;
const unsigned MAX_VERTEX_ATTRIBS;
@ -122,21 +118,23 @@ public:
GLuint program;
unsigned maxAttrib; // number of slots used by program
DbgContext(const unsigned version, const gl_hooks_t * const hooks, const unsigned MAX_VERTEX_ATTRIBS);
DbgContext(const unsigned version, const gl_hooks_t * const hooks,
const unsigned MAX_VERTEX_ATTRIBS);
~DbgContext();
void Fetch(const unsigned index, std::string * const data) const;
unsigned Compress(const void * in_data, unsigned in_len); // compressed to lzf_buf
void Compress(const void * in_data, unsigned in_len, std::string * const outStr);
void * GetReadPixelsBuffer(const unsigned size);
bool IsReadPixelBuffer(const void * const ptr) {
return ptr == lzf_ref[lzf_readIndex];
}
unsigned CompressReadPixelBuffer();
void CompressReadPixelBuffer(std::string * const outStr);
void glUseProgram(GLuint program);
void glEnableVertexAttribArray(GLuint index);
void glDisableVertexAttribArray(GLuint index);
void glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr);
void glVertexAttribPointer(GLuint indx, GLint size, GLenum type,
GLboolean normalized, GLsizei stride, const GLvoid* ptr);
void glBindBuffer(GLenum target, GLuint buffer);
void glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
@ -148,7 +146,8 @@ DbgContext * getDbgContextThreadSpecific();
#define DBGCONTEXT(ctx) DbgContext * const ctx = getDbgContextThreadSpecific();
struct FunctionCall {
virtual const int * operator()(gl_hooks_t::gl_t const * const _c, glesv2debugger::Message & msg) = 0;
virtual const int * operator()(gl_hooks_t::gl_t const * const _c,
glesv2debugger::Message & msg) = 0;
virtual ~FunctionCall() {}
};

View File

@ -39,7 +39,6 @@ void Debug_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
msg.set_arg6(reinterpret_cast<int>(pixels));
const unsigned size = width * height * GetBytesPerPixel(format, type);
unsigned compressed = 0;
if (!expectResponse)
cmd.set_function(glesv2debugger::Message_Function_CONTINUE);
Send(msg, cmd);
@ -56,13 +55,12 @@ void Debug_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
msg.set_type(glesv2debugger::Message_Type_AfterCall);
msg.set_expect_response(expectResponse);
if (dbg->IsReadPixelBuffer(pixels)) {
compressed = dbg->CompressReadPixelBuffer();
dbg->CompressReadPixelBuffer(msg.mutable_data());
msg.set_data_type(msg.ReferencedImage);
} else {
compressed = dbg->Compress(pixels, size);
dbg->Compress(pixels, size, msg.mutable_data());
msg.set_data_type(msg.NonreferencedImage);
}
msg.set_data(dbg->lzf_buf, compressed);
if (!expectResponse)
cmd.set_function(glesv2debugger::Message_Function_SKIP);
Send(msg, cmd);