diff options
author | David 'Digit' Turner <digit@google.com> | 2011-09-20 15:19:42 +0200 |
---|---|---|
committer | David 'Digit' Turner <digit@google.com> | 2011-09-20 15:58:54 +0200 |
commit | 894a63dd6eb8a1c675c21a8a10eff8c0118890c8 (patch) | |
tree | bb3ea6c47fe46cb229bc5862172b2ef2d3aeb508 | |
parent | 5d7f0875e9cda2d6ab37b49f0b6ceed8f0d16f45 (diff) | |
download | development-gingerbread.tar.gz |
emulator: opengl: Add custom_write optimization to encoder.android-cts-2.3_r12android-cts-2.3_r11android-cts-2.3_r10gingerbread
This patch allows an auto-generated GLES encoder function to write
'isLarge' buffers with a custom writer, instead of calling stream->readFully()
directly.
This is intended to allow writing pixel or vertex data that is stored
with a specific stride.
Another patch will introduce the corresponding changes to the .attrib files
Change-Id: I6ca86b968cd3f4db91676bc485ee1e84419e50e0
5 files changed, 59 insertions, 5 deletions
diff --git a/tools/emulator/opengl/host/tools/emugen/ApiGen.cpp b/tools/emulator/opengl/host/tools/emugen/ApiGen.cpp index 72b7bb314..42653013c 100644 --- a/tools/emulator/opengl/host/tools/emugen/ApiGen.cpp +++ b/tools/emulator/opengl/host/tools/emugen/ApiGen.cpp @@ -436,7 +436,12 @@ static void writeVarLargeEncodingExpression(Var& var, FILE* fp) } else { fprintf(fp, "\t"); } - fprintf(fp, "stream->writeFully(%s, __size_%s);\n", varname, varname); + if (var.writeExpression() != "") { + fprintf(fp, "%s", var.writeExpression().c_str()); + } else { + fprintf(fp, "stream->writeFully(%s, __size_%s)", varname, varname); + } + fprintf(fp, ";\n"); } #endif /* WITH_LARGE_SUPPORT */ diff --git a/tools/emulator/opengl/host/tools/emugen/EntryPoint.cpp b/tools/emulator/opengl/host/tools/emugen/EntryPoint.cpp index 044433d90..43b904bee 100644 --- a/tools/emulator/opengl/host/tools/emugen/EntryPoint.cpp +++ b/tools/emulator/opengl/host/tools/emugen/EntryPoint.cpp @@ -119,7 +119,7 @@ bool EntryPoint::parse(unsigned int lc, const std::string & str) fprintf(stderr, "UNKNOWN retval: %s\n", linestr.c_str()); } - m_retval.init(std::string(""), theType, std::string(""), Var::POINTER_OUT, std::string("")); + m_retval.init(std::string(""), theType, std::string(""), Var::POINTER_OUT, std::string(""), std::string("")); // function name m_name = getNextToken(linestr, pos, &last, ",)"); @@ -146,7 +146,7 @@ bool EntryPoint::parse(unsigned int lc, const std::string & str) varname = oss.str(); } - m_vars.push_back(Var(varname, v, std::string(""), Var::POINTER_IN, "")); + m_vars.push_back(Var(varname, v, std::string(""), Var::POINTER_IN, "", "")); } pos = last + 1; } @@ -334,6 +334,23 @@ int EntryPoint::setAttribute(const std::string &line, size_t lc) // set the size expression into var pos = last; v->setPackExpression(line.substr(pos)); + } else if (token == "custom_write") { + pos = last; + std::string varname = getNextToken(line, pos, &last, WHITESPACE); + + if (varname.size() == 0) { + fprintf(stderr, "ERROR: %u: Missing variable name in 'custom_write' attribute\n", (unsigned int)lc); + return -1; + } + Var * v = var(varname); + if (v == NULL) { + fprintf(stderr, "ERROR: %u: variable %s is not a parameter of %s\n", + (unsigned int)lc, varname.c_str(), name().c_str()); + return -2; + } + // set the size expression into var + pos = last; + v->setWriteExpression(line.substr(pos)); } else if (token == "flag") { pos = last; std::string flag = getNextToken(line, pos, &last, WHITESPACE); diff --git a/tools/emulator/opengl/host/tools/emugen/Var.h b/tools/emulator/opengl/host/tools/emugen/Var.h index 658b80566..322c66a92 100644 --- a/tools/emulator/opengl/host/tools/emugen/Var.h +++ b/tools/emulator/opengl/host/tools/emugen/Var.h @@ -32,6 +32,7 @@ public: m_nullAllowed(false), m_isLarge(false), m_packExpression(""), + m_writeExpression(""), m_paramCheckExpression("") { @@ -41,7 +42,8 @@ public: const VarType * vartype, const std::string & lenExpression, PointerDir dir, - const std::string &packExpression) : + const std::string &packExpression, + const std::string &writeExpression) : m_name(name), m_type(const_cast<VarType *>(vartype)), m_lenExpression(lenExpression), @@ -49,17 +51,21 @@ public: m_nullAllowed(false), m_isLarge(false), m_packExpression(packExpression), + m_writeExpression(writeExpression), m_paramCheckExpression("") { } void init(const std::string name, const VarType * vartype, std::string lenExpression, - PointerDir dir, std::string packExpression) { + PointerDir dir, + std::string packExpression, + std::string writeExpression) { m_name = name; m_type = vartype; m_lenExpression = lenExpression; m_packExpression = packExpression; + m_writeExpression = writeExpression; m_pointerDir = dir; m_nullAllowed = false; m_isLarge = false; @@ -72,9 +78,11 @@ public: bool isVoid() const { return ((m_type->bytes() == 0) && (!m_type->isPointer())); } const std::string & lenExpression() const { return m_lenExpression; } const std::string & packExpression() const { return(m_packExpression); } + const std::string & writeExpression() const { return(m_writeExpression); } const std::string & paramCheckExpression() const { return m_paramCheckExpression; } void setLenExpression(const std::string & lenExpression) { m_lenExpression = lenExpression; } void setPackExpression(const std::string & packExpression) { m_packExpression = packExpression; } + void setWriteExpression(const std::string & writeExpression) { m_writeExpression = writeExpression; } void setParamCheckExpression(const std::string & paramCheckExpression) { m_paramCheckExpression = paramCheckExpression; } void setPointerDir(PointerDir dir) { m_pointerDir = dir; } PointerDir pointerDir() { return m_pointerDir; } @@ -94,6 +102,7 @@ private: bool m_nullAllowed; bool m_isLarge; std::string m_packExpression; // an expression to pack data into the stream + std::string m_writeExpression; // an expression to write data into the stream std::string m_paramCheckExpression; //an expression to check parameter value }; diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.cpp b/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.cpp index b0702a76d..ae70598a3 100644 --- a/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.cpp +++ b/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.cpp @@ -16,6 +16,7 @@ #include "glUtils.h" #include <string.h> #include "ErrorLog.h" +#include <IOStream.h> size_t glSizeof(GLenum type) { @@ -344,6 +345,25 @@ void glUtilsPackPointerData(unsigned char *dst, unsigned char *src, } } +void glUtilsWritePackPointerData(void* _stream, unsigned char *src, + int size, GLenum type, unsigned int stride, + unsigned int datalen) +{ + IOStream* stream = reinterpret_cast<IOStream*>(_stream); + + unsigned int vsize = size * glSizeof(type); + if (stride == 0) stride = vsize; + + if (stride == vsize) { + stream->writeFully(src, datalen); + } else { + for (unsigned int i = 0; i < datalen; i += vsize) { + stream->writeFully(src, (size_t)vsize); + src += stride; + } + } +} + int glUtilsPixelBitSize(GLenum format, GLenum type) { int components = 0; diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.h b/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.h index c66c568f0..f8857f165 100644 --- a/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.h +++ b/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.h @@ -51,6 +51,9 @@ extern "C" { void glUtilsPackPointerData(unsigned char *dst, unsigned char *str, int size, GLenum type, unsigned int stride, unsigned int datalen); + void glUtilsWritePackPointerData(void* stream, unsigned char *src, + int size, GLenum type, unsigned int stride, + unsigned int datalen); int glUtilsPixelBitSize(GLenum format, GLenum type); void glUtilsPackStrings(char *ptr, char **strings, GLint *length, GLsizei count); int glUtilsCalcShaderSourceLen(char **strings, GLint *length, GLsizei count); |