Favour DSA texture queries, avoid binding, use GetNumMips

* We only bind where necessary to create (as I don't want to rely on
  glCreate* from ARB_dsa/4.5 yet).
This commit is contained in:
baldurk
2014-11-30 14:48:08 +00:00
parent 5e6e243c67
commit 4cbb4c888a
2 changed files with 36 additions and 95 deletions
+27 -68
View File
@@ -164,39 +164,30 @@ bool GLResourceManager::Prepare_InitialState(GLResource res)
{
WrappedOpenGL::TextureData &details = m_GL->m_Textures[Id];
GLenum binding = TextureBinding(details.curType);
GLuint oldtex = 0;
gl.glGetIntegerv(binding, (GLint *)&oldtex);
GLuint tex;
gl.glGenTextures(1, &tex);
GLuint tex = 0;
gl.glBindTexture(details.curType, res.name);
{
GLuint oldtex = 0;
gl.glGetIntegerv(binding, (GLint *)&oldtex);
gl.glGenTextures(1, &tex);
gl.glBindTexture(details.curType, tex);
gl.glBindTexture(details.curType, oldtex);
}
int depth = details.depth;
if(details.curType != eGL_TEXTURE_3D) depth = 1;
int mips = 0;
GLint isComp = 0;
GLenum queryType = details.curType;
if(queryType == eGL_TEXTURE_CUBE_MAP || queryType == eGL_TEXTURE_CUBE_MAP_ARRAY)
queryType = eGL_TEXTURE_CUBE_MAP_POSITIVE_X;
gl.glGetTexLevelParameteriv(queryType, 0, eGL_TEXTURE_COMPRESSED, &isComp);
GLint immut = 0;
gl.glGetTexParameteriv(details.curType, eGL_TEXTURE_IMMUTABLE_FORMAT, &immut);
if(immut)
gl.glGetTexParameteriv(details.curType, eGL_TEXTURE_IMMUTABLE_LEVELS, (GLint *)&mips);
else
mips = CalcNumMips(details.width, details.height, details.depth);
GLint maxLevel = 1000;
gl.glGetTexParameteriv(details.curType, eGL_TEXTURE_MAX_LEVEL, &maxLevel);
mips = RDCMIN(mips, maxLevel+1);
gl.glBindTexture(details.curType, tex);
gl.glGetTextureLevelParameterivEXT(res.name, queryType, 0, eGL_TEXTURE_COMPRESSED, &isComp);
int mips = GetNumMips(gl, details.curType, tex, details.width, details.height, details.depth);
// create texture of identical format/size to store initial contents
if(details.curType == eGL_TEXTURE_2D_MULTISAMPLE)
@@ -258,8 +249,6 @@ bool GLResourceManager::Prepare_InitialState(GLResource res)
}
SetInitialContents(Id, InitialContentData(TextureRes(res.Context, tex), 0, (byte *)state));
gl.glBindTexture(details.curType, oldtex);
}
else if(res.Namespace == eResVertexArray)
{
@@ -402,31 +391,15 @@ bool GLResourceManager::Serialise_InitialState(GLResource res)
gl.glPixelStorei(eGL_PACK_SKIP_IMAGES, 0);
gl.glPixelStorei(eGL_PACK_ALIGNMENT, 1);
GLuint prevtex = 0;
gl.glGetIntegerv(TextureBinding(details.curType), (GLint *)&prevtex);
gl.glBindTexture(details.curType, res.name);
int imgmips = 0;
GLint isComp = 0;
GLenum queryType = details.curType;
if(queryType == eGL_TEXTURE_CUBE_MAP || queryType == eGL_TEXTURE_CUBE_MAP_ARRAY)
queryType = eGL_TEXTURE_CUBE_MAP_POSITIVE_X;
gl.glGetTexLevelParameteriv(queryType, 0, eGL_TEXTURE_COMPRESSED, &isComp);
GLint immut = 0;
gl.glGetTexParameteriv(details.curType, eGL_TEXTURE_IMMUTABLE_FORMAT, &immut);
if(immut)
gl.glGetTexParameteriv(details.curType, eGL_TEXTURE_IMMUTABLE_LEVELS, (GLint *)&imgmips);
else
imgmips = CalcNumMips(details.width, details.height, details.depth);
GLint maxLevel = 1000;
gl.glGetTexParameteriv(details.curType, eGL_TEXTURE_MAX_LEVEL, &maxLevel);
imgmips = RDCMIN(imgmips, maxLevel+1);
gl.glGetTextureLevelParameterivEXT(res.name, queryType, 0, eGL_TEXTURE_COMPRESSED, &isComp);
int imgmips = GetNumMips(gl, details.curType, tex, details.width, details.height, details.depth);
TextureStateInitialData *state = (TextureStateInitialData *)GetInitialContents(Id).blob;
@@ -538,8 +511,6 @@ bool GLResourceManager::Serialise_InitialState(GLResource res)
delete[] buf;
}
gl.glBindTexture(t, prevtex);
gl.glBindBuffer(eGL_PIXEL_PACK_BUFFER, ppb);
@@ -554,9 +525,6 @@ bool GLResourceManager::Serialise_InitialState(GLResource res)
}
else
{
GLuint tex = 0;
gl.glGenTextures(1, &tex);
GLuint pub = 0;
gl.glGetIntegerv(eGL_PIXEL_UNPACK_BUFFER_BINDING, (GLint *)&pub);
gl.glBindBuffer(eGL_PIXEL_UNPACK_BUFFER, 0);
@@ -594,10 +562,17 @@ bool GLResourceManager::Serialise_InitialState(GLResource res)
SERIALISE_ELEMENT(int, mips, 0);
SERIALISE_ELEMENT(bool, isCompressed, false);
GLuint prevtex = 0;
gl.glGetIntegerv(TextureBinding(textype), (GLint *)&prevtex);
GLuint tex = 0;
gl.glBindTexture(textype, tex);
{
GLuint prevtex = 0;
gl.glGetIntegerv(TextureBinding(textype), (GLint *)&prevtex);
gl.glGenTextures(1, &tex);
gl.glBindTexture(textype, tex);
gl.glBindTexture(textype, prevtex);
}
// create texture of identical format/size to store initial contents
if(textype == eGL_TEXTURE_2D_MULTISAMPLE)
@@ -715,8 +690,6 @@ bool GLResourceManager::Serialise_InitialState(GLResource res)
SetInitialContents(Id, InitialContentData(TextureRes(m_GL->GetCtx(), tex), 0, (byte *)state));
gl.glBindBuffer(eGL_PIXEL_UNPACK_BUFFER, pub);
gl.glBindTexture(textype, prevtex);
gl.glPixelStorei(eGL_UNPACK_SWAP_BYTES, unpackParams[0]);
gl.glPixelStorei(eGL_UNPACK_LSB_FIRST, unpackParams[1]);
@@ -783,22 +756,8 @@ void GLResourceManager::Apply_InitialState(GLResource live, InitialContentData i
WrappedOpenGL::TextureData &details = m_GL->m_Textures[Id];
GLuint tex = initial.resource.name;
gl.glBindTexture(details.curType, tex);
int mips = 0;
GLint immut = 0;
gl.glGetTexParameteriv(details.curType, eGL_TEXTURE_IMMUTABLE_FORMAT, &immut);
if(immut)
gl.glGetTexParameteriv(details.curType, eGL_TEXTURE_IMMUTABLE_LEVELS, (GLint *)&mips);
else
mips = CalcNumMips(details.width, details.height, details.depth);
GLint maxLevel = 1000;
gl.glGetTexParameteriv(details.curType, eGL_TEXTURE_MAX_LEVEL, &maxLevel);
mips = RDCMIN(mips, maxLevel+1);
int mips = GetNumMips(gl, details.curType, tex, details.width, details.height, details.depth);
// copy over mips
for(int i=0; i < mips; i++)
+9 -27
View File
@@ -350,18 +350,16 @@ void GLReplay::CacheTexture(ResourceId id)
GLenum target = TextureTarget(res.curType);
gl.glBindTexture(target, res.resource.name);
GLenum levelQueryType = target;
if(levelQueryType == eGL_TEXTURE_CUBE_MAP)
levelQueryType = eGL_TEXTURE_CUBE_MAP_POSITIVE_X;
// TODO if I call this for levels 1, 2, .. etc. Can I get sizes that aren't mip dimensions?
GLint width = 1, height = 1, depth = 1, samples=1;
gl.glGetTexLevelParameteriv(levelQueryType, 0, eGL_TEXTURE_WIDTH, &width);
gl.glGetTexLevelParameteriv(levelQueryType, 0, eGL_TEXTURE_HEIGHT, &height);
gl.glGetTexLevelParameteriv(levelQueryType, 0, eGL_TEXTURE_DEPTH, &depth);
gl.glGetTexLevelParameteriv(levelQueryType, 0, eGL_TEXTURE_SAMPLES, &samples);
gl.glGetTextureLevelParameterivEXT(res.resource.name, levelQueryType, 0, eGL_TEXTURE_WIDTH, &width);
gl.glGetTextureLevelParameterivEXT(res.resource.name, levelQueryType, 0, eGL_TEXTURE_HEIGHT, &height);
gl.glGetTextureLevelParameterivEXT(res.resource.name, levelQueryType, 0, eGL_TEXTURE_DEPTH, &depth);
gl.glGetTextureLevelParameterivEXT(res.resource.name, levelQueryType, 0, eGL_TEXTURE_SAMPLES, &samples);
if(res.width == 0)
{
@@ -439,7 +437,7 @@ void GLReplay::CacheTexture(ResourceId id)
// surely this will be the same for each level... right? that would be insane if it wasn't
GLint fmt = 0;
gl.glGetTexLevelParameteriv(levelQueryType, 0, eGL_TEXTURE_INTERNAL_FORMAT, &fmt);
gl.glGetTextureLevelParameterivEXT(res.resource.name, levelQueryType, 0, eGL_TEXTURE_INTERNAL_FORMAT, &fmt);
tex.format = MakeResourceFormat(gl, target, (GLenum)fmt);
@@ -494,35 +492,19 @@ void GLReplay::CacheTexture(ResourceId id)
tex.msQual = tex.msSamp = 0;
tex.byteSize = 0;
gl.glGetTexLevelParameteriv(levelQueryType, 0, eGL_TEXTURE_BUFFER_SIZE, (GLint *)&tex.width);
gl.glGetTextureLevelParameterivEXT(res.resource.name, levelQueryType, 0, eGL_TEXTURE_BUFFER_SIZE, (GLint *)&tex.width);
tex.byteSize = tex.width/(tex.format.compByteWidth*tex.format.compCount);
m_CachedTextures[id] = tex;
return;
}
GLint immut = 0;
gl.glGetTexParameteriv(target, eGL_TEXTURE_IMMUTABLE_FORMAT, &immut);
if(immut)
{
gl.glGetTexParameteriv(target, eGL_TEXTURE_IMMUTABLE_LEVELS, &immut);
tex.mips = (uint32_t)immut;
}
else
{
// assuming complete texture
tex.mips = CalcNumMips(tex.width, tex.height, tex.depth);
}
GLuint maxLevel = 1000;
gl.glGetTexParameteriv(target, eGL_TEXTURE_MAX_LEVEL, (GLint *)&maxLevel);
tex.mips = RDCMIN(tex.mips, maxLevel+1);
tex.mips = GetNumMips(gl.m_Real, target, res.resource.name, tex.width, tex.height, tex.depth);
tex.numSubresources = tex.mips*tex.arraysize;
GLint compressed;
gl.glGetTexLevelParameteriv(levelQueryType, 0, eGL_TEXTURE_COMPRESSED, &compressed);
gl.glGetTextureLevelParameterivEXT(res.resource.name, levelQueryType, 0, eGL_TEXTURE_COMPRESSED, &compressed);
tex.byteSize = 0;
for(uint32_t a=0; a < tex.arraysize; a++)
{
@@ -530,7 +512,7 @@ void GLReplay::CacheTexture(ResourceId id)
{
if(compressed)
{
gl.glGetTexLevelParameteriv(levelQueryType, m, eGL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed);
gl.glGetTextureLevelParameterivEXT(res.resource.name, levelQueryType, m, eGL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed);
tex.byteSize += compressed;
}
else if(tex.format.special)