cd_body.append('#endif')
cd_body.append(' std::vector<char *>m_extensions;')
cd_body.append('};\n')
- cd_body.append('typedef struct _XGLAllocInfo {')
- cd_body.append(' XGL_GPU_SIZE size;')
- cd_body.append(' void *pData;')
- cd_body.append('} XGLAllocInfo;\n')
cd_body.append('class objMemory {')
cd_body.append('public:')
cd_body.append(' objMemory() : m_numAllocations(0), m_pMemReqs(NULL) {}')
cd_body.append(' uint32_t m_numAllocations;')
cd_body.append(' XGL_MEMORY_REQUIREMENTS *m_pMemReqs;')
cd_body.append('};\n')
+ cd_body.append('class gpuMemory {')
+ cd_body.append('public:')
+ cd_body.append(' gpuMemory() : m_pData(NULL) {m_allocInfo.allocationSize = 0;}')
+ cd_body.append(' ~gpuMemory() {}')
+ cd_body.append(' void setAllocInfo(const XGL_MEMORY_ALLOC_INFO *info);')
+ cd_body.append(' void setMemoryDataAddr(void *pBuf);')
+ cd_body.append(' void copyMappingData(const void *pSrcData);')
+ cd_body.append('private:')
+ cd_body.append(' void *m_pData;')
+ cd_body.append(' XGL_MEMORY_ALLOC_INFO m_allocInfo;')
+ cd_body.append('};\n')
return "\n".join(cd_body)
def _generate_replay_func_ptrs(self):
rc_body.append(' };')
rc_body.append(' std::vector<struct validationMsg> m_validationMsgs;')
rc_body.append(' std::vector<int> m_screenshotFrames;')
- # Custom code for memory mapping functions for app writes into mapped memory
- rc_body.append(' // memory mapping functions for app writes into mapped memory')
- rc_body.append(self._map_decl('XGL_GPU_MEMORY', 'XGLAllocInfo', 'm_mapData'))
- rc_body.append(' void add_entry_to_mapData(XGL_GPU_MEMORY handle, XGL_GPU_SIZE size)')
- rc_body.append(' {')
- rc_body.append(' XGLAllocInfo info;')
- rc_body.append(' info.pData = NULL;')
- rc_body.append(' info.size = size;')
- rc_body.append(' m_mapData.insert(std::pair<XGL_GPU_MEMORY, XGLAllocInfo>(handle, info));')
- rc_body.append(' }')
- rc_body.append(' void add_mapping_to_mapData(XGL_GPU_MEMORY handle, void *pData)')
- rc_body.append(' {')
- rc_body.append(' std::map<XGL_GPU_MEMORY,XGLAllocInfo>::iterator it = m_mapData.find(handle);')
- rc_body.append(' if (it == m_mapData.end())')
- rc_body.append(' {')
- rc_body.append(' glv_LogWarn("add_mapping_to_mapData() could not find entry\\n");')
- rc_body.append(' return;')
- rc_body.append(' }')
- rc_body.append(' XGLAllocInfo &info = it->second;')
- rc_body.append(' if (info.pData != NULL)')
- rc_body.append(' glv_LogWarn("add_mapping_to_mapData() data already mapped overwrite old mapping\\n");')
- rc_body.append(' else if (pData == NULL)')
- rc_body.append(' glv_LogWarn("add_mapping_to_mapData() adding NULL pointer\\n");')
- rc_body.append(' info.pData = pData;')
- rc_body.append(' }')
- rc_body.append(' void rm_entry_from_mapData(XGL_GPU_MEMORY handle)')
- rc_body.append(' {')
- rc_body.append(' std::map<XGL_GPU_MEMORY,XGLAllocInfo>::iterator it = m_mapData.find(handle);')
- rc_body.append(' if (it == m_mapData.end())')
- rc_body.append(' return;')
- rc_body.append(' m_mapData.erase(it);')
- rc_body.append(' }')
- rc_body.append(' void rm_mapping_from_mapData(XGL_GPU_MEMORY handle, void* pData)')
- rc_body.append(' {')
- rc_body.append(' std::map<XGL_GPU_MEMORY,XGLAllocInfo>::iterator it = m_mapData.find(handle);')
- rc_body.append(' if (it == m_mapData.end())')
- rc_body.append(' return;\n')
- rc_body.append(' XGLAllocInfo &info = it->second;')
- rc_body.append(' if (!pData || !info.pData)')
- rc_body.append(' {')
- rc_body.append(' if (!pData)')
- rc_body.append(' glv_LogWarn("rm_mapping_from_mapData() null src pointer\\n");')
- rc_body.append(' else')
- rc_body.append(' glv_LogWarn("rm_mapping_from_mapData() null dest pointer size=%u\\n", info.size);')
- rc_body.append(' info.pData = NULL;')
- rc_body.append(' return;')
- rc_body.append(' }')
- rc_body.append(' memcpy(info.pData, pData, info.size);')
- rc_body.append(' info.pData = NULL;')
- rc_body.append(' }\n')
rc_body.append(' bool m_adjustForGPU; // true if replay adjusts behavior based on GPU')
# Code for memory objects for handling replay GPU != trace GPU object memory requirements
rc_body.append(' struct imageObj {')
rc_body.append(' XGL_BUFFER replayBuffer;')
rc_body.append(' };\n')
rc_body.append(' struct gpuMemObj {')
- rc_body.append(' objMemory gpuMem;')
+ rc_body.append(' gpuMemory *pGpuMem;')
rc_body.append(' XGL_GPU_MEMORY replayGpuMem;')
rc_body.append(' };\n')
rc_body.append(' void init_objMemCount(const XGL_BASE_OBJECT& object, const uint32_t &num)\n {')
rof_body.append(' memcpy(m_pMemReqs, pReqs, num);')
rof_body.append(' }')
rof_body.append('}\n')
+ # Custom code for memory mapping functions for app writes into mapped memory
+ rof_body.append(' // memory mapping functions for app writes into mapped memory')
+ rof_body.append(' void gpuMemory::setAllocInfo(const XGL_MEMORY_ALLOC_INFO *info)')
+ rof_body.append(' {')
+ rof_body.append(' m_allocInfo = *info;')
+ rof_body.append(' }\n')
+ rof_body.append(' void gpuMemory::setMemoryDataAddr(void *pBuf)')
+ rof_body.append(' {')
+ rof_body.append(' if (m_pData != NULL)')
+ rof_body.append(' glv_LogWarn("gpuMemory::setMemoryDataAddr() data already mapped overwrite old mapping\\n");')
+ rof_body.append(' else if (pBuf == NULL)')
+ rof_body.append(' glv_LogWarn("gpuMemory::setMemoryDataAddr() adding NULL pointer\\n");')
+ rof_body.append(' m_pData = pBuf;')
+ rof_body.append(' }\n')
+ rof_body.append(' void gpuMemory::copyMappingData(const void* pSrcData)')
+ rof_body.append(' {')
+ rof_body.append(' if (!pSrcData || !m_pData)')
+ rof_body.append(' {')
+ rof_body.append(' if (!pSrcData)')
+ rof_body.append(' glv_LogWarn("gpuMemory::copyMappingData() null src pointer\\n");')
+ rof_body.append(' else')
+ rof_body.append(' glv_LogWarn("gpuMemory::copyMappingData() null dest pointer size=%u\\n", m_allocInfo.allocationSize);')
+ rof_body.append(' m_pData = NULL;')
+ rof_body.append(' return;')
+ rof_body.append(' }')
+ rof_body.append(' memcpy(m_pData, pSrcData, m_allocInfo.allocationSize);')
+ rof_body.append(' m_pData = NULL;')
+ rof_body.append(' }\n')
return "\n".join(rof_body)
def _generate_replay_structors(self):
am_body.append(' replayResult = m_xglFuncs.real_xglAllocMemory(remap(pPacket->device), pPacket->pAllocInfo, &local_mem.replayGpuMem);')
am_body.append(' if (replayResult == XGL_SUCCESS)')
am_body.append(' {')
+ am_body.append(' local_mem.pGpuMem = new (gpuMemory);')
+ am_body.append(' if (local_mem.pGpuMem)')
+ am_body.append(' local_mem.pGpuMem->setAllocInfo(pPacket->pAllocInfo);')
am_body.append(' add_to_map(pPacket->pMem, &local_mem);')
- am_body.append(' add_entry_to_mapData(local_mem.replayGpuMem, pPacket->pAllocInfo->allocationSize);')
am_body.append(' }')
return "\n".join(am_body)
def _gen_replay_free_memory(self):
fm_body = []
- fm_body.append(' XGL_GPU_MEMORY local_mem = remap(pPacket->mem);')
- fm_body.append(' replayResult = m_xglFuncs.real_xglFreeMemory(local_mem);')
+ fm_body.append(' struct gpuMemObj local_mem;')
+ fm_body.append(' local_mem = m_gpuMemorys.find(pPacket->mem)->second;')
+ fm_body.append(' replayResult = m_xglFuncs.real_xglFreeMemory(local_mem.replayGpuMem);')
fm_body.append(' if (replayResult == XGL_SUCCESS) ')
fm_body.append(' {')
- fm_body.append(' rm_entry_from_mapData(local_mem);')
+ fm_body.append(' delete local_mem.pGpuMem;')
fm_body.append(' rm_from_map(pPacket->mem);')
fm_body.append(' }')
return "\n".join(fm_body)
def _gen_replay_map_memory(self):
mm_body = []
- mm_body.append(' XGL_GPU_MEMORY local_mem = remap(pPacket->mem);')
+ mm_body.append(' struct gpuMemObj local_mem = m_gpuMemorys.find(pPacket->mem)->second;')
mm_body.append(' void* pData;')
- mm_body.append(' replayResult = m_xglFuncs.real_xglMapMemory(local_mem, pPacket->flags, &pData);')
+ mm_body.append(' replayResult = m_xglFuncs.real_xglMapMemory(local_mem.replayGpuMem, pPacket->flags, &pData);')
mm_body.append(' if (replayResult == XGL_SUCCESS)')
- mm_body.append(' add_mapping_to_mapData(local_mem, pData);')
+ mm_body.append(' {')
+ mm_body.append(' if (local_mem.pGpuMem)')
+ mm_body.append(' local_mem.pGpuMem->setMemoryDataAddr(pData);')
+ mm_body.append(' }')
return "\n".join(mm_body)
def _gen_replay_unmap_memory(self):
um_body = []
- um_body.append(' XGL_GPU_MEMORY local_mem = remap(pPacket->mem);')
- um_body.append(' rm_mapping_from_mapData(local_mem, pPacket->pData); // copies data from packet into memory buffer')
- um_body.append(' replayResult = m_xglFuncs.real_xglUnmapMemory(local_mem);')
+ um_body.append(' struct gpuMemObj local_mem = m_gpuMemorys.find(pPacket->mem)->second;')
+ um_body.append(' if (local_mem.pGpuMem)')
+ um_body.append(' local_mem.pGpuMem->copyMappingData(pPacket->pData); // copies data from packet into memory buffer')
+ um_body.append(' replayResult = m_xglFuncs.real_xglUnmapMemory(local_mem.replayGpuMem);')
return "\n".join(um_body)
def _gen_replay_pin_system_memory(self):