From 9d73baf12366a29c52038bab976db0208af3ab21 Mon Sep 17 00:00:00 2001 From: Jon Ashburn Date: Fri, 13 Feb 2015 11:25:53 -0700 Subject: [PATCH] glave: Replay for UpdateDescriptor handle multiple replays The local chain copy had embedded pointers into the original chain. So multiple replays/remaps weren't working. Simplify code to just save a queue of the actaul objects that need to be remapped and restore them after making the call to xglUpdateDescriptors(). --- glave-generate.py | 148 +++++++++++++++++++++++++++------------------- 1 file changed, 88 insertions(+), 60 deletions(-) diff --git a/glave-generate.py b/glave-generate.py index 88db3f8c..a136cec2 100755 --- a/glave-generate.py +++ b/glave-generate.py @@ -2691,96 +2691,123 @@ class Subcommand(object): def _gen_replay_update_descriptors(self): ud_body = [] - # TODO : Add code here to read chain of update structs - # We have to remap handles internal to the structures so make complete local copy of update chain - # and remap all of the handles inside of the update structs + # We have to remap handles internal to the structures so save the handles prior to remap and then restore + # Rather than doing a deep memcpy of the entire struct and fixing any intermediate pointers, do save and restores via STL queue ud_body.append(' XGL_UPDATE_SAMPLERS* pUpdateChain = (XGL_UPDATE_SAMPLERS*)pPacket->pUpdateChain;') - ud_body.append(' void* pLocalUpdateChain = NULL;') - ud_body.append(' XGL_UPDATE_SAMPLERS* pPrev = NULL;') - ud_body.append(' void* pLocalUpdateChainHEAD = NULL;') - ud_body.append(' size_t blockSize = 0;') + ud_body.append(' std::queue saveSamplers;') + ud_body.append(' std::queue saveBufferViews;') + ud_body.append(' std::queue saveImageViews;') + ud_body.append(' std::queue saveDescSets;') ud_body.append(' while (pUpdateChain) {') ud_body.append(' switch(pUpdateChain->sType)') ud_body.append(' {') ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:') - ud_body.append(' blockSize = sizeof(XGL_UPDATE_SAMPLERS) + ((XGL_UPDATE_SAMPLERS*)pUpdateChain)->count * sizeof(XGL_SAMPLER);') - ud_body.append(' pLocalUpdateChain = (void*)malloc(blockSize);') - ud_body.append(' memcpy(pLocalUpdateChain, pUpdateChain, blockSize);') - ud_body.append(' for (uint32_t i = 0; i < ((XGL_UPDATE_SAMPLERS*)pLocalUpdateChain)->count; i++) {') - ud_body.append(' XGL_SAMPLER* pLocalSampler = (XGL_SAMPLER*) &((XGL_UPDATE_SAMPLERS*)pLocalUpdateChain)->pSamplers[i];') + ud_body.append(' for (uint32_t i = 0; i < ((XGL_UPDATE_SAMPLERS*)pUpdateChain)->count; i++) {') + ud_body.append(' XGL_SAMPLER* pLocalSampler = (XGL_SAMPLER*) &((XGL_UPDATE_SAMPLERS*)pUpdateChain)->pSamplers[i];') + ud_body.append(' saveSamplers.push(*pLocalSampler);') ud_body.append(' *pLocalSampler = remap(((XGL_UPDATE_SAMPLERS*)pUpdateChain)->pSamplers[i]);') ud_body.append(' }') ud_body.append(' break;') ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:') - ud_body.append(' blockSize = sizeof(XGL_UPDATE_SAMPLER_TEXTURES) + ((XGL_UPDATE_SAMPLER_TEXTURES*)pUpdateChain)->count * (sizeof(XGL_SAMPLER_IMAGE_VIEW_INFO) + sizeof(XGL_IMAGE_VIEW_ATTACH_INFO));') - ud_body.append(' XGL_UPDATE_SAMPLER_TEXTURES *pLocalUST;') - ud_body.append(' pLocalUST = (XGL_UPDATE_SAMPLER_TEXTURES *)malloc(blockSize);') - ud_body.append(' memcpy(pLocalUST, pUpdateChain, blockSize);') - ud_body.append(' for (uint32_t i = 0; i < pLocalUST->count; i++) {') - ud_body.append(' XGL_SAMPLER *plocalSampler = (XGL_SAMPLER *) &pLocalUST->pSamplerImageViews[i].pSampler; ') - ud_body.append(' *plocalSampler = remap(((XGL_UPDATE_SAMPLER_TEXTURES*)pUpdateChain)->pSamplerImageViews[i].pSampler);') - ud_body.append(' XGL_IMAGE_VIEW *pLocalView = (XGL_IMAGE_VIEW *)&pLocalUST->pSamplerImageViews[i].pImageView->view; ') - ud_body.append(' *pLocalView = remap(((XGL_UPDATE_SAMPLER_TEXTURES*)pUpdateChain)->pSamplerImageViews[i].pImageView->view);') + ud_body.append(' {') + ud_body.append(' XGL_UPDATE_SAMPLER_TEXTURES *pUST = (XGL_UPDATE_SAMPLER_TEXTURES *) pUpdateChain;') + ud_body.append(' for (uint32_t i = 0; i < pUST->count; i++) {') + ud_body.append(' XGL_SAMPLER *pLocalSampler = (XGL_SAMPLER *) &pUST->pSamplerImageViews[i].pSampler;') + ud_body.append(' saveSamplers.push(*pLocalSampler);') + ud_body.append(' *pLocalSampler = remap(pUST->pSamplerImageViews[i].pSampler);') + ud_body.append(' XGL_IMAGE_VIEW *pLocalView = (XGL_IMAGE_VIEW *) &pUST->pSamplerImageViews[i].pImageView->view;') + ud_body.append(' saveImageViews.push(*pLocalView);') + ud_body.append(' *pLocalView = remap(pUST->pSamplerImageViews[i].pImageView->view);') ud_body.append(' }') - ud_body.append(' pLocalUpdateChain = (void *) pLocalUST;') ud_body.append(' break;') + ud_body.append(' }') ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:') - ud_body.append(' blockSize = sizeof(XGL_UPDATE_IMAGES) + (((XGL_UPDATE_IMAGES*)pUpdateChain)->count * (sizeof(XGL_IMAGE_VIEW_ATTACH_INFO*) + sizeof(XGL_IMAGE_VIEW_ATTACH_INFO)));') - ud_body.append(' pLocalUpdateChain = malloc(blockSize);') - ud_body.append(' memcpy(pLocalUpdateChain, pUpdateChain, blockSize);') - ud_body.append(' for (uint32_t i = 0; i < ((XGL_UPDATE_IMAGES*)pLocalUpdateChain)->count; i++) {') - ud_body.append(' XGL_IMAGE_VIEW* pLocalView = (XGL_IMAGE_VIEW*) &((XGL_UPDATE_IMAGES*)pUpdateChain)->pImageViews[i]->view;') - ud_body.append(' *pLocalView = remap(((XGL_UPDATE_IMAGES*)pUpdateChain)->pImageViews[i]->view);') + ud_body.append(' {') + ud_body.append(' XGL_UPDATE_IMAGES *pUI = (XGL_UPDATE_IMAGES*) pUpdateChain;') + ud_body.append(' for (uint32_t i = 0; i < pUI->count; i++) {') + ud_body.append(' XGL_IMAGE_VIEW* pLocalView = (XGL_IMAGE_VIEW*) &pUI->pImageViews[i]->view;') + ud_body.append(' saveImageViews.push(*pLocalView);') + ud_body.append(' *pLocalView = remap(pUI->pImageViews[i]->view);') ud_body.append(' }') ud_body.append(' break;') + ud_body.append(' }') ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:') - ud_body.append(' blockSize = sizeof(XGL_UPDATE_BUFFERS) + (((XGL_UPDATE_BUFFERS*)pUpdateChain)->count * (sizeof(XGL_BUFFER_VIEW_ATTACH_INFO*) + sizeof(XGL_BUFFER_VIEW_ATTACH_INFO)));') - ud_body.append(' pLocalUpdateChain = malloc(blockSize);') - ud_body.append(' memcpy(pLocalUpdateChain, pUpdateChain, blockSize);') - ud_body.append(' for (uint32_t i = 0; i < ((XGL_UPDATE_BUFFERS*)pLocalUpdateChain)->count; i++) {') - ud_body.append(' XGL_BUFFER_VIEW* pLocalView = (XGL_BUFFER_VIEW*) &((XGL_UPDATE_BUFFERS*)pUpdateChain)->pBufferViews[i]->view;') - ud_body.append(' *pLocalView = remap(((XGL_UPDATE_BUFFERS*)pUpdateChain)->pBufferViews[i]->view);') + ud_body.append(' {') + ud_body.append(' XGL_UPDATE_BUFFERS *pUB = (XGL_UPDATE_BUFFERS *) pUpdateChain;') + ud_body.append(' for (uint32_t i = 0; i < pUB->count; i++) {') + ud_body.append(' XGL_BUFFER_VIEW* pLocalView = (XGL_BUFFER_VIEW*) &pUB->pBufferViews[i]->view;') + ud_body.append(' saveBufferViews.push(*pLocalView);') + ud_body.append(' *pLocalView = remap(pUB->pBufferViews[i]->view);') ud_body.append(' }') ud_body.append(' break;') + ud_body.append(' }') ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:') - ud_body.append(' blockSize += sizeof(XGL_UPDATE_AS_COPY);') - ud_body.append(' pLocalUpdateChain = malloc(blockSize);') - ud_body.append(' memcpy(pLocalUpdateChain, pUpdateChain, blockSize);') - ud_body.append(' ((XGL_UPDATE_AS_COPY*)pLocalUpdateChain)->descriptorSet = remap(((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet);') + ud_body.append(' saveDescSets.push(((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet);') + ud_body.append(' ((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet = remap(((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet);') ud_body.append(' break;') ud_body.append(' default:') - ud_body.append(' // TODO : Flag error here') + ud_body.append(' assert(0);') ud_body.append(' break;') ud_body.append(' }') - ud_body.append(' if (NULL == pLocalUpdateChainHEAD) {') - ud_body.append(' pLocalUpdateChainHEAD = pLocalUpdateChain;') - ud_body.append(' }') - ud_body.append(' if (pPrev) {') - ud_body.append(' pPrev->pNext = pLocalUpdateChain;') - ud_body.append(' }') - ud_body.append(' pPrev = (XGL_UPDATE_SAMPLERS*)pLocalUpdateChain;') - ud_body.append(' pUpdateChain = (XGL_UPDATE_SAMPLERS*)pUpdateChain->pNext;') + ud_body.append(' pUpdateChain = (XGL_UPDATE_SAMPLERS*) pUpdateChain->pNext;') ud_body.append(' }') - ud_body.append(' m_xglFuncs.real_xglUpdateDescriptors(remap(pPacket->descriptorSet), pLocalUpdateChainHEAD);') - ud_body.append(' pLocalUpdateChain = (XGL_UPDATE_SAMPLERS*)pLocalUpdateChainHEAD;') - ud_body.append(' XGL_UPDATE_SAMPLERS* pFreeMe = NULL;') - ud_body.append(' while (pLocalUpdateChain) {') - ud_body.append(' switch(((XGL_UPDATE_SAMPLERS*)pLocalUpdateChain)->sType)') + ud_body.append(' m_xglFuncs.real_xglUpdateDescriptors(remap(pPacket->descriptorSet), pPacket->pUpdateChain);') + ud_body.append(' pUpdateChain = (XGL_UPDATE_SAMPLERS*) pPacket->pUpdateChain;') + ud_body.append(' while (pUpdateChain) {') + ud_body.append(' switch(pUpdateChain->sType)') ud_body.append(' {') ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:') - ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:') - ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:') - ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:') + ud_body.append(' for (uint32_t i = 0; i < ((XGL_UPDATE_SAMPLERS*)pUpdateChain)->count; i++) {') + ud_body.append(' XGL_SAMPLER* pLocalSampler = (XGL_SAMPLER*) &((XGL_UPDATE_SAMPLERS*)pUpdateChain)->pSamplers[i];') + ud_body.append(' *pLocalSampler = saveSamplers.front();') + ud_body.append(' saveSamplers.pop();') + ud_body.append(' }') + ud_body.append(' break;') ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:') - ud_body.append(' pFreeMe = (XGL_UPDATE_SAMPLERS*)pLocalUpdateChain;') - ud_body.append(' pLocalUpdateChain = (void*)((XGL_UPDATE_SAMPLERS*)pLocalUpdateChain)->pNext;') - ud_body.append(' free(pFreeMe);') + ud_body.append(' {') + ud_body.append(' XGL_UPDATE_SAMPLER_TEXTURES *pUST = (XGL_UPDATE_SAMPLER_TEXTURES *) pUpdateChain;') + ud_body.append(' for (uint32_t i = 0; i < pUST->count; i++) {') + ud_body.append(' XGL_SAMPLER *plocalSampler = (XGL_SAMPLER *) &pUST->pSamplerImageViews[i].pSampler;') + ud_body.append(' *plocalSampler = saveSamplers.front();') + ud_body.append(' saveSamplers.pop();') + ud_body.append(' XGL_IMAGE_VIEW *pLocalView = (XGL_IMAGE_VIEW *) &pUST->pSamplerImageViews[i].pImageView->view;') + ud_body.append(' *pLocalView = saveImageViews.front();') + ud_body.append(' saveImageViews.pop();') + ud_body.append(' }') + ud_body.append(' break;') + ud_body.append(' }') + ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:') + ud_body.append(' {') + ud_body.append(' XGL_UPDATE_IMAGES *pUI = (XGL_UPDATE_IMAGES*) pUpdateChain;') + ud_body.append(' for (uint32_t i = 0; i < pUI->count; i++) {') + ud_body.append(' XGL_IMAGE_VIEW* pLocalView = (XGL_IMAGE_VIEW*) &pUI->pImageViews[i]->view;') + ud_body.append(' *pLocalView = saveImageViews.front();') + ud_body.append(' saveImageViews.pop();') + ud_body.append(' }') + ud_body.append(' break;') + ud_body.append(' }') + ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:') + ud_body.append(' {') + ud_body.append(' XGL_UPDATE_BUFFERS *pUB = (XGL_UPDATE_BUFFERS *) pUpdateChain;') + ud_body.append(' for (uint32_t i = 0; i < pUB->count; i++) {') + ud_body.append(' XGL_BUFFER_VIEW* pLocalView = (XGL_BUFFER_VIEW*) &pUB->pBufferViews[i]->view;') + ud_body.append(' *pLocalView = saveBufferViews.front();') + ud_body.append(' saveBufferViews.pop();') + ud_body.append(' }') + ud_body.append(' break;') + ud_body.append(' }') + ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:') + ud_body.append(' ((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet = saveDescSets.front();') + ud_body.append(' saveDescSets.pop();') + ud_body.append(' //pFreeMe = (XGL_UPDATE_SAMPLERS*)pLocalUpdateChain;') + ud_body.append(' //pLocalUpdateChain = (void*)((XGL_UPDATE_SAMPLERS*)pLocalUpdateChain)->pNext;') + ud_body.append(' //free(pFreeMe);') ud_body.append(' break;') ud_body.append(' default:') - ud_body.append(' // TODO : Flag error here') - ud_body.append(' pLocalUpdateChain = (void*)((XGL_UPDATE_SAMPLERS*)pLocalUpdateChain)->pNext;') + ud_body.append(' assert(0);') ud_body.append(' break;') ud_body.append(' }') + ud_body.append(' pUpdateChain = (XGL_UPDATE_SAMPLERS*) pUpdateChain->pNext;') ud_body.append(' }') return "\n".join(ud_body) @@ -3565,6 +3592,7 @@ class GlaveReplayC(Subcommand): header_txt.append('#include "glvreplay_xgl_write_ppm.h"\n') header_txt.append('#include "glvreplay_main.h"\n') header_txt.append('#include ') + header_txt.append('#include ') header_txt.append('extern glvreplay_settings *g_pReplaySettings;') header_txt.append('extern "C" {') header_txt.append('#include "glvtrace_xgl_xgl_structs.h"')