FetchTexture GLReplay::GetTexture(ResourceId id) { FetchTexture tex; MakeCurrentReplayContext(&m_ReplayCtx); auto &res = m_pDriver->m_Textures[id]; if(res.resource.Namespace == eResUnknown) { RDCERR("Details for invalid texture id %llu requested", id); RDCEraseEl(tex); return tex; } WrappedOpenGL &gl = *m_pDriver; tex.ID = m_pDriver->GetResourceManager()->GetOriginalID(id); gl.glBindTexture(res.curType, res.resource.name); // 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(res.curType, 0, eGL_TEXTURE_WIDTH, &width); gl.glGetTexLevelParameteriv(res.curType, 0, eGL_TEXTURE_HEIGHT, &height); gl.glGetTexLevelParameteriv(res.curType, 0, eGL_TEXTURE_DEPTH, &depth); gl.glGetTexLevelParameteriv(res.curType, 0, eGL_TEXTURE_SAMPLES, &samples); if(res.width == 0) { RDCWARN("TextureData::width didn't get filled out, setting at last minute"); res.width = width; } if(res.height == 0) { RDCWARN("TextureData::height didn't get filled out, setting at last minute"); res.height = height; } if(res.depth == 0) { RDCWARN("TextureData::depth didn't get filled out, setting at last minute"); res.depth = depth; } // reasonably common defaults tex.msQual = 0; tex.msSamp = 1; tex.width = tex.height = tex.depth = tex.arraysize = 1; tex.cubemap = false; switch(res.curType) { case eGL_TEXTURE_1D: case eGL_TEXTURE_BUFFER: tex.dimension = 1; tex.width = (uint32_t)width; break; case eGL_TEXTURE_1D_ARRAY: tex.dimension = 1; tex.width = (uint32_t)width; tex.arraysize = depth; break; case eGL_TEXTURE_2D: case eGL_TEXTURE_RECTANGLE: case eGL_TEXTURE_2D_MULTISAMPLE: case eGL_TEXTURE_CUBE_MAP: tex.dimension = 2; tex.width = (uint32_t)width; tex.height = (uint32_t)height; tex.cubemap = (res.curType == eGL_TEXTURE_CUBE_MAP); tex.msSamp = (res.curType == eGL_TEXTURE_2D_MULTISAMPLE ? samples : 1); break; case eGL_TEXTURE_2D_ARRAY: case eGL_TEXTURE_2D_MULTISAMPLE_ARRAY: case eGL_TEXTURE_CUBE_MAP_ARRAY: tex.dimension = 2; tex.width = (uint32_t)width; tex.height = (uint32_t)height; tex.arraysize = depth; tex.cubemap = (res.curType == eGL_TEXTURE_CUBE_MAP_ARRAY); tex.msSamp = (res.curType == eGL_TEXTURE_2D_MULTISAMPLE_ARRAY ? samples : 1); break; case eGL_TEXTURE_3D: tex.dimension = 3; tex.width = (uint32_t)width; tex.height = (uint32_t)height; tex.depth = (uint32_t)depth; break; default: tex.dimension = 2; RDCERR("Unexpected texture enum %hs", ToStr::Get(res.curType).c_str()); } GLint immut = 0; gl.glGetTexParameteriv(res.curType, eGL_TEXTURE_IMMUTABLE_FORMAT, &immut); if(immut) { gl.glGetTexParameteriv(res.curType, eGL_TEXTURE_IMMUTABLE_LEVELS, &immut); tex.mips = (uint32_t)immut; } else { // assuming complete texture GLint mips = 1; gl.glGetTexParameteriv(res.curType, eGL_TEXTURE_MAX_LEVEL, &mips); tex.mips = (uint32_t)mips; } tex.numSubresources = tex.mips*tex.arraysize; // surely this will be the same for each level... right? that would be insane if it wasn't GLint fmt = 0; gl.glGetTexLevelParameteriv(res.curType, 0, eGL_TEXTURE_INTERNAL_FORMAT, &fmt); tex.format = MakeResourceFormat(gl, res.curType, (GLenum)fmt); string str = ""; char name[128] = {0}; gl.glGetObjectLabel(eGL_TEXTURE, res.resource.name, 127, NULL, name); str = name; tex.customName = true; if(str == "") { tex.customName = false; str = StringFormat::Fmt("Texture%dD %llu", tex.dimension, tex.ID); } tex.name = widen(str); tex.creationFlags = eTextureCreate_SRV; if(tex.format.compType == eCompType_Depth) tex.creationFlags |= eTextureCreate_DSV; GLNOTIMP("creationFlags are not calculated yet"); tex.byteSize = 0; GLNOTIMP("Not calculating bytesize"); return tex; }
FetchTexture D3D12Replay::GetTexture(ResourceId id) { FetchTexture ret; ret.ID = m_pDevice->GetResourceManager()->GetOriginalID(id); auto it = WrappedID3D12Resource::m_List.find(id); if(it == WrappedID3D12Resource::m_List.end()) return ret; D3D12_RESOURCE_DESC desc = it->second->GetDesc(); ret.format = MakeResourceFormat(desc.Format); ret.dimension = desc.Dimension - D3D12_RESOURCE_DIMENSION_BUFFER; ret.width = (uint32_t)desc.Width; ret.height = desc.Height; ret.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? desc.DepthOrArraySize : 1; ret.arraysize = desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE3D ? desc.DepthOrArraySize : 1; ret.numSubresources = GetNumSubresources(&desc); ret.mips = desc.MipLevels; ret.msQual = desc.SampleDesc.Quality; ret.msSamp = desc.SampleDesc.Count; ret.byteSize = 0; for(uint32_t i = 0; i < ret.mips; i++) ret.byteSize += GetByteSize(ret.width, ret.height, ret.depth, desc.Format, i); switch(ret.dimension) { case 1: ret.resType = ret.arraysize > 1 ? eResType_Texture1DArray : eResType_Texture1D; break; case 2: if(ret.msSamp > 1) ret.resType = ret.arraysize > 1 ? eResType_Texture2DMSArray : eResType_Texture2DMS; else ret.resType = ret.arraysize > 1 ? eResType_Texture2DArray : eResType_Texture2D; break; case 3: ret.resType = eResType_Texture3D; break; } // TODO determine this from usage? ret.cubemap = false; // eResType_TextureCube, eResType_TextureCubeArray ret.creationFlags = eTextureCreate_SRV; if(desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET) ret.creationFlags |= eTextureCreate_RTV; if(desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL) ret.creationFlags |= eTextureCreate_DSV; if(desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS) ret.creationFlags |= eTextureCreate_UAV; if(ret.ID == m_pDevice->GetQueue()->GetBackbufferResourceID()) { ret.format = MakeResourceFormat(GetTypedFormat(desc.Format, eCompType_UNorm)); ret.creationFlags |= eTextureCreate_SwapBuffer; } ret.customName = true; string str = ""; // TODO GetName(it.second); if(str == "") { const char *suffix = ""; const char *ms = ""; if(ret.msSamp > 1) ms = "MS"; if(ret.creationFlags & eTextureCreate_RTV) suffix = " RTV"; if(ret.creationFlags & eTextureCreate_DSV) suffix = " DSV"; ret.customName = false; if(ret.arraysize > 1) str = StringFormat::Fmt("Texture%uD%sArray%s %llu", ret.dimension, ms, suffix, ret.ID); else str = StringFormat::Fmt("Texture%uD%s%s %llu", ret.dimension, ms, suffix, ret.ID); } ret.name = str; return ret; }