From 3f0d69789bbb8b2bde0447cc3b416257347b8e4d Mon Sep 17 00:00:00 2001 From: Peter Lohrmann Date: Wed, 1 Apr 2015 18:12:34 -0700 Subject: [PATCH] glave: Big cleanup of codegen related to glvreplay_xgl. * xglDisplay class was entirely manually-written, but inside the codegen script. This now lives in it's own .h and .cpp files. * xglReplay implementation is now split between a manually written .cpp file, and a codegen'ed one. * A bunch of the manually-coded entrypoints for xglReplay are now handled in the manually written .cpp file. --- tools/glave/scripts/vk_generate.py | 1114 ++------------------ .../glv_extensions/glvreplay_xgl/CMakeLists.txt | 9 +- .../glvreplay_xgl/codegen/glvreplay_xgl_replay.h | 76 +- ...xgl_replay.cpp => glvreplay_xgl_replay_gen.cpp} | 1007 +----------------- .../glvreplay_xgl/glvreplay_xgl_xgldisplay.cpp | 269 +++++ .../glvreplay_xgl/glvreplay_xgl_xgldisplay.h | 71 ++ .../glvreplay_xgl/glvreplay_xgl_xglreplay.cpp | 948 +++++++++++++++++ 7 files changed, 1416 insertions(+), 2078 deletions(-) rename tools/glave/src/glv_extensions/glvreplay_xgl/codegen/{glvreplay_xgl_replay.cpp => glvreplay_xgl_replay_gen.cpp} (59%) create mode 100644 tools/glave/src/glv_extensions/glvreplay_xgl/glvreplay_xgl_xgldisplay.cpp create mode 100644 tools/glave/src/glv_extensions/glvreplay_xgl/glvreplay_xgl_xgldisplay.h create mode 100644 tools/glave/src/glv_extensions/glvreplay_xgl/glvreplay_xgl_xglreplay.cpp diff --git a/tools/glave/scripts/vk_generate.py b/tools/glave/scripts/vk_generate.py index 364ef43..1d59dfd 100755 --- a/tools/glave/scripts/vk_generate.py +++ b/tools/glave/scripts/vk_generate.py @@ -1699,56 +1699,6 @@ class Subcommand(object): if_body.append('}\n') return "\n".join(if_body) - def _generate_replay_class_decls(self): - cd_body = [] - cd_body.append('class xglDisplay: public glv_replay::DisplayImp {') - cd_body.append('friend class xglReplay;') - cd_body.append('public:') - cd_body.append(' xglDisplay();') - cd_body.append(' ~xglDisplay();') - cd_body.append(' int init(const unsigned int gpu_idx);') - cd_body.append(' int set_window(glv_window_handle hWindow, unsigned int width, unsigned int height);') - cd_body.append(' int create_window(const unsigned int width, const unsigned int height);') - cd_body.append(' void resize_window(const unsigned int width, const unsigned int height);') - cd_body.append(' void process_event();') - cd_body.append(' // XGL_DEVICE get_device() { return m_dev[m_gpuIdx];}') - cd_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') - cd_body.append(' xcb_window_t get_window_handle() { return m_XcbWindow; }') - cd_body.append('#elif defined(WIN32)') - cd_body.append(' HWND get_window_handle() { return m_windowHandle; }') - cd_body.append('#endif') - cd_body.append('private:') - cd_body.append(' XGL_RESULT init_xgl(const unsigned int gpu_idx);') - cd_body.append(' bool m_initedXGL;') - cd_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') - cd_body.append(' XGL_WSI_X11_CONNECTION_INFO m_WsiConnection;') - cd_body.append(' xcb_screen_t *m_pXcbScreen;') - cd_body.append(' xcb_window_t m_XcbWindow;') - cd_body.append('#elif defined(WIN32)') - cd_body.append(' HWND m_windowHandle;') - cd_body.append('#endif') - cd_body.append(' unsigned int m_windowWidth;') - cd_body.append(' unsigned int m_windowHeight;') - cd_body.append(' unsigned int m_frameNumber;') - cd_body.append(' std::vector imageWidth;') - cd_body.append(' std::vector imageHeight;') - cd_body.append(' std::vector imageHandles;') - cd_body.append(' std::vector imageMemory;') - cd_body.append('#if 0') - cd_body.append(' XGL_DEVICE m_dev[XGL_MAX_PHYSICAL_GPUS];') - cd_body.append(' uint32_t m_gpuCount;') - cd_body.append(' unsigned int m_gpuIdx;') - cd_body.append(' XGL_PHYSICAL_GPU m_gpus[XGL_MAX_PHYSICAL_GPUS];') - cd_body.append(' XGL_PHYSICAL_GPU_PROPERTIES m_gpuProps[XGL_MAX_PHYSICAL_GPUS];') - cd_body.append('#endif') - cd_body.append(' std::vectorm_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;') - return "\n".join(cd_body) - def _generate_replay_func_ptrs(self): xf_body = [] xf_body.append('struct xglFuncs {') @@ -1798,6 +1748,11 @@ class Subcommand(object): mem_var = 'm_%s%ss' % (mem_var_list[0], "".join([m.title() for m in mem_var_list[1:]])) obj_map_dict[mem_var] = ty rc_body = [] + rc_body.append('typedef struct _XGLAllocInfo {') + rc_body.append(' XGL_GPU_SIZE size;') + rc_body.append(' void *pData;') + rc_body.append('} XGLAllocInfo;\n') + rc_body.append('#define CHECK_RETURN_VALUE(entrypoint) returnValue = handle_replay_errors(#entrypoint, replayResult, pPacket->result, returnValue);\n') rc_body.append('class xglReplay {') rc_body.append('public:') rc_body.append(' ~xglReplay();') @@ -1828,6 +1783,29 @@ class Subcommand(object): rc_body.append(' };') rc_body.append(' std::vector m_validationMsgs;') rc_body.append(' std::vector m_screenshotFrames;') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglCreateDevice(struct_xglCreateDevice* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglEnumerateGpus(struct_xglEnumerateGpus* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglGetGpuInfo(struct_xglGetGpuInfo* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglGetExtensionSupport(struct_xglGetExtensionSupport* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglQueueSubmit(struct_xglQueueSubmit* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglGetObjectInfo(struct_xglGetObjectInfo* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglGetFormatInfo(struct_xglGetFormatInfo* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglGetImageSubresourceInfo(struct_xglGetImageSubresourceInfo* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglUpdateDescriptors(struct_xglUpdateDescriptors* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglCreateDescriptorSetLayout(struct_xglCreateDescriptorSetLayout* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglCreateGraphicsPipeline(struct_xglCreateGraphicsPipeline* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglCmdWaitEvents(struct_xglCmdWaitEvents* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglCmdPipelineBarrier(struct_xglCmdPipelineBarrier* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglCreateFramebuffer(struct_xglCreateFramebuffer* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglCreateRenderPass(struct_xglCreateRenderPass* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglBeginCommandBuffer(struct_xglBeginCommandBuffer* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglStorePipeline(struct_xglStorePipeline* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglGetMultiGpuCompatibility(struct_xglGetMultiGpuCompatibility* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglDestroyObject(struct_xglDestroyObject* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglWaitForFences(struct_xglWaitForFences* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglFreeMemory(struct_xglFreeMemory* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglMapMemory(struct_xglMapMemory* pPacket);') + rc_body.append(' glv_replay::GLV_REPLAY_RESULT manually_handle_xglUnmapMemory(struct_xglUnmapMemory* pPacket);') rc_body.append(self._map_decl('XGL_GPU_MEMORY', 'XGLAllocInfo', 'm_mapData')) # Custom code for 1-off memory mapping functions rc_body.append(' void add_entry_to_mapData(XGL_GPU_MEMORY handle, XGL_GPU_SIZE size)') @@ -1948,358 +1926,6 @@ class Subcommand(object): rc_body.append('};') return "\n".join(rc_body) - def _generate_replay_display_init_xgl(self): - dix_body = [] - dix_body.append('XGL_RESULT xglDisplay::init_xgl(unsigned int gpu_idx)') - dix_body.append('{') - dix_body.append('#if 0') - dix_body.append(' XGL_APPLICATION_INFO appInfo = {};') - dix_body.append(' appInfo.pAppName = APP_NAME;') - dix_body.append(' appInfo.pEngineName = "";') - dix_body.append(' appInfo.apiVersion = XGL_API_VERSION;') - dix_body.append(' XGL_RESULT res = xglInitAndEnumerateGpus(&appInfo, NULL, XGL_MAX_PHYSICAL_GPUS, &m_gpuCount, m_gpus);') - dix_body.append(' if ( res == XGL_SUCCESS ) {') - dix_body.append(' // retrieve the GPU information for all GPUs') - dix_body.append(' for( uint32_t gpu = 0; gpu < m_gpuCount; gpu++)') - dix_body.append(' {') - dix_body.append(' size_t gpuInfoSize = sizeof(m_gpuProps[0]);\n') - dix_body.append(' // get the GPU physical properties:') - dix_body.append(' res = xglGetGpuInfo( m_gpus[gpu], XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES, &gpuInfoSize, &m_gpuProps[gpu]);') - dix_body.append(' if (res != XGL_SUCCESS)') - dix_body.append(' glv_LogWarn("Failed to retrieve properties for gpu[%d] result %d\\n", gpu, res);') - dix_body.append(' }') - dix_body.append(' res = XGL_SUCCESS;') - dix_body.append(' } else if ((gpu_idx + 1) > m_gpuCount) {') - dix_body.append(' glv_LogError("xglInitAndEnumerate number of gpus does not include requested index: num %d, requested %d\\n", m_gpuCount, gpu_idx);') - dix_body.append(' return -1;') - dix_body.append(' } else {') - dix_body.append(' glv_LogError("xglInitAndEnumerate failed\\n");') - dix_body.append(' return res;') - dix_body.append(' }') - dix_body.append(' // TODO add multi-gpu support always use gpu[gpu_idx] for now') - dix_body.append(' // get all extensions supported by this device gpu[gpu_idx]') - dix_body.append(' // first check if extensions are available and save a list of them') - dix_body.append(' bool foundWSIExt = false;') - dix_body.append(' for( int ext = 0; ext < sizeof( extensions ) / sizeof( extensions[0] ); ext++)') - dix_body.append(' {') - dix_body.append(' res = xglGetExtensionSupport( m_gpus[gpu_idx], extensions[ext] );') - dix_body.append(' if (res == XGL_SUCCESS) {') - dix_body.append(' m_extensions.push_back((char *) extensions[ext]);') - dix_body.append(' if (!strcmp(extensions[ext], "XGL_WSI_WINDOWS"))') - dix_body.append(' foundWSIExt = true;') - dix_body.append(' }') - dix_body.append(' }') - dix_body.append(' if (!foundWSIExt) {') - dix_body.append(' glv_LogError("XGL_WSI_WINDOWS extension not supported by gpu[%d]\\n", gpu_idx);') - dix_body.append(' return XGL_ERROR_INCOMPATIBLE_DEVICE;') - dix_body.append(' }') - dix_body.append(' // TODO generalize this: use one universal queue for now') - dix_body.append(' XGL_DEVICE_QUEUE_CREATE_INFO dqci = {};') - dix_body.append(' dqci.queueCount = 1;') - dix_body.append(' dqci.queueType = XGL_QUEUE_UNIVERSAL;') - dix_body.append(' // create the device enabling validation level 4') - dix_body.append(' const char * const * extNames = &m_extensions[0];') - dix_body.append(' XGL_DEVICE_CREATE_INFO info = {};') - dix_body.append(' info.queueRecordCount = 1;') - dix_body.append(' info.pRequestedQueues = &dqci;') - dix_body.append(' info.extensionCount = static_cast (m_extensions.size());') - dix_body.append(' info.ppEnabledExtensionNames = extNames;') - dix_body.append(' info.flags = XGL_DEVICE_CREATE_VALIDATION;') - dix_body.append(' info.maxValidationLevel = XGL_VALIDATION_LEVEL_4;') - dix_body.append(' bool32_t xglTrue = XGL_TRUE;') - dix_body.append(' res = xglDbgSetGlobalOption( XGL_DBG_OPTION_BREAK_ON_ERROR, sizeof( xglTrue ), &xglTrue );') - dix_body.append(' if (res != XGL_SUCCESS)') - dix_body.append(' glv_LogWarn("Could not set debug option break on error\\n");') - dix_body.append(' res = xglCreateDevice( m_gpus[0], &info, &m_dev[gpu_idx]);') - dix_body.append(' return res;') - dix_body.append('#else') - dix_body.append(' return XGL_ERROR_INITIALIZATION_FAILED;') - dix_body.append('#endif') - dix_body.append('}') - return "\n".join(dix_body) - - def _generate_replay_display_init(self): - di_body = [] - di_body.append('int xglDisplay::init(const unsigned int gpu_idx)') - di_body.append('{') - di_body.append(' //m_gpuIdx = gpu_idx;') - di_body.append('#if 0') - di_body.append(' XGL_RESULT result = init_xgl(gpu_idx);') - di_body.append(' if (result != XGL_SUCCESS) {') - di_body.append(' glv_LogError("could not init xgl library");') - di_body.append(' return -1;') - di_body.append(' } else {') - di_body.append(' m_initedXGL = true;') - di_body.append(' }') - di_body.append('#endif') - di_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') - di_body.append(' const xcb_setup_t *setup;') - di_body.append(' xcb_screen_iterator_t iter;') - di_body.append(' int scr;') - di_body.append(' xcb_connection_t *pConnection;') - di_body.append(' pConnection = xcb_connect(NULL, &scr);') - di_body.append(' setup = xcb_get_setup(pConnection);') - di_body.append(' iter = xcb_setup_roots_iterator(setup);') - di_body.append(' while (scr-- > 0)') - di_body.append(' xcb_screen_next(&iter);') - di_body.append(' m_pXcbScreen = iter.data;') - di_body.append(' m_WsiConnection.pConnection = pConnection;') - di_body.append(' m_WsiConnection.root = m_pXcbScreen->root;') - di_body.append('#endif') - di_body.append(' return 0;') - di_body.append('}') - return "\n".join(di_body) - - def _generate_replay_display_structors(self): - ds_body = [] - ds_body.append('xglDisplay::xglDisplay()') - ds_body.append(' : m_initedXGL(false),') - ds_body.append(' m_windowWidth(0),') - ds_body.append(' m_windowHeight(0)') - ds_body.append('{') - ds_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') - ds_body.append(' m_WsiConnection.pConnection = NULL;') - ds_body.append(' m_WsiConnection.root = 0;') - ds_body.append(' m_WsiConnection.provider = 0;') - ds_body.append(' m_pXcbScreen = NULL;') - ds_body.append(' m_XcbWindow = 0;') - ds_body.append('#elif defined(WIN32)') - ds_body.append(' m_windowHandle = NULL;') - ds_body.append('#endif') - ds_body.append('}') - ds_body.append('xglDisplay::~xglDisplay()') - ds_body.append('{') - ds_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') - ds_body.append(' if (m_XcbWindow != 0)') - ds_body.append(' {') - ds_body.append(' xcb_destroy_window(m_WsiConnection.pConnection, m_XcbWindow);') - ds_body.append(' }') - ds_body.append(' if (m_WsiConnection.pConnection != NULL)') - ds_body.append(' {') - ds_body.append(' xcb_disconnect(m_WsiConnection.pConnection);') - ds_body.append(' }') - ds_body.append('#endif') - ds_body.append('}') - return "\n".join(ds_body) - - def _generate_replay_display_window(self): - dw_body = [] - dw_body.append('#if defined(WIN32)') - dw_body.append('LRESULT WINAPI WindowProcXgl( HWND window, unsigned int msg, WPARAM wp, LPARAM lp)') - dw_body.append('{') - dw_body.append(' switch(msg)') - dw_body.append(' {') - dw_body.append(' case WM_CLOSE:') - dw_body.append(' DestroyWindow( window);') - dw_body.append(' // fall-thru') - dw_body.append(' case WM_DESTROY:') - dw_body.append(' PostQuitMessage(0) ;') - dw_body.append(' return 0L ;') - dw_body.append(' default:') - dw_body.append(' return DefWindowProc( window, msg, wp, lp ) ;') - dw_body.append(' }') - dw_body.append('}') - dw_body.append('#endif') - dw_body.append('int xglDisplay::set_window(glv_window_handle hWindow, unsigned int width, unsigned int height)') - dw_body.append('{') - dw_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') - dw_body.append(' m_XcbWindow = hWindow;') - dw_body.append('#elif defined(WIN32)') - dw_body.append(' m_windowHandle = hWindow;') - dw_body.append('#endif') - dw_body.append(' m_windowWidth = width;') - dw_body.append(' m_windowHeight = height;') - dw_body.append(' return 0;') - dw_body.append('}\n') - dw_body.append('int xglDisplay::create_window(const unsigned int width, const unsigned int height)') - dw_body.append('{') - dw_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)\n') - dw_body.append(' uint32_t value_mask, value_list[32];') - dw_body.append(' m_XcbWindow = xcb_generate_id(m_WsiConnection.pConnection);\n') - dw_body.append(' value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;') - dw_body.append(' value_list[0] = m_pXcbScreen->black_pixel;') - dw_body.append(' value_list[1] = XCB_EVENT_MASK_KEY_RELEASE |') - dw_body.append(' XCB_EVENT_MASK_EXPOSURE;\n') - dw_body.append(' xcb_create_window(m_WsiConnection.pConnection,') - dw_body.append(' XCB_COPY_FROM_PARENT,') - dw_body.append(' m_XcbWindow, m_WsiConnection.root,') - dw_body.append(' 0, 0, width, height, 0,') - dw_body.append(' XCB_WINDOW_CLASS_INPUT_OUTPUT,') - dw_body.append(' m_pXcbScreen->root_visual,') - dw_body.append(' value_mask, value_list);\n') - dw_body.append(' xcb_map_window(m_WsiConnection.pConnection, m_XcbWindow);') - dw_body.append(' xcb_flush(m_WsiConnection.pConnection);') - dw_body.append(' return 0;') - dw_body.append('#elif defined(WIN32)') - dw_body.append(' // Register Window class') - dw_body.append(' WNDCLASSEX wcex = {};') - dw_body.append(' wcex.cbSize = sizeof( WNDCLASSEX);') - dw_body.append(' wcex.style = CS_HREDRAW | CS_VREDRAW;') - dw_body.append(' wcex.lpfnWndProc = WindowProcXgl;') - dw_body.append(' wcex.cbClsExtra = 0;') - dw_body.append(' wcex.cbWndExtra = 0;') - dw_body.append(' wcex.hInstance = GetModuleHandle(0);') - dw_body.append(' wcex.hIcon = LoadIcon(wcex.hInstance, MAKEINTRESOURCE( IDI_ICON));') - dw_body.append(' wcex.hCursor = LoadCursor( NULL, IDC_ARROW);') - dw_body.append(' wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1);') - dw_body.append(' wcex.lpszMenuName = NULL;') - dw_body.append(' wcex.lpszClassName = APP_NAME;') - dw_body.append(' wcex.hIconSm = LoadIcon( wcex.hInstance, MAKEINTRESOURCE( IDI_ICON));') - dw_body.append(' if( !RegisterClassEx( &wcex))') - dw_body.append(' {') - dw_body.append(' glv_LogError("Failed to register windows class\\n");') - dw_body.append(' return -1;') - dw_body.append(' }\n') - dw_body.append(' // create the window') - dw_body.append(' m_windowHandle = CreateWindow(APP_NAME, APP_NAME, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, 0, 0,') - dw_body.append(' width, height, NULL, NULL, wcex.hInstance, NULL);\n') - dw_body.append(' if (m_windowHandle)') - dw_body.append(' {') - dw_body.append(' ShowWindow( m_windowHandle, SW_SHOWDEFAULT);') - dw_body.append(' m_windowWidth = width;') - dw_body.append(' m_windowHeight = height;') - dw_body.append(' } else {') - dw_body.append(' glv_LogError("Failed to create window\\n");') - dw_body.append(' return -1;') - dw_body.append(' }') - dw_body.append(' return 0;') - dw_body.append('#endif') - dw_body.append('}\n') - dw_body.append('void xglDisplay::resize_window(const unsigned int width, const unsigned int height)') - dw_body.append('{') - dw_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') - dw_body.append(' if (width != m_windowWidth || height != m_windowHeight)') - dw_body.append(' {') - dw_body.append(' uint32_t values[2];') - dw_body.append(' values[0] = width;') - dw_body.append(' values[1] = height;') - dw_body.append(' xcb_configure_window(m_WsiConnection.pConnection, m_XcbWindow, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values);') - dw_body.append(' m_windowWidth = width;') - dw_body.append(' m_windowHeight = height;') - dw_body.append(' }') - dw_body.append('#elif defined(WIN32)') - dw_body.append(' if (width != m_windowWidth || height != m_windowHeight)') - dw_body.append(' {') - dw_body.append(' SetWindowPos(get_window_handle(), HWND_TOP, 0, 0, width, height, SWP_NOMOVE);') - dw_body.append(' m_windowWidth = width;') - dw_body.append(' m_windowHeight = height;') - dw_body.append(' }') - dw_body.append('#endif') - dw_body.append('}\n') - dw_body.append('void xglDisplay::process_event()') - dw_body.append('{') - dw_body.append('}') - return "\n".join(dw_body) - - def _generate_replay_structors(self): - rs_body = [] - rs_body.append('xglReplay::xglReplay(glvreplay_settings *pReplaySettings)') - rs_body.append('{') - rs_body.append(' g_pReplaySettings = pReplaySettings;') - rs_body.append(' m_display = new xglDisplay();') - rs_body.append(' m_pDSDump = NULL;') - rs_body.append(' m_pCBDump = NULL;') - rs_body.append(' m_pGlvSnapshotPrint = NULL;') - rs_body.append(' if (g_pReplaySettings && g_pReplaySettings->screenshotList) {') - rs_body.append(' process_screenshot_list(g_pReplaySettings->screenshotList);') - rs_body.append(' }') - rs_body.append('}\n') - rs_body.append('xglReplay::~xglReplay()') - rs_body.append('{') - rs_body.append(' delete m_display;') - rs_body.append(' glv_platform_close_library(m_xglFuncs.m_libHandle);') - rs_body.append('}') - return "\n".join(rs_body) - - def _generate_replay_init(self): - ri_body = [] - ri_body.append('int xglReplay::init(glv_replay::Display & disp)') - ri_body.append('{') - ri_body.append(' int err;') - ri_body.append('#if defined PLATFORM_LINUX') - ri_body.append(' void * handle = dlopen("libXGL.so", RTLD_LAZY);') - ri_body.append('#else') - ri_body.append(' HMODULE handle = LoadLibrary("xgl.dll" );') - ri_body.append('#endif\n') - ri_body.append(' if (handle == NULL) {') - ri_body.append(' glv_LogError("Failed to open xgl library.\\n");') - ri_body.append(' return -1;') - ri_body.append(' }') - ri_body.append(' m_xglFuncs.init_funcs(handle);') - ri_body.append(' disp.set_implementation(m_display);') - ri_body.append(' if ((err = m_display->init(disp.get_gpu())) != 0) {') - ri_body.append(' glv_LogError("Failed to init XGL display.\\n");') - ri_body.append(' return err;') - ri_body.append(' }') - ri_body.append(' if (disp.get_window_handle() == 0)') - ri_body.append(' {') - ri_body.append(' if ((err = m_display->create_window(disp.get_width(), disp.get_height())) != 0) {') - ri_body.append(' glv_LogError("Failed to create Window\\n");') - ri_body.append(' return err;') - ri_body.append(' }') - ri_body.append(' }') - ri_body.append(' else') - ri_body.append(' {') - ri_body.append(' if ((err = m_display->set_window(disp.get_window_handle(), disp.get_width(), disp.get_height())) != 0)') - ri_body.append(' {') - ri_body.append(' glv_LogError("Failed to set Window\\n");') - ri_body.append(' return err;') - ri_body.append(' }') - ri_body.append(' }') - ri_body.append(' return 0;') - ri_body.append('}') - return "\n".join(ri_body) - - def _generate_replay_errors(self): - re_body = [] - re_body.append('glv_replay::GLV_REPLAY_RESULT xglReplay::handle_replay_errors(const char* entrypointName, const XGL_RESULT resCall, const XGL_RESULT resTrace, const glv_replay::GLV_REPLAY_RESULT resIn)') - re_body.append('{') - re_body.append(' glv_replay::GLV_REPLAY_RESULT res = resIn;') - re_body.append(' if (resCall != resTrace) {') - re_body.append(' glv_LogWarn("Mismatched return from API call (%s) traced result %s, replay result %s\\n", entrypointName,') - re_body.append(' string_XGL_RESULT((XGL_RESULT)resTrace), string_XGL_RESULT((XGL_RESULT)resCall));') - re_body.append(' res = glv_replay::GLV_REPLAY_BAD_RETURN;') - re_body.append(' }') - re_body.append('#if 0') - re_body.append(' if (resCall != XGL_SUCCESS) {') - re_body.append(' glv_LogWarn("API call (%s) returned failed result %s\\n", entrypointName, string_XGL_RESULT(resCall));') - re_body.append(' }') - re_body.append('#endif') - re_body.append(' return res;') - re_body.append('}') - return "\n".join(re_body) - - def _generate_replay_validation_funcs(self): - rvf_body = [] - rvf_body.append('void xglReplay::push_validation_msg(XGL_VALIDATION_LEVEL validationLevel, XGL_BASE_OBJECT srcObject, size_t location, int32_t msgCode, const char * pMsg)') - rvf_body.append('{') - rvf_body.append(' struct validationMsg msgObj;') - rvf_body.append(' msgObj.validationLevel = validationLevel;') - rvf_body.append(' msgObj.srcObject = srcObject;') - rvf_body.append(' msgObj.location = location;') - rvf_body.append(' msgObj.msgCode = msgCode;') - rvf_body.append(' strncpy(msgObj.msg, pMsg, 256);') - rvf_body.append(" msgObj.msg[255] = '\\0';") - rvf_body.append(' m_validationMsgs.push_back(msgObj);') - rvf_body.append('}\n') - rvf_body.append('glv_replay::GLV_REPLAY_RESULT xglReplay::pop_validation_msgs()') - rvf_body.append('{') - rvf_body.append(' if (m_validationMsgs.size() == 0)') - rvf_body.append(' return glv_replay::GLV_REPLAY_SUCCESS;') - rvf_body.append(' m_validationMsgs.clear();') - rvf_body.append(' return glv_replay::GLV_REPLAY_VALIDATION_ERROR;') - rvf_body.append('}') - rvf_body.append('int xglReplay::dump_validation_data()') - rvf_body.append('{') - rvf_body.append(' if (m_pDSDump && m_pCBDump)') - rvf_body.append(' {') - rvf_body.append(' m_pDSDump((char *) "pipeline_dump.dot");') - rvf_body.append(' m_pCBDump((char *) "cb_dump.dot");') - rvf_body.append(' }') - rvf_body.append(' if (m_pGlvSnapshotPrint != NULL) { m_pGlvSnapshotPrint(); }') - rvf_body.append(' return 0;') - rvf_body.append('}') - return "\n".join(rvf_body) def _generate_replay_init_funcs(self): rif_body = [] @@ -2324,689 +1950,102 @@ class Subcommand(object): def _gen_replay_enum_gpus(self): ieg_body = [] - ieg_body.append(' if (!m_display->m_initedXGL)') - ieg_body.append(' {') - ieg_body.append(' uint32_t gpuCount;') - ieg_body.append(' XGL_PHYSICAL_GPU gpus[XGL_MAX_PHYSICAL_GPUS];') - ieg_body.append(' uint32_t maxGpus = (pPacket->maxGpus < XGL_MAX_PHYSICAL_GPUS) ? pPacket->maxGpus : XGL_MAX_PHYSICAL_GPUS;') - ieg_body.append(' replayResult = m_xglFuncs.real_xglEnumerateGpus(remap(pPacket->instance), maxGpus, &gpuCount, &gpus[0]);') - ieg_body.append(' CHECK_RETURN_VALUE(xglEnumerateGpus);') - ieg_body.append(' //TODO handle different number of gpus in trace versus replay') - ieg_body.append(' if (gpuCount != *(pPacket->pGpuCount))') - ieg_body.append(' {') - ieg_body.append(' glv_LogWarn("number of gpus mismatched in replay %u versus trace %u\\n", gpuCount, *(pPacket->pGpuCount));') - ieg_body.append(' }') - ieg_body.append(' else if (gpuCount == 0)') - ieg_body.append(' {') - ieg_body.append(' glv_LogError("xglEnumerateGpus number of gpus is zero\\n");') - ieg_body.append(' }') - ieg_body.append(' else') - ieg_body.append(' {') - ieg_body.append(' glv_LogInfo("Enumerated %d GPUs in the system\\n", gpuCount);') - ieg_body.append(' }') - ieg_body.append(' // TODO handle enumeration results in a different order from trace to replay') - ieg_body.append(' for (uint32_t i = 0; i < gpuCount; i++)') - ieg_body.append(' {') - ieg_body.append(' if (pPacket->pGpus)') - ieg_body.append(' add_to_map(&(pPacket->pGpus[i]), &(gpus[i]));') - ieg_body.append(' }') - ieg_body.append(' }') + ieg_body.append(' returnValue = manually_handle_xglEnumerateGpus(pPacket);') return "\n".join(ieg_body) def _gen_replay_get_gpu_info(self): ggi_body = [] - ggi_body.append(' if (!m_display->m_initedXGL)') - ggi_body.append(' {') - ggi_body.append(' switch (pPacket->infoType) {') - ggi_body.append(' case XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES:') - ggi_body.append(' {') - ggi_body.append(' XGL_PHYSICAL_GPU_PROPERTIES gpuProps;') - ggi_body.append(' size_t dataSize = sizeof(XGL_PHYSICAL_GPU_PROPERTIES);') - ggi_body.append(' replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &dataSize,') - ggi_body.append(' (pPacket->pData == NULL) ? NULL : &gpuProps);') - ggi_body.append(' if (pPacket->pData != NULL)') - ggi_body.append(' {') - ggi_body.append(' glv_LogInfo("Replay Gpu Properties\\n");') - ggi_body.append(' glv_LogInfo("Vendor ID %x, Device ID %x, name %s\\n",gpuProps.vendorId, gpuProps.deviceId, gpuProps.gpuName);') - ggi_body.append(' glv_LogInfo("API version %u, Driver version %u, gpu Type %u\\n",gpuProps.apiVersion, gpuProps.driverVersion, gpuProps.gpuType);') - ggi_body.append(' }') - ggi_body.append(' break;') - ggi_body.append(' }') - ggi_body.append(' case XGL_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE:') - ggi_body.append(' {') - ggi_body.append(' XGL_PHYSICAL_GPU_PERFORMANCE gpuPerfs;') - ggi_body.append(' size_t dataSize = sizeof(XGL_PHYSICAL_GPU_PERFORMANCE);') - ggi_body.append(' replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &dataSize,') - ggi_body.append(' (pPacket->pData == NULL) ? NULL : &gpuPerfs);') - ggi_body.append(' if (pPacket->pData != NULL)') - ggi_body.append(' {') - ggi_body.append(' glv_LogInfo("Replay Gpu Performance\\n");') - ggi_body.append(' glv_LogInfo("Max GPU clock %f, max shader ALUs/clock %f, max texel fetches/clock %f\\n",gpuPerfs.maxGpuClock, gpuPerfs.aluPerClock, gpuPerfs.texPerClock);') - ggi_body.append(' glv_LogInfo("Max primitives/clock %f, Max pixels/clock %f\\n",gpuPerfs.primsPerClock, gpuPerfs.pixelsPerClock);') - ggi_body.append(' }') - ggi_body.append(' break;') - ggi_body.append(' }') - ggi_body.append(' case XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES:') - ggi_body.append(' {') - ggi_body.append(' XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *pGpuQueue, *pQ;') - ggi_body.append(' size_t dataSize = sizeof(XGL_PHYSICAL_GPU_QUEUE_PROPERTIES);') - ggi_body.append(' size_t numQueues = 1;') - ggi_body.append(' assert(pPacket->pDataSize);') - ggi_body.append(' if ((*(pPacket->pDataSize) % dataSize) != 0)') - ggi_body.append(' glv_LogWarn("xglGetGpuInfo() for GPU_QUEUE_PROPERTIES not an integral data size assuming 1\\n");') - ggi_body.append(' else') - ggi_body.append(' numQueues = *(pPacket->pDataSize) / dataSize;') - ggi_body.append(' dataSize = numQueues * dataSize;') - ggi_body.append(' pQ = static_cast < XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *> (glv_malloc(dataSize));') - ggi_body.append(' pGpuQueue = pQ;') - ggi_body.append(' replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &dataSize,') - ggi_body.append(' (pPacket->pData == NULL) ? NULL : pGpuQueue);') - ggi_body.append(' if (pPacket->pData != NULL)') - ggi_body.append(' {') - ggi_body.append(' for (unsigned int i = 0; i < numQueues; i++)') - ggi_body.append(' {') - ggi_body.append(' glv_LogInfo("Replay Gpu Queue Property for index %d, flags %u\\n", i, pGpuQueue->queueFlags);') - ggi_body.append(' glv_LogInfo("Max available count %u, max atomic counters %u, supports timestamps %u\\n",pGpuQueue->queueCount, pGpuQueue->maxAtomicCounters, pGpuQueue->supportsTimestamps);') - ggi_body.append(' pGpuQueue++;') - ggi_body.append(' }') - ggi_body.append(' }') - ggi_body.append(' glv_free(pQ);') - ggi_body.append(' break;') - ggi_body.append(' }') - ggi_body.append(' default:') - ggi_body.append(' {') - ggi_body.append(' size_t size = 0;') - ggi_body.append(' void* pData = NULL;') - ggi_body.append(' if (pPacket->pData != NULL && pPacket->pDataSize != NULL)') - ggi_body.append(' {') - ggi_body.append(' size = *pPacket->pDataSize;') - ggi_body.append(' pData = glv_malloc(*pPacket->pDataSize);') - ggi_body.append(' }') - ggi_body.append(' replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &size, pData);') - ggi_body.append(' if (replayResult == XGL_SUCCESS)') - ggi_body.append(' {') - ggi_body.append(' if (size != *pPacket->pDataSize && pData != NULL)') - ggi_body.append(' {') - ggi_body.append(' glv_LogWarn("xglGetGpuInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\\n", size, *pPacket->pDataSize);') - ggi_body.append(' }') - ggi_body.append(' else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0)') - ggi_body.append(' {') - ggi_body.append(' glv_LogWarn("xglGetGpuInfo returned differing data contents than the trace file contained.\\n");') - ggi_body.append(' }') - ggi_body.append(' }') - ggi_body.append(' glv_free(pData);') - ggi_body.append(' break;') - ggi_body.append(' }') - ggi_body.append(' };') - ggi_body.append(' CHECK_RETURN_VALUE(xglGetGpuInfo);') - ggi_body.append(' }') + ggi_body.append(' returnValue = manually_handle_xglGetGpuInfo(pPacket);') return "\n".join(ggi_body) def _gen_replay_create_device(self): cd_body = [] - cd_body.append(' if (!m_display->m_initedXGL)') - cd_body.append(' {') - cd_body.append(' XGL_DEVICE device;') - cd_body.append(' if (g_xglReplaySettings.debugLevel > 0)') - cd_body.append(' {') - cd_body.append(' XGL_DEVICE_CREATE_INFO cInfo, *ci, *pCreateInfoSaved;') - cd_body.append(' unsigned int numLayers = 0;') - cd_body.append(' char ** layersStr = get_enableLayers_list(&numLayers);') - cd_body.append(' apply_layerSettings_overrides();') - cd_body.append(' XGL_LAYER_CREATE_INFO layerInfo;') - cd_body.append(' pCreateInfoSaved = (XGL_DEVICE_CREATE_INFO *) pPacket->pCreateInfo;') - cd_body.append(' ci = (XGL_DEVICE_CREATE_INFO *) pPacket->pCreateInfo;') - - cd_body.append(' if (layersStr != NULL && numLayers > 0)') - cd_body.append(' {') - cd_body.append(' while (ci->pNext != NULL)') - cd_body.append(' ci = (XGL_DEVICE_CREATE_INFO *) ci->pNext;') - cd_body.append(' ci->pNext = &layerInfo;') - cd_body.append(' layerInfo.sType = XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO;') - cd_body.append(' layerInfo.pNext = 0;') - cd_body.append(' layerInfo.layerCount = numLayers;') - cd_body.append(' layerInfo.ppActiveLayerNames = layersStr;') - cd_body.append(' }') - - cd_body.append(' memcpy(&cInfo, pPacket->pCreateInfo, sizeof(XGL_DEVICE_CREATE_INFO));') - cd_body.append(' cInfo.flags = pPacket->pCreateInfo->flags | XGL_DEVICE_CREATE_VALIDATION_BIT;') - cd_body.append(' cInfo.maxValidationLevel = (XGL_VALIDATION_LEVEL)((g_xglReplaySettings.debugLevel <= 4) ? (unsigned int) XGL_VALIDATION_LEVEL_0 + g_xglReplaySettings.debugLevel : (unsigned int) XGL_VALIDATION_LEVEL_0);') - cd_body.append(' pPacket->pCreateInfo = &cInfo;') - cd_body.append(' replayResult = m_xglFuncs.real_xglCreateDevice(remap(pPacket->gpu), pPacket->pCreateInfo, &device);') - cd_body.append(' // restore the packet for next replay') - cd_body.append(' ci->pNext = NULL;') - cd_body.append(' pPacket->pCreateInfo = pCreateInfoSaved;') - cd_body.append(' release_enableLayer_list(layersStr);') - cd_body.append(' if (xglDbgRegisterMsgCallback(g_fpDbgMsgCallback, NULL) != XGL_SUCCESS)') - cd_body.append(' glv_LogError("Failed to register xgl callback for replayer error handling\\n");') - cd_body.append('#if !defined(_WIN32)') - cd_body.append(' m_pDSDump = (DRAW_STATE_DUMP_DOT_FILE) m_xglFuncs.real_xglGetProcAddr(remap(pPacket->gpu), "drawStateDumpDotFile");') - cd_body.append(' m_pCBDump = (DRAW_STATE_DUMP_COMMAND_BUFFER_DOT_FILE) m_xglFuncs.real_xglGetProcAddr(remap(pPacket->gpu), "drawStateDumpCommandBufferDotFile");') - cd_body.append(' m_pGlvSnapshotPrint = (GLVSNAPSHOT_PRINT_OBJECTS) m_xglFuncs.real_xglGetProcAddr(remap(pPacket->gpu), "glvSnapshotPrintObjects");') - cd_body.append('#endif') - cd_body.append(' }') - cd_body.append(' else ') - cd_body.append(' replayResult = m_xglFuncs.real_xglCreateDevice(remap(pPacket->gpu), pPacket->pCreateInfo, &device);') - cd_body.append(' CHECK_RETURN_VALUE(xglCreateDevice);') - cd_body.append(' if (replayResult == XGL_SUCCESS)') - cd_body.append(' {') - cd_body.append(' add_to_map(pPacket->pDevice, &device);') - cd_body.append(' }') - cd_body.append(' }') + cd_body.append(' returnValue = manually_handle_xglCreateDevice(pPacket);') return "\n".join(cd_body) def _gen_replay_get_extension_support(self): ges_body = [] - ges_body.append(' if (!m_display->m_initedXGL) {') - ges_body.append(' replayResult = m_xglFuncs.real_xglGetExtensionSupport(remap(pPacket->gpu), pPacket->pExtName);') - ges_body.append(' CHECK_RETURN_VALUE(xglGetExtensionSupport);') - ges_body.append(' if (replayResult == XGL_SUCCESS) {') - ges_body.append(' for (unsigned int ext = 0; ext < sizeof(g_extensions) / sizeof(g_extensions[0]); ext++)') - ges_body.append(' {') - ges_body.append(' if (!strncmp(g_extensions[ext], pPacket->pExtName, strlen(g_extensions[ext]))) {') - ges_body.append(' bool extInList = false;') - ges_body.append(' for (unsigned int j = 0; j < m_display->m_extensions.size(); ++j) {') - ges_body.append(' if (!strncmp(m_display->m_extensions[j], g_extensions[ext], strlen(g_extensions[ext])))') - ges_body.append(' extInList = true;') - ges_body.append(' break;') - ges_body.append(' }') - ges_body.append(' if (!extInList)') - ges_body.append(' m_display->m_extensions.push_back((char *) g_extensions[ext]);') - ges_body.append(' break;') - ges_body.append(' }') - ges_body.append(' }') - ges_body.append(' }') - ges_body.append(' }') + ges_body.append(' returnValue = manually_handle_xglGetExtensionSupport(pPacket);') return "\n".join(ges_body) def _gen_replay_queue_submit(self): qs_body = [] - qs_body.append(' XGL_CMD_BUFFER *remappedBuffers = NULL;') - qs_body.append(' if (pPacket->pCmdBuffers != NULL)') - qs_body.append(' {') - qs_body.append(' remappedBuffers = GLV_NEW_ARRAY( XGL_CMD_BUFFER, pPacket->cmdBufferCount);') - qs_body.append(' for (uint32_t i = 0; i < pPacket->cmdBufferCount; i++)') - qs_body.append(' {') - qs_body.append(' *(remappedBuffers + i) = remap(*(pPacket->pCmdBuffers + i));') - qs_body.append(' }') - qs_body.append(' }') - qs_body.append(' XGL_MEMORY_REF* memRefs = NULL;') - qs_body.append(' if (pPacket->pMemRefs != NULL)') - qs_body.append(' {') - qs_body.append(' memRefs = GLV_NEW_ARRAY(XGL_MEMORY_REF, pPacket->memRefCount);') - qs_body.append(' memcpy(memRefs, pPacket->pMemRefs, sizeof(XGL_MEMORY_REF) * pPacket->memRefCount);') - qs_body.append(' for (uint32_t i = 0; i < pPacket->memRefCount; i++)') - qs_body.append(' {') - qs_body.append(' memRefs[i].mem = remap(pPacket->pMemRefs[i].mem);') - qs_body.append(' }') - qs_body.append(' }') - qs_body.append(' replayResult = m_xglFuncs.real_xglQueueSubmit(remap(pPacket->queue), pPacket->cmdBufferCount, remappedBuffers, pPacket->memRefCount,') - qs_body.append(' memRefs, remap(pPacket->fence));') - qs_body.append(' GLV_DELETE(remappedBuffers);') - qs_body.append(' GLV_DELETE(memRefs);') + qs_body.append(' returnValue = manually_handle_xglQueueSubmit(pPacket);') return "\n".join(qs_body) def _gen_replay_get_object_info(self): goi_body = [] - goi_body.append(' size_t size = 0;') - goi_body.append(' void* pData = NULL;') - goi_body.append(' if (pPacket->pData != NULL && pPacket->pDataSize != NULL)') - goi_body.append(' {') - goi_body.append(' size = *pPacket->pDataSize;') - goi_body.append(' pData = glv_malloc(*pPacket->pDataSize);') - goi_body.append(' memcpy(pData, pPacket->pData, *pPacket->pDataSize);') - goi_body.append(' }') - goi_body.append(' replayResult = m_xglFuncs.real_xglGetObjectInfo(remap(pPacket->object), pPacket->infoType, &size, pData);') - goi_body.append(' if (replayResult == XGL_SUCCESS)') - goi_body.append(' {') - goi_body.append(' if (size != *pPacket->pDataSize && pData != NULL)') - goi_body.append(' {') - goi_body.append(' glv_LogWarn("xglGetObjectInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\\n", size, *pPacket->pDataSize);') - goi_body.append(' }') - goi_body.append(' else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0)') - goi_body.append(' {') - goi_body.append(' glv_LogWarn("xglGetObjectInfo returned differing data contents than the trace file contained.\\n");') - goi_body.append(' }') - goi_body.append(' }') - goi_body.append(' glv_free(pData);') + goi_body.append(' returnValue = manually_handle_xglGetObjectInfo(pPacket);') return "\n".join(goi_body) def _gen_replay_get_format_info(self): gfi_body = [] - gfi_body.append(' size_t size = 0;') - gfi_body.append(' void* pData = NULL;') - gfi_body.append(' if (pPacket->pData != NULL && pPacket->pDataSize != NULL)') - gfi_body.append(' {') - gfi_body.append(' size = *pPacket->pDataSize;') - gfi_body.append(' pData = glv_malloc(*pPacket->pDataSize);') - gfi_body.append(' }') - gfi_body.append(' replayResult = m_xglFuncs.real_xglGetFormatInfo(remap(pPacket->device), pPacket->format, pPacket->infoType, &size, pData);') - gfi_body.append(' if (replayResult == XGL_SUCCESS)') - gfi_body.append(' {') - gfi_body.append(' if (size != *pPacket->pDataSize && pData != NULL)') - gfi_body.append(' {') - gfi_body.append(' glv_LogWarn("xglGetFormatInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\\n", size, *pPacket->pDataSize);') - gfi_body.append(' }') - gfi_body.append(' else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0)') - gfi_body.append(' {') - gfi_body.append(' glv_LogWarn("xglGetFormatInfo returned differing data contents than the trace file contained.\\n");') - gfi_body.append(' }') - gfi_body.append(' }') - gfi_body.append(' glv_free(pData);') + gfi_body.append(' returnValue = manually_handle_xglGetFormatInfo(pPacket);') return "\n".join(gfi_body) def _gen_replay_get_image_subresource_info(self): isi_body = [] - isi_body.append(' size_t size = 0;') - isi_body.append(' void* pData = NULL;') - isi_body.append(' if (pPacket->pData != NULL && pPacket->pDataSize != NULL)') - isi_body.append(' {') - isi_body.append(' size = *pPacket->pDataSize;') - isi_body.append(' pData = glv_malloc(*pPacket->pDataSize);') - isi_body.append(' }') - isi_body.append(' replayResult = m_xglFuncs.real_xglGetImageSubresourceInfo(remap(pPacket->image), pPacket->pSubresource, pPacket->infoType, &size, pData);') - isi_body.append(' if (replayResult == XGL_SUCCESS)') - isi_body.append(' {') - isi_body.append(' if (size != *pPacket->pDataSize && pData != NULL)') - isi_body.append(' {') - isi_body.append(' glv_LogWarn("xglGetImageSubresourceInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\\n", size, *pPacket->pDataSize);') - isi_body.append(' }') - isi_body.append(' else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0)') - isi_body.append(' {') - isi_body.append(' glv_LogWarn("xglGetImageSubresourceInfo returned differing data contents than the trace file contained.\\n");') - isi_body.append(' }') - isi_body.append(' }') - isi_body.append(' glv_free(pData);') + isi_body.append(' returnValue = manually_handle_xglGetImageSubresourceInfo(pPacket);') return "\n".join(isi_body) def _gen_replay_update_descriptors(self): ud_body = [] - # 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(' 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(' 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(' {') - 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(' 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(' 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(' {') - 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(' 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(' assert(0);') - ud_body.append(' break;') - ud_body.append(' }') - ud_body.append(' pUpdateChain = (XGL_UPDATE_SAMPLERS*) pUpdateChain->pNext;') - ud_body.append(' }') - 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(' 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(' {') - 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(' assert(0);') - ud_body.append(' break;') - ud_body.append(' }') - ud_body.append(' pUpdateChain = (XGL_UPDATE_SAMPLERS*) pUpdateChain->pNext;') - ud_body.append(' }') + ud_body.append(' returnValue = manually_handle_xglUpdateDescriptors(pPacket);') return "\n".join(ud_body) def _gen_replay_create_descriptor_set_layout(self): cdsl_body = [] - cdsl_body.append(' XGL_SAMPLER saveSampler;') - cdsl_body.append(' if (pPacket->pSetLayoutInfoList != NULL) {') - cdsl_body.append(' XGL_SAMPLER *pSampler = (XGL_SAMPLER *) &pPacket->pSetLayoutInfoList->immutableSampler;') - cdsl_body.append(' saveSampler = pPacket->pSetLayoutInfoList->immutableSampler;') - cdsl_body.append(' *pSampler = remap(saveSampler);') - cdsl_body.append(' }') - cdsl_body.append(' XGL_DESCRIPTOR_SET_LAYOUT setLayout;') - cdsl_body.append(' replayResult = m_xglFuncs.real_xglCreateDescriptorSetLayout(remap(pPacket->device), pPacket->stageFlags, pPacket->pSetBindPoints, remap(pPacket->priorSetLayout), pPacket->pSetLayoutInfoList, &setLayout);') - cdsl_body.append(' if (replayResult == XGL_SUCCESS)') - cdsl_body.append(' {') - cdsl_body.append(' add_to_map(pPacket->pSetLayout, &setLayout);') - cdsl_body.append(' }') - cdsl_body.append(' if (pPacket->pSetLayoutInfoList != NULL) {') - cdsl_body.append(' XGL_SAMPLER *pSampler = (XGL_SAMPLER *) &pPacket->pSetLayoutInfoList->immutableSampler;') - cdsl_body.append(' *pSampler = saveSampler;') - cdsl_body.append(' }') + cdsl_body.append(' returnValue = manually_handle_xglCreateDescriptorSetLayout(pPacket);') return "\n".join(cdsl_body) def _gen_replay_create_graphics_pipeline(self): cgp_body = [] - cgp_body.append(' XGL_GRAPHICS_PIPELINE_CREATE_INFO createInfo;') - cgp_body.append(' struct shaderPair saveShader[10];') - cgp_body.append(' unsigned int idx = 0;') - cgp_body.append(' memcpy(&createInfo, pPacket->pCreateInfo, sizeof(XGL_GRAPHICS_PIPELINE_CREATE_INFO));') - cgp_body.append(' createInfo.lastSetLayout = remap(createInfo.lastSetLayout);') - cgp_body.append(' // Cast to shader type, as those are of primariy interest and all structs in LL have same header w/ sType & pNext') - cgp_body.append(' XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pPacketNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pPacket->pCreateInfo->pNext;') - cgp_body.append(' XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)createInfo.pNext;') - cgp_body.append(' while (XGL_NULL_HANDLE != pPacketNext)') - cgp_body.append(' {') - cgp_body.append(' if (XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO == pNext->sType)') - cgp_body.append(' {') - cgp_body.append(' saveShader[idx].val = pNext->shader.shader;') - cgp_body.append(' saveShader[idx++].addr = &(pNext->shader.shader);') - cgp_body.append(' pNext->shader.shader = remap(pPacketNext->shader.shader);') - cgp_body.append(' }') - cgp_body.append(' pPacketNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pPacketNext->pNext;') - cgp_body.append(' pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pNext->pNext;') - cgp_body.append(' }') - cgp_body.append(' XGL_PIPELINE pipeline;') - cgp_body.append(' replayResult = m_xglFuncs.real_xglCreateGraphicsPipeline(remap(pPacket->device), &createInfo, &pipeline);') - cgp_body.append(' if (replayResult == XGL_SUCCESS)') - cgp_body.append(' {') - cgp_body.append(' add_to_map(pPacket->pPipeline, &pipeline);') - cgp_body.append(' }') - cgp_body.append(' for (unsigned int i = 0; i < idx; i++)') - cgp_body.append(' *(saveShader[i].addr) = saveShader[i].val;') + cgp_body.append(' returnValue = manually_handle_xglCreateGraphicsPipeline(pPacket);') return "\n".join(cgp_body) def _gen_replay_cmd_wait_events(self): cwe_body = [] - cwe_body.append(' XGL_EVENT saveEvent[100];') - cwe_body.append(' uint32_t idx, numRemapBuf=0, numRemapImg=0;') - cwe_body.append(' assert(pPacket->pWaitInfo && pPacket->pWaitInfo->eventCount <= 100);') - cwe_body.append(' for (idx = 0; idx < pPacket->pWaitInfo->eventCount; idx++)') - cwe_body.append(' {') - cwe_body.append(' XGL_EVENT *pEvent = (XGL_EVENT *) &(pPacket->pWaitInfo->pEvents[idx]);') - cwe_body.append(' saveEvent[idx] = pPacket->pWaitInfo->pEvents[idx];') - cwe_body.append(' *pEvent = remap(pPacket->pWaitInfo->pEvents[idx]);') - cwe_body.append(' }') - cwe_body.append('') - cwe_body.append(' XGL_BUFFER saveBuf[100];') - cwe_body.append(' XGL_IMAGE saveImg[100];') - cwe_body.append(' for (idx = 0; idx < pPacket->pWaitInfo->memBarrierCount; idx++)') - cwe_body.append(' {') - cwe_body.append(' XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx];') - cwe_body.append(' assert(pNext);') - cwe_body.append(' if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) {') - cwe_body.append(' XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx];') - cwe_body.append(' assert(numRemapBuf < 100);') - cwe_body.append(' saveBuf[numRemapBuf++] = pNextBuf->buffer;') - cwe_body.append(' pNextBuf->buffer = remap(pNextBuf->buffer);') - cwe_body.append(' } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {') - cwe_body.append(' XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx];') - cwe_body.append(' assert(numRemapImg < 100);') - cwe_body.append(' saveImg[numRemapImg++] = pNextImg->image;') - cwe_body.append(' pNextImg->image = remap(pNextImg->image);') - cwe_body.append(' }') - cwe_body.append(' }') - cwe_body.append(' m_xglFuncs.real_xglCmdWaitEvents(remap(pPacket->cmdBuffer), pPacket->pWaitInfo);') - cwe_body.append(' for (idx = 0; idx < pPacket->pWaitInfo->memBarrierCount; idx++) {') - cwe_body.append(' XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx];') - cwe_body.append(' if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) {') - cwe_body.append(' XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx];') - cwe_body.append(' pNextBuf->buffer = saveBuf[idx];') - cwe_body.append(' } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {') - cwe_body.append(' XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx];') - cwe_body.append(' pNextImg->image = saveImg[idx];') - cwe_body.append(' }') - cwe_body.append(' }') - cwe_body.append(' for (idx = 0; idx < pPacket->pWaitInfo->eventCount; idx++) {') - cwe_body.append(' XGL_EVENT *pEvent = (XGL_EVENT *) &(pPacket->pWaitInfo->pEvents[idx]);') - cwe_body.append(' *pEvent = saveEvent[idx];') - cwe_body.append(' }') + cwe_body.append(' returnValue = manually_handle_xglCmdWaitEvents(pPacket);') return "\n".join(cwe_body) def _gen_replay_cmd_pipeline_barrier(self): cpb_body = [] - cpb_body.append(' uint32_t idx, numRemapBuf=0, numRemapImg=0;') - cpb_body.append(' XGL_BUFFER saveBuf[100];') - cpb_body.append(' XGL_IMAGE saveImg[100];') - cpb_body.append(' for (idx = 0; idx < pPacket->pBarrier->memBarrierCount; idx++)') - cpb_body.append(' {') - cpb_body.append(' XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx];') - cpb_body.append(' assert(pNext);') - cpb_body.append(' if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) {') - cpb_body.append(' XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx];') - cpb_body.append(' assert(numRemapBuf < 100);') - cpb_body.append(' saveBuf[numRemapBuf++] = pNextBuf->buffer;') - cpb_body.append(' pNextBuf->buffer = remap(pNextBuf->buffer);') - cpb_body.append(' } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {') - cpb_body.append(' XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx];') - cpb_body.append(' assert(numRemapImg < 100);') - cpb_body.append(' saveImg[numRemapImg++] = pNextImg->image;') - cpb_body.append(' pNextImg->image = remap(pNextImg->image);') - cpb_body.append(' }') - cpb_body.append(' }') - cpb_body.append(' m_xglFuncs.real_xglCmdPipelineBarrier(remap(pPacket->cmdBuffer), pPacket->pBarrier);') - cpb_body.append(' for (idx = 0; idx < pPacket->pBarrier->memBarrierCount; idx++) {') - cpb_body.append(' XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx];') - cpb_body.append(' if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) {') - cpb_body.append(' XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx];') - cpb_body.append(' pNextBuf->buffer = saveBuf[idx];') - cpb_body.append(' } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {') - cpb_body.append(' XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx];') - cpb_body.append(' pNextImg->image = saveImg[idx];') - cpb_body.append(' }') - cpb_body.append(' }') + cpb_body.append(' returnValue = manually_handle_xglCmdPipelineBarrier(pPacket);') return "\n".join(cpb_body) def _gen_replay_create_framebuffer(self): cf_body = [] - cf_body.append(' XGL_FRAMEBUFFER_CREATE_INFO *pInfo = (XGL_FRAMEBUFFER_CREATE_INFO *) pPacket->pCreateInfo;') - cf_body.append(' XGL_COLOR_ATTACHMENT_BIND_INFO *pColorAttachments, *pSavedColor = (XGL_COLOR_ATTACHMENT_BIND_INFO*)pInfo->pColorAttachments;') - cf_body.append(' bool allocatedColorAttachments = false;') - cf_body.append(' if (pSavedColor != NULL)') - cf_body.append(' {') - cf_body.append(' allocatedColorAttachments = true;') - cf_body.append(' pColorAttachments = GLV_NEW_ARRAY(XGL_COLOR_ATTACHMENT_BIND_INFO, pInfo->colorAttachmentCount);') - cf_body.append(' memcpy(pColorAttachments, pSavedColor, sizeof(XGL_COLOR_ATTACHMENT_BIND_INFO) * pInfo->colorAttachmentCount);') - cf_body.append(' for (uint32_t i = 0; i < pInfo->colorAttachmentCount; i++)') - cf_body.append(' {') - cf_body.append(' pColorAttachments[i].view = remap(pInfo->pColorAttachments[i].view);') - cf_body.append(' }') - cf_body.append(' pInfo->pColorAttachments = pColorAttachments;') - cf_body.append(' }') - cf_body.append(' // remap depth stencil target') - cf_body.append(' const XGL_DEPTH_STENCIL_BIND_INFO *pSavedDS = pInfo->pDepthStencilAttachment;') - cf_body.append(' XGL_DEPTH_STENCIL_BIND_INFO depthTarget;') - cf_body.append(' if (pSavedDS != NULL)') - cf_body.append(' {') - cf_body.append(' memcpy(&depthTarget, pSavedDS, sizeof(XGL_DEPTH_STENCIL_BIND_INFO));') - cf_body.append(' depthTarget.view = remap(pSavedDS->view);') - cf_body.append(' pInfo->pDepthStencilAttachment = &depthTarget;') - cf_body.append(' }') - cf_body.append(' XGL_FRAMEBUFFER local_framebuffer;') - cf_body.append(' replayResult = m_xglFuncs.real_xglCreateFramebuffer(remap(pPacket->device), pPacket->pCreateInfo, &local_framebuffer);') - cf_body.append(' pInfo->pColorAttachments = pSavedColor;') - cf_body.append(' pInfo->pDepthStencilAttachment = pSavedDS;') - cf_body.append(' if (replayResult == XGL_SUCCESS)') - cf_body.append(' {') - cf_body.append(' add_to_map(pPacket->pFramebuffer, &local_framebuffer);') - cf_body.append(' }') - cf_body.append(' if (allocatedColorAttachments)') - cf_body.append(' {') - cf_body.append(' GLV_DELETE((void*)pColorAttachments);') - cf_body.append(' }') + cf_body.append(' returnValue = manually_handle_xglCreateFramebuffer(pPacket);') return "\n".join(cf_body) def _gen_replay_create_renderpass(self): cr_body = [] - cr_body.append(' XGL_RENDER_PASS_CREATE_INFO *pInfo = (XGL_RENDER_PASS_CREATE_INFO *) pPacket->pCreateInfo;') - cr_body.append(' // remap framebuffer') - cr_body.append(' XGL_FRAMEBUFFER savedFB = 0, *pFB = &(pInfo->framebuffer);') - cr_body.append(' if (*pFB != NULL)') - cr_body.append(' {') - cr_body.append(' savedFB = pInfo->framebuffer;') - cr_body.append(' *pFB = remap(pInfo->framebuffer);') - cr_body.append(' }') - cr_body.append(' XGL_RENDER_PASS local_renderpass;') - cr_body.append(' replayResult = m_xglFuncs.real_xglCreateRenderPass(remap(pPacket->device), pPacket->pCreateInfo, &local_renderpass);') - cr_body.append(' if (*pFB != NULL)') - cr_body.append(' pInfo->framebuffer = savedFB;') - cr_body.append(' if (replayResult == XGL_SUCCESS)') - cr_body.append(' {') - cr_body.append(' add_to_map(pPacket->pRenderPass, &local_renderpass);') - cr_body.append(' }') + cr_body.append(' returnValue = manually_handle_xglCreateRenderPass(pPacket);') return "\n".join(cr_body) def _gen_replay_begin_command_buffer(self): bcb_body = [] - bcb_body.append(' XGL_CMD_BUFFER_BEGIN_INFO* pInfo = (XGL_CMD_BUFFER_BEGIN_INFO*)pPacket->pBeginInfo;') - bcb_body.append(' // assume only zero or one graphics_begin_info in the chain') - bcb_body.append(' XGL_RENDER_PASS savedRP, *pRP;') - bcb_body.append(' XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO *pGInfo = NULL;') - bcb_body.append(' while (pInfo != NULL)') - bcb_body.append(' {') - bcb_body.append('') - bcb_body.append(' if (pInfo->sType == XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO)') - bcb_body.append(' {') - bcb_body.append(' pGInfo = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO *) pInfo;') - bcb_body.append(' savedRP = pGInfo->renderPass;') - bcb_body.append(' pRP = &(pGInfo->renderPass);') - bcb_body.append(' *pRP = remap(pGInfo->renderPass);') - bcb_body.append(' break;') - bcb_body.append(' }') - bcb_body.append(' pInfo = (XGL_CMD_BUFFER_BEGIN_INFO*) pInfo->pNext;') - bcb_body.append(' }') - bcb_body.append(' replayResult = m_xglFuncs.real_xglBeginCommandBuffer(remap(pPacket->cmdBuffer), pPacket->pBeginInfo);') - bcb_body.append(' if (pGInfo != NULL)') - bcb_body.append(' pGInfo->renderPass = savedRP;') + bcb_body.append(' returnValue = manually_handle_xglBeginCommandBuffer(pPacket);') return "\n".join(bcb_body) def _gen_replay_store_pipeline(self): sp_body = [] - sp_body.append(' size_t size = 0;') - sp_body.append(' void* pData = NULL;') - sp_body.append(' if (pPacket->pData != NULL && pPacket->pDataSize != NULL)') - sp_body.append(' {') - sp_body.append(' size = *pPacket->pDataSize;') - sp_body.append(' pData = glv_malloc(*pPacket->pDataSize);') - sp_body.append(' }') - sp_body.append(' replayResult = m_xglFuncs.real_xglStorePipeline(remap(pPacket->pipeline), &size, pData);') - sp_body.append(' if (replayResult == XGL_SUCCESS)') - sp_body.append(' {') - sp_body.append(' if (size != *pPacket->pDataSize && pData != NULL)') - sp_body.append(' {') - sp_body.append(' glv_LogWarn("xglStorePipeline returned a differing data size: replay (%d bytes) vs trace (%d bytes)\\n", size, *pPacket->pDataSize);') - sp_body.append(' }') - sp_body.append(' else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0)') - sp_body.append(' {') - sp_body.append(' glv_LogWarn("xglStorePipeline returned differing data contents than the trace file contained.\\n");') - sp_body.append(' }') - sp_body.append(' }') - sp_body.append(' glv_free(pData);') + sp_body.append(' returnValue = manually_handle_xglStorePipeline(pPacket);') return "\n".join(sp_body) def _gen_replay_get_multi_gpu_compatibility(self): gmgc_body = [] - gmgc_body.append(' XGL_GPU_COMPATIBILITY_INFO cInfo;') - gmgc_body.append(' XGL_PHYSICAL_GPU handle0, handle1;') - gmgc_body.append(' handle0 = remap(pPacket->gpu0);') - gmgc_body.append(' handle1 = remap(pPacket->gpu1);') - gmgc_body.append(' replayResult = m_xglFuncs.real_xglGetMultiGpuCompatibility(handle0, handle1, &cInfo);') + gmgc_body.append(' returnValue = manually_handle_xglGetMultiGpuCompatibility(pPacket);') return "\n".join(gmgc_body) def _gen_replay_destroy_object(self): do_body = [] - do_body.append(' XGL_OBJECT object = remap(pPacket->object);') - do_body.append(' if (object != XGL_NULL_HANDLE)') - do_body.append(' replayResult = m_xglFuncs.real_xglDestroyObject(object);') - do_body.append(' if (replayResult == XGL_SUCCESS)') - do_body.append(' rm_from_map(pPacket->object);') + do_body.append(' returnValue = manually_handle_xglDestroyObject(pPacket);') return "\n".join(do_body) def _gen_replay_wait_for_fences(self): wf_body = [] - wf_body.append(' XGL_FENCE *pFence = GLV_NEW_ARRAY(XGL_FENCE, pPacket->fenceCount);') - wf_body.append(' for (uint32_t i = 0; i < pPacket->fenceCount; i++)') - wf_body.append(' {') - wf_body.append(' *(pFence + i) = remap(*(pPacket->pFences + i));') - wf_body.append(' }') - wf_body.append(' replayResult = m_xglFuncs.real_xglWaitForFences(remap(pPacket->device), pPacket->fenceCount, pFence, pPacket->waitAll, pPacket->timeout);') - wf_body.append(' GLV_DELETE(pFence);') + wf_body.append(' returnValue = manually_handle_xglWaitForFences(pPacket);') return "\n".join(wf_body) def _gen_replay_wsi_associate_connection(self): @@ -3088,34 +2127,22 @@ class Subcommand(object): wqp_body.append(' m_display->m_frameNumber++;') return "\n".join(wqp_body) - # I don't like making these 3 mem functions 'fully' custom, but just doing it for now to avoid being too cute def _gen_replay_free_memory(self): fm_body = [] - fm_body.append(' XGL_GPU_MEMORY handle = remap(pPacket->mem);') - fm_body.append(' replayResult = m_xglFuncs.real_xglFreeMemory(handle);') - fm_body.append(' if (replayResult == XGL_SUCCESS) ') - fm_body.append(' {') - fm_body.append(' rm_entry_from_mapData(handle);') - fm_body.append(' rm_from_map(pPacket->mem);') - fm_body.append(' }') + fm_body.append(' returnValue = manually_handle_xglFreeMemory(pPacket);') return "\n".join(fm_body) def _gen_replay_map_memory(self): mm_body = [] - mm_body.append(' XGL_GPU_MEMORY handle = remap(pPacket->mem);') - mm_body.append(' void* pData;') - mm_body.append(' replayResult = m_xglFuncs.real_xglMapMemory(handle, pPacket->flags, &pData);') - mm_body.append(' if (replayResult == XGL_SUCCESS)') - mm_body.append(' add_mapping_to_mapData(handle, pData);') + mm_body.append(' returnValue = manually_handle_xglMapMemory(pPacket);') return "\n".join(mm_body) def _gen_replay_unmap_memory(self): um_body = [] - um_body.append(' XGL_GPU_MEMORY handle = remap(pPacket->mem);') - um_body.append(' rm_mapping_from_mapData(handle, pPacket->pData); // copies data from packet into memory buffer') - um_body.append(' replayResult = m_xglFuncs.real_xglUnmapMemory(handle);') + um_body.append(' returnValue = manually_handle_xglUnmapMemory(pPacket);') return "\n".join(um_body) + # I don't think this function is being generated anymore (ie, it may have been removed from XGL) def _gen_replay_bind_dynamic_memory_view(self): bdmv_body = [] bdmv_body.append(' XGL_MEMORY_VIEW_ATTACH_INFO memView;') @@ -3157,7 +2184,10 @@ class Subcommand(object): 'CmdPipelineBarrier': self._gen_replay_cmd_pipeline_barrier} # TODO : Need to guard CreateInstance with "if (!m_display->m_initedXGL)" check # Despite returning a value, don't check these funcs b/c custom code includes check already - custom_check_ret_val = ['EnumerateGpus', 'GetGpuInfo', 'CreateDevice', 'GetExtensionSupport'] + custom_check_ret_val = ['EnumerateGpus', 'GetGpuInfo', 'CreateDevice', 'GetExtensionSupport', 'QueueSubmit', 'GetObjectInfo', + 'GetFormatInfo', 'GetImageSubresourceInfo', 'CreateDescriptorSetLayout', 'CreateGraphicsPipeline', + 'CreateFramebuffer', 'CreateRenderPass', 'BeginCommandBuffer', 'StorePipeline', 'GetMultiGpuCompatibility', + 'DestroyObject', 'WaitForFences', 'FreeMemory', 'MapMemory', 'UnmapMemory'] # multi-gpu Open funcs w/ list of local params to create custom_open_params = {'OpenSharedMemory': (-1,), 'OpenSharedQueueSemaphore': (-1,), @@ -3170,7 +2200,6 @@ class Subcommand(object): # A couple funcs use do while loops do_while_dict = {'GetFenceStatus': 'replayResult != pPacket->result && pPacket->result == XGL_SUCCESS', 'GetEventStatus': '(pPacket->result == XGL_EVENT_SET || pPacket->result == XGL_EVENT_RESET) && replayResult != pPacket->result'} rbody = [] - rbody.append('#define CHECK_RETURN_VALUE(entrypoint) returnValue = handle_replay_errors(#entrypoint, replayResult, pPacket->result, returnValue);\n') rbody.append('glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet)') rbody.append('{') rbody.append(' glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS;') @@ -3562,6 +2591,9 @@ class GlaveReplayHeader(Subcommand): header_txt.append('#include "glvreplay_window.h"') header_txt.append('#include "glvreplay_factory.h"') header_txt.append('#include "glv_trace_packet_identifiers.h"\n') + header_txt.append('extern "C" {\n') + header_txt.append('#include "glv_vk_vk_structs.h"\n') + header_txt.append('}\n') header_txt.append('#include "xgl.h"') header_txt.append('#include "xglDbg.h"') header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') @@ -3571,12 +2603,12 @@ class GlaveReplayHeader(Subcommand): header_txt.append('#endif') header_txt.append('#include "draw_state.h"') header_txt.append('#include "glave_snapshot.h"') + header_txt.append('#include "glvreplay_xgl_xgldisplay.h"') header_txt.append('#include "glvreplay_xgl_func_ptrs.h"') return "\n".join(header_txt) def generate_body(self): - body = [self._generate_replay_class_decls(), - self._generate_replay_class()] + body = [self._generate_replay_class()] return "\n".join(body) @@ -3589,7 +2621,7 @@ class GlaveReplayC(Subcommand): header_txt.append('#include "glvreplay_main.h"\n') header_txt.append('#include ') header_txt.append('#include ') - header_txt.append('glvreplay_settings *g_pReplaySettings;') + header_txt.append('\n') header_txt.append('extern "C" {') header_txt.append('#include "glv_vk_vk_structs.h"') header_txt.append('#include "glv_vk_vkdbg_structs.h"') @@ -3598,29 +2630,11 @@ class GlaveReplayC(Subcommand): header_txt.append('#include "xgl_enum_string_helper.h"\n}\n') header_txt.append('#define APP_NAME "glvreplay_xgl"') header_txt.append('#define IDI_ICON 101\n') - header_txt.append('static const char* g_extensions[] =') - header_txt.append('{') - header_txt.append(' "XGL_WSI_WINDOWS",') - header_txt.append(' "XGL_TIMER_QUEUE",') - header_txt.append(' "XGL_GPU_TIMESTAMP_CALIBRATION",') - header_txt.append(' "XGL_DMA_QUEUE",') - header_txt.append(' "XGL_COMMAND_BUFFER_CONTROL_FLOW",') - header_txt.append(' "XGL_COPY_OCCLUSION_QUERY_DATA",') - header_txt.append(' "XGL_ADVANCED_MULTISAMPLING",') - header_txt.append(' "XGL_BORDER_COLOR_PALETTE"') - header_txt.append('};') + return "\n".join(header_txt) def generate_body(self): - body = [self._generate_replay_display_init_xgl(), - self._generate_replay_display_init(), - self._generate_replay_display_structors(), - self._generate_replay_display_window(), - self._generate_replay_structors(), - self._generate_replay_init(), - self._generate_replay_errors(), - self._generate_replay_validation_funcs(), - self._generate_replay_init_funcs(), + body = [self._generate_replay_init_funcs(), self._generate_replay()] return "\n".join(body) diff --git a/tools/glave/src/glv_extensions/glvreplay_xgl/CMakeLists.txt b/tools/glave/src/glv_extensions/glvreplay_xgl/CMakeLists.txt index b130615..f06eaea 100644 --- a/tools/glave/src/glv_extensions/glvreplay_xgl/CMakeLists.txt +++ b/tools/glave/src/glv_extensions/glvreplay_xgl/CMakeLists.txt @@ -16,14 +16,14 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/codegen/glv_vk_packet_id.h ${CMAKE_CURRENT_SOURCE_DIR}/codegen/glv_vk_vkdbg_structs.h ${CMAKE_CURRENT_SOURCE_DIR}/codegen/glvreplay_xgl_func_ptrs.h ${CMAKE_CURRENT_SOURCE_DIR}/codegen/glvreplay_xgl_replay.h - ${CMAKE_CURRENT_SOURCE_DIR}/codegen/glvreplay_xgl_replay.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/codegen/glvreplay_xgl_replay_gen.cpp COMMAND ${PYTHON_CMD} ${SRC_DIR}/../scripts/vk_generate.py glave-packet-id > glv_vk_packet_id.h COMMAND ${PYTHON_CMD} ${SRC_DIR}/../scripts/vk_generate.py glave-core-structs > glv_vk_vk_structs.h COMMAND ${PYTHON_CMD} ${SRC_DIR}/../scripts/vk_generate.py glave-wsi-trace-structs > glv_vk_vkwsix11ext_structs.h COMMAND ${PYTHON_CMD} ${SRC_DIR}/../scripts/vk_generate.py glave-dbg-trace-structs > glv_vk_vkdbg_structs.h COMMAND ${PYTHON_CMD} ${SRC_DIR}/../scripts/vk_generate.py glave-replay-xgl-funcs > glvreplay_xgl_func_ptrs.h COMMAND ${PYTHON_CMD} ${SRC_DIR}/../scripts/vk_generate.py glave-replay-h > glvreplay_xgl_replay.h - COMMAND ${PYTHON_CMD} ${SRC_DIR}/../scripts/vk_generate.py glave-replay-c > glvreplay_xgl_replay.cpp + COMMAND ${PYTHON_CMD} ${SRC_DIR}/../scripts/vk_generate.py glave-replay-c > glvreplay_xgl_replay_gen.cpp COMMAND ${PYTHON_CMD} ${SRC_DIR}/../../../xgl_helper.py --gen_enum_string_helper ${SRC_DIR}/../../../include/xgl.h --abs_out_dir ${CMAKE_CURRENT_SOURCE_DIR}/codegen DEPENDS ${SRC_DIR}/../scripts/vk_generate.py ${SRC_DIR}/../../../xgl_helper.py @@ -50,7 +50,9 @@ set(SRC_LIST ${SRC_LIST} glvreplay_xgl.cpp glvreplay_xgl_settings.cpp - codegen/glvreplay_xgl_replay.cpp + glvreplay_xgl_xglreplay.cpp + glvreplay_xgl_xgldisplay.cpp + codegen/glvreplay_xgl_replay_gen.cpp ) set (HDR_LIST @@ -61,6 +63,7 @@ set (HDR_LIST codegen/xgl_enum_string_helper.h glvreplay_xgl.h glvreplay_xgl_settings.h + glvreplay_xgl_xgldisplay.h codegen/glvreplay_xgl_func_ptrs.h codegen/glvreplay_xgl_replay.h ) diff --git a/tools/glave/src/glv_extensions/glvreplay_xgl/codegen/glvreplay_xgl_replay.h b/tools/glave/src/glv_extensions/glvreplay_xgl/codegen/glvreplay_xgl_replay.h index 74ab841..dd0c523 100644 --- a/tools/glave/src/glv_extensions/glvreplay_xgl/codegen/glvreplay_xgl_replay.h +++ b/tools/glave/src/glv_extensions/glvreplay_xgl/codegen/glvreplay_xgl_replay.h @@ -38,6 +38,12 @@ #include "glvreplay_factory.h" #include "glv_trace_packet_identifiers.h" +extern "C" { + +#include "glv_vk_vk_structs.h" + +} + #include "xgl.h" #include "xglDbg.h" #if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) @@ -47,55 +53,16 @@ #endif #include "draw_state.h" #include "glave_snapshot.h" +#include "glvreplay_xgl_xgldisplay.h" #include "glvreplay_xgl_func_ptrs.h" -class xglDisplay: public glv_replay::DisplayImp { -friend class xglReplay; -public: - xglDisplay(); - ~xglDisplay(); - int init(const unsigned int gpu_idx); - int set_window(glv_window_handle hWindow, unsigned int width, unsigned int height); - int create_window(const unsigned int width, const unsigned int height); - void resize_window(const unsigned int width, const unsigned int height); - void process_event(); - // XGL_DEVICE get_device() { return m_dev[m_gpuIdx];} -#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) - xcb_window_t get_window_handle() { return m_XcbWindow; } -#elif defined(WIN32) - HWND get_window_handle() { return m_windowHandle; } -#endif -private: - XGL_RESULT init_xgl(const unsigned int gpu_idx); - bool m_initedXGL; -#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) - XGL_WSI_X11_CONNECTION_INFO m_WsiConnection; - xcb_screen_t *m_pXcbScreen; - xcb_window_t m_XcbWindow; -#elif defined(WIN32) - HWND m_windowHandle; -#endif - unsigned int m_windowWidth; - unsigned int m_windowHeight; - unsigned int m_frameNumber; - std::vector imageWidth; - std::vector imageHeight; - std::vector imageHandles; - std::vector imageMemory; -#if 0 - XGL_DEVICE m_dev[XGL_MAX_PHYSICAL_GPUS]; - uint32_t m_gpuCount; - unsigned int m_gpuIdx; - XGL_PHYSICAL_GPU m_gpus[XGL_MAX_PHYSICAL_GPUS]; - XGL_PHYSICAL_GPU_PROPERTIES m_gpuProps[XGL_MAX_PHYSICAL_GPUS]; -#endif - std::vectorm_extensions; -}; - typedef struct _XGLAllocInfo { XGL_GPU_SIZE size; void *pData; } XGLAllocInfo; + +#define CHECK_RETURN_VALUE(entrypoint) returnValue = handle_replay_errors(#entrypoint, replayResult, pPacket->result, returnValue); + class xglReplay { public: ~xglReplay(); @@ -128,6 +95,29 @@ private: }; std::vector m_validationMsgs; std::vector m_screenshotFrames; + glv_replay::GLV_REPLAY_RESULT manually_handle_xglCreateDevice(struct_xglCreateDevice* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglEnumerateGpus(struct_xglEnumerateGpus* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglGetGpuInfo(struct_xglGetGpuInfo* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglGetExtensionSupport(struct_xglGetExtensionSupport* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglQueueSubmit(struct_xglQueueSubmit* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglGetObjectInfo(struct_xglGetObjectInfo* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglGetFormatInfo(struct_xglGetFormatInfo* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglGetImageSubresourceInfo(struct_xglGetImageSubresourceInfo* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglUpdateDescriptors(struct_xglUpdateDescriptors* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglCreateDescriptorSetLayout(struct_xglCreateDescriptorSetLayout* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglCreateGraphicsPipeline(struct_xglCreateGraphicsPipeline* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglCmdWaitEvents(struct_xglCmdWaitEvents* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglCmdPipelineBarrier(struct_xglCmdPipelineBarrier* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglCreateFramebuffer(struct_xglCreateFramebuffer* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglCreateRenderPass(struct_xglCreateRenderPass* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglBeginCommandBuffer(struct_xglBeginCommandBuffer* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglStorePipeline(struct_xglStorePipeline* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglGetMultiGpuCompatibility(struct_xglGetMultiGpuCompatibility* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglDestroyObject(struct_xglDestroyObject* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglWaitForFences(struct_xglWaitForFences* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglFreeMemory(struct_xglFreeMemory* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglMapMemory(struct_xglMapMemory* pPacket); + glv_replay::GLV_REPLAY_RESULT manually_handle_xglUnmapMemory(struct_xglUnmapMemory* pPacket); std::map m_mapData; void add_entry_to_mapData(XGL_GPU_MEMORY handle, XGL_GPU_SIZE size) { diff --git a/tools/glave/src/glv_extensions/glvreplay_xgl/codegen/glvreplay_xgl_replay.cpp b/tools/glave/src/glv_extensions/glvreplay_xgl/codegen/glvreplay_xgl_replay_gen.cpp similarity index 59% rename from tools/glave/src/glv_extensions/glvreplay_xgl/codegen/glvreplay_xgl_replay.cpp rename to tools/glave/src/glv_extensions/glvreplay_xgl/codegen/glvreplay_xgl_replay_gen.cpp index 323799b..8652272 100644 --- a/tools/glave/src/glv_extensions/glvreplay_xgl/codegen/glvreplay_xgl_replay.cpp +++ b/tools/glave/src/glv_extensions/glvreplay_xgl/codegen/glvreplay_xgl_replay_gen.cpp @@ -34,7 +34,8 @@ #include #include -glvreplay_settings *g_pReplaySettings; + + extern "C" { #include "glv_vk_vk_structs.h" #include "glv_vk_vkdbg_structs.h" @@ -46,352 +47,7 @@ extern "C" { #define APP_NAME "glvreplay_xgl" #define IDI_ICON 101 -static const char* g_extensions[] = -{ - "XGL_WSI_WINDOWS", - "XGL_TIMER_QUEUE", - "XGL_GPU_TIMESTAMP_CALIBRATION", - "XGL_DMA_QUEUE", - "XGL_COMMAND_BUFFER_CONTROL_FLOW", - "XGL_COPY_OCCLUSION_QUERY_DATA", - "XGL_ADVANCED_MULTISAMPLING", - "XGL_BORDER_COLOR_PALETTE" -}; - -XGL_RESULT xglDisplay::init_xgl(unsigned int gpu_idx) -{ -#if 0 - XGL_APPLICATION_INFO appInfo = {}; - appInfo.pAppName = APP_NAME; - appInfo.pEngineName = ""; - appInfo.apiVersion = XGL_API_VERSION; - XGL_RESULT res = xglInitAndEnumerateGpus(&appInfo, NULL, XGL_MAX_PHYSICAL_GPUS, &m_gpuCount, m_gpus); - if ( res == XGL_SUCCESS ) { - // retrieve the GPU information for all GPUs - for( uint32_t gpu = 0; gpu < m_gpuCount; gpu++) - { - size_t gpuInfoSize = sizeof(m_gpuProps[0]); - - // get the GPU physical properties: - res = xglGetGpuInfo( m_gpus[gpu], XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES, &gpuInfoSize, &m_gpuProps[gpu]); - if (res != XGL_SUCCESS) - glv_LogWarn("Failed to retrieve properties for gpu[%d] result %d\n", gpu, res); - } - res = XGL_SUCCESS; - } else if ((gpu_idx + 1) > m_gpuCount) { - glv_LogError("xglInitAndEnumerate number of gpus does not include requested index: num %d, requested %d\n", m_gpuCount, gpu_idx); - return -1; - } else { - glv_LogError("xglInitAndEnumerate failed\n"); - return res; - } - // TODO add multi-gpu support always use gpu[gpu_idx] for now - // get all extensions supported by this device gpu[gpu_idx] - // first check if extensions are available and save a list of them - bool foundWSIExt = false; - for( int ext = 0; ext < sizeof( extensions ) / sizeof( extensions[0] ); ext++) - { - res = xglGetExtensionSupport( m_gpus[gpu_idx], extensions[ext] ); - if (res == XGL_SUCCESS) { - m_extensions.push_back((char *) extensions[ext]); - if (!strcmp(extensions[ext], "XGL_WSI_WINDOWS")) - foundWSIExt = true; - } - } - if (!foundWSIExt) { - glv_LogError("XGL_WSI_WINDOWS extension not supported by gpu[%d]\n", gpu_idx); - return XGL_ERROR_INCOMPATIBLE_DEVICE; - } - // TODO generalize this: use one universal queue for now - XGL_DEVICE_QUEUE_CREATE_INFO dqci = {}; - dqci.queueCount = 1; - dqci.queueType = XGL_QUEUE_UNIVERSAL; - // create the device enabling validation level 4 - const char * const * extNames = &m_extensions[0]; - XGL_DEVICE_CREATE_INFO info = {}; - info.queueRecordCount = 1; - info.pRequestedQueues = &dqci; - info.extensionCount = static_cast (m_extensions.size()); - info.ppEnabledExtensionNames = extNames; - info.flags = XGL_DEVICE_CREATE_VALIDATION; - info.maxValidationLevel = XGL_VALIDATION_LEVEL_4; - bool32_t xglTrue = XGL_TRUE; - res = xglDbgSetGlobalOption( XGL_DBG_OPTION_BREAK_ON_ERROR, sizeof( xglTrue ), &xglTrue ); - if (res != XGL_SUCCESS) - glv_LogWarn("Could not set debug option break on error\n"); - res = xglCreateDevice( m_gpus[0], &info, &m_dev[gpu_idx]); - return res; -#else - return XGL_ERROR_INITIALIZATION_FAILED; -#endif -} -int xglDisplay::init(const unsigned int gpu_idx) -{ - //m_gpuIdx = gpu_idx; -#if 0 - XGL_RESULT result = init_xgl(gpu_idx); - if (result != XGL_SUCCESS) { - glv_LogError("could not init xgl library"); - return -1; - } else { - m_initedXGL = true; - } -#endif -#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) - const xcb_setup_t *setup; - xcb_screen_iterator_t iter; - int scr; - xcb_connection_t *pConnection; - pConnection = xcb_connect(NULL, &scr); - setup = xcb_get_setup(pConnection); - iter = xcb_setup_roots_iterator(setup); - while (scr-- > 0) - xcb_screen_next(&iter); - m_pXcbScreen = iter.data; - m_WsiConnection.pConnection = pConnection; - m_WsiConnection.root = m_pXcbScreen->root; -#endif - return 0; -} -xglDisplay::xglDisplay() - : m_initedXGL(false), - m_windowWidth(0), - m_windowHeight(0) -{ -#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) - m_WsiConnection.pConnection = NULL; - m_WsiConnection.root = 0; - m_WsiConnection.provider = 0; - m_pXcbScreen = NULL; - m_XcbWindow = 0; -#elif defined(WIN32) - m_windowHandle = NULL; -#endif -} -xglDisplay::~xglDisplay() -{ -#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) - if (m_XcbWindow != 0) - { - xcb_destroy_window(m_WsiConnection.pConnection, m_XcbWindow); - } - if (m_WsiConnection.pConnection != NULL) - { - xcb_disconnect(m_WsiConnection.pConnection); - } -#endif -} -#if defined(WIN32) -LRESULT WINAPI WindowProcXgl( HWND window, unsigned int msg, WPARAM wp, LPARAM lp) -{ - switch(msg) - { - case WM_CLOSE: - DestroyWindow( window); - // fall-thru - case WM_DESTROY: - PostQuitMessage(0) ; - return 0L ; - default: - return DefWindowProc( window, msg, wp, lp ) ; - } -} -#endif -int xglDisplay::set_window(glv_window_handle hWindow, unsigned int width, unsigned int height) -{ -#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) - m_XcbWindow = hWindow; -#elif defined(WIN32) - m_windowHandle = hWindow; -#endif - m_windowWidth = width; - m_windowHeight = height; - return 0; -} - -int xglDisplay::create_window(const unsigned int width, const unsigned int height) -{ -#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) - - uint32_t value_mask, value_list[32]; - m_XcbWindow = xcb_generate_id(m_WsiConnection.pConnection); - - value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; - value_list[0] = m_pXcbScreen->black_pixel; - value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | - XCB_EVENT_MASK_EXPOSURE; - - xcb_create_window(m_WsiConnection.pConnection, - XCB_COPY_FROM_PARENT, - m_XcbWindow, m_WsiConnection.root, - 0, 0, width, height, 0, - XCB_WINDOW_CLASS_INPUT_OUTPUT, - m_pXcbScreen->root_visual, - value_mask, value_list); - - xcb_map_window(m_WsiConnection.pConnection, m_XcbWindow); - xcb_flush(m_WsiConnection.pConnection); - return 0; -#elif defined(WIN32) - // Register Window class - WNDCLASSEX wcex = {}; - wcex.cbSize = sizeof( WNDCLASSEX); - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = WindowProcXgl; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = GetModuleHandle(0); - wcex.hIcon = LoadIcon(wcex.hInstance, MAKEINTRESOURCE( IDI_ICON)); - wcex.hCursor = LoadCursor( NULL, IDC_ARROW); - wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1); - wcex.lpszMenuName = NULL; - wcex.lpszClassName = APP_NAME; - wcex.hIconSm = LoadIcon( wcex.hInstance, MAKEINTRESOURCE( IDI_ICON)); - if( !RegisterClassEx( &wcex)) - { - glv_LogError("Failed to register windows class\n"); - return -1; - } - - // create the window - m_windowHandle = CreateWindow(APP_NAME, APP_NAME, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, 0, 0, - width, height, NULL, NULL, wcex.hInstance, NULL); - - if (m_windowHandle) - { - ShowWindow( m_windowHandle, SW_SHOWDEFAULT); - m_windowWidth = width; - m_windowHeight = height; - } else { - glv_LogError("Failed to create window\n"); - return -1; - } - return 0; -#endif -} - -void xglDisplay::resize_window(const unsigned int width, const unsigned int height) -{ -#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) - if (width != m_windowWidth || height != m_windowHeight) - { - uint32_t values[2]; - values[0] = width; - values[1] = height; - xcb_configure_window(m_WsiConnection.pConnection, m_XcbWindow, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values); - m_windowWidth = width; - m_windowHeight = height; - } -#elif defined(WIN32) - if (width != m_windowWidth || height != m_windowHeight) - { - SetWindowPos(get_window_handle(), HWND_TOP, 0, 0, width, height, SWP_NOMOVE); - m_windowWidth = width; - m_windowHeight = height; - } -#endif -} - -void xglDisplay::process_event() -{ -} -xglReplay::xglReplay(glvreplay_settings *pReplaySettings) -{ - g_pReplaySettings = pReplaySettings; - m_display = new xglDisplay(); - m_pDSDump = NULL; - m_pCBDump = NULL; - m_pGlvSnapshotPrint = NULL; - if (g_pReplaySettings && g_pReplaySettings->screenshotList) { - process_screenshot_list(g_pReplaySettings->screenshotList); - } -} - -xglReplay::~xglReplay() -{ - delete m_display; - glv_platform_close_library(m_xglFuncs.m_libHandle); -} -int xglReplay::init(glv_replay::Display & disp) -{ - int err; -#if defined PLATFORM_LINUX - void * handle = dlopen("libXGL.so", RTLD_LAZY); -#else - HMODULE handle = LoadLibrary("xgl.dll" ); -#endif - if (handle == NULL) { - glv_LogError("Failed to open xgl library.\n"); - return -1; - } - m_xglFuncs.init_funcs(handle); - disp.set_implementation(m_display); - if ((err = m_display->init(disp.get_gpu())) != 0) { - glv_LogError("Failed to init XGL display.\n"); - return err; - } - if (disp.get_window_handle() == 0) - { - if ((err = m_display->create_window(disp.get_width(), disp.get_height())) != 0) { - glv_LogError("Failed to create Window\n"); - return err; - } - } - else - { - if ((err = m_display->set_window(disp.get_window_handle(), disp.get_width(), disp.get_height())) != 0) - { - glv_LogError("Failed to set Window\n"); - return err; - } - } - return 0; -} -glv_replay::GLV_REPLAY_RESULT xglReplay::handle_replay_errors(const char* entrypointName, const XGL_RESULT resCall, const XGL_RESULT resTrace, const glv_replay::GLV_REPLAY_RESULT resIn) -{ - glv_replay::GLV_REPLAY_RESULT res = resIn; - if (resCall != resTrace) { - glv_LogWarn("Mismatched return from API call (%s) traced result %s, replay result %s\n", entrypointName, - string_XGL_RESULT((XGL_RESULT)resTrace), string_XGL_RESULT((XGL_RESULT)resCall)); - res = glv_replay::GLV_REPLAY_BAD_RETURN; - } -#if 0 - if (resCall != XGL_SUCCESS) { - glv_LogWarn("API call (%s) returned failed result %s\n", entrypointName, string_XGL_RESULT(resCall)); - } -#endif - return res; -} -void xglReplay::push_validation_msg(XGL_VALIDATION_LEVEL validationLevel, XGL_BASE_OBJECT srcObject, size_t location, int32_t msgCode, const char * pMsg) -{ - struct validationMsg msgObj; - msgObj.validationLevel = validationLevel; - msgObj.srcObject = srcObject; - msgObj.location = location; - msgObj.msgCode = msgCode; - strncpy(msgObj.msg, pMsg, 256); - msgObj.msg[255] = '\0'; - m_validationMsgs.push_back(msgObj); -} - -glv_replay::GLV_REPLAY_RESULT xglReplay::pop_validation_msgs() -{ - if (m_validationMsgs.size() == 0) - return glv_replay::GLV_REPLAY_SUCCESS; - m_validationMsgs.clear(); - return glv_replay::GLV_REPLAY_VALIDATION_ERROR; -} -int xglReplay::dump_validation_data() -{ - if (m_pDSDump && m_pCBDump) - { - m_pDSDump((char *) "pipeline_dump.dot"); - m_pCBDump((char *) "cb_dump.dot"); - } - if (m_pGlvSnapshotPrint != NULL) { m_pGlvSnapshotPrint(); } - return 0; -} void xglFuncs::init_funcs(void * handle) { m_libHandle = handle; @@ -522,8 +178,6 @@ void xglFuncs::init_funcs(void * handle) real_xglWsiX11CreatePresentableImage = (type_xglWsiX11CreatePresentableImage)(glv_platform_get_library_entrypoint(handle, "xglWsiX11CreatePresentableImage")); real_xglWsiX11QueuePresent = (type_xglWsiX11QueuePresent)(glv_platform_get_library_entrypoint(handle, "xglWsiX11QueuePresent")); } -#define CHECK_RETURN_VALUE(entrypoint) returnValue = handle_replay_errors(#entrypoint, replayResult, pPacket->result, returnValue); - glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) { glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; @@ -561,123 +215,13 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglEnumerateGpus: { struct_xglEnumerateGpus* pPacket = (struct_xglEnumerateGpus*)(packet->pBody); - if (!m_display->m_initedXGL) - { - uint32_t gpuCount; - XGL_PHYSICAL_GPU gpus[XGL_MAX_PHYSICAL_GPUS]; - uint32_t maxGpus = (pPacket->maxGpus < XGL_MAX_PHYSICAL_GPUS) ? pPacket->maxGpus : XGL_MAX_PHYSICAL_GPUS; - replayResult = m_xglFuncs.real_xglEnumerateGpus(remap(pPacket->instance), maxGpus, &gpuCount, &gpus[0]); - CHECK_RETURN_VALUE(xglEnumerateGpus); - //TODO handle different number of gpus in trace versus replay - if (gpuCount != *(pPacket->pGpuCount)) - { - glv_LogWarn("number of gpus mismatched in replay %u versus trace %u\n", gpuCount, *(pPacket->pGpuCount)); - } - else if (gpuCount == 0) - { - glv_LogError("xglEnumerateGpus number of gpus is zero\n"); - } - else - { - glv_LogInfo("Enumerated %d GPUs in the system\n", gpuCount); - } - // TODO handle enumeration results in a different order from trace to replay - for (uint32_t i = 0; i < gpuCount; i++) - { - if (pPacket->pGpus) - add_to_map(&(pPacket->pGpus[i]), &(gpus[i])); - } - } + returnValue = manually_handle_xglEnumerateGpus(pPacket); break; } case GLV_TPI_XGL_xglGetGpuInfo: { struct_xglGetGpuInfo* pPacket = (struct_xglGetGpuInfo*)(packet->pBody); - if (!m_display->m_initedXGL) - { - switch (pPacket->infoType) { - case XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES: - { - XGL_PHYSICAL_GPU_PROPERTIES gpuProps; - size_t dataSize = sizeof(XGL_PHYSICAL_GPU_PROPERTIES); - replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &dataSize, - (pPacket->pData == NULL) ? NULL : &gpuProps); - if (pPacket->pData != NULL) - { - glv_LogInfo("Replay Gpu Properties\n"); - glv_LogInfo("Vendor ID %x, Device ID %x, name %s\n",gpuProps.vendorId, gpuProps.deviceId, gpuProps.gpuName); - glv_LogInfo("API version %u, Driver version %u, gpu Type %u\n",gpuProps.apiVersion, gpuProps.driverVersion, gpuProps.gpuType); - } - break; - } - case XGL_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE: - { - XGL_PHYSICAL_GPU_PERFORMANCE gpuPerfs; - size_t dataSize = sizeof(XGL_PHYSICAL_GPU_PERFORMANCE); - replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &dataSize, - (pPacket->pData == NULL) ? NULL : &gpuPerfs); - if (pPacket->pData != NULL) - { - glv_LogInfo("Replay Gpu Performance\n"); - glv_LogInfo("Max GPU clock %f, max shader ALUs/clock %f, max texel fetches/clock %f\n",gpuPerfs.maxGpuClock, gpuPerfs.aluPerClock, gpuPerfs.texPerClock); - glv_LogInfo("Max primitives/clock %f, Max pixels/clock %f\n",gpuPerfs.primsPerClock, gpuPerfs.pixelsPerClock); - } - break; - } - case XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES: - { - XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *pGpuQueue, *pQ; - size_t dataSize = sizeof(XGL_PHYSICAL_GPU_QUEUE_PROPERTIES); - size_t numQueues = 1; - assert(pPacket->pDataSize); - if ((*(pPacket->pDataSize) % dataSize) != 0) - glv_LogWarn("xglGetGpuInfo() for GPU_QUEUE_PROPERTIES not an integral data size assuming 1\n"); - else - numQueues = *(pPacket->pDataSize) / dataSize; - dataSize = numQueues * dataSize; - pQ = static_cast < XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *> (glv_malloc(dataSize)); - pGpuQueue = pQ; - replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &dataSize, - (pPacket->pData == NULL) ? NULL : pGpuQueue); - if (pPacket->pData != NULL) - { - for (unsigned int i = 0; i < numQueues; i++) - { - glv_LogInfo("Replay Gpu Queue Property for index %d, flags %u\n", i, pGpuQueue->queueFlags); - glv_LogInfo("Max available count %u, max atomic counters %u, supports timestamps %u\n",pGpuQueue->queueCount, pGpuQueue->maxAtomicCounters, pGpuQueue->supportsTimestamps); - pGpuQueue++; - } - } - glv_free(pQ); - break; - } - default: - { - size_t size = 0; - void* pData = NULL; - if (pPacket->pData != NULL && pPacket->pDataSize != NULL) - { - size = *pPacket->pDataSize; - pData = glv_malloc(*pPacket->pDataSize); - } - replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &size, pData); - if (replayResult == XGL_SUCCESS) - { - if (size != *pPacket->pDataSize && pData != NULL) - { - glv_LogWarn("xglGetGpuInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\n", size, *pPacket->pDataSize); - } - else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0) - { - glv_LogWarn("xglGetGpuInfo returned differing data contents than the trace file contained.\n"); - } - } - glv_free(pData); - break; - } - }; - CHECK_RETURN_VALUE(xglGetGpuInfo); - } + returnValue = manually_handle_xglGetGpuInfo(pPacket); break; } case GLV_TPI_XGL_xglGetProcAddr: @@ -689,53 +233,7 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglCreateDevice: { struct_xglCreateDevice* pPacket = (struct_xglCreateDevice*)(packet->pBody); - if (!m_display->m_initedXGL) - { - XGL_DEVICE device; - if (g_xglReplaySettings.debugLevel > 0) - { - XGL_DEVICE_CREATE_INFO cInfo, *ci, *pCreateInfoSaved; - unsigned int numLayers = 0; - char ** layersStr = get_enableLayers_list(&numLayers); - apply_layerSettings_overrides(); - XGL_LAYER_CREATE_INFO layerInfo; - pCreateInfoSaved = (XGL_DEVICE_CREATE_INFO *) pPacket->pCreateInfo; - ci = (XGL_DEVICE_CREATE_INFO *) pPacket->pCreateInfo; - if (layersStr != NULL && numLayers > 0) - { - while (ci->pNext != NULL) - ci = (XGL_DEVICE_CREATE_INFO *) ci->pNext; - ci->pNext = &layerInfo; - layerInfo.sType = XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO; - layerInfo.pNext = 0; - layerInfo.layerCount = numLayers; - layerInfo.ppActiveLayerNames = layersStr; - } - memcpy(&cInfo, pPacket->pCreateInfo, sizeof(XGL_DEVICE_CREATE_INFO)); - cInfo.flags = pPacket->pCreateInfo->flags | XGL_DEVICE_CREATE_VALIDATION_BIT; - cInfo.maxValidationLevel = (XGL_VALIDATION_LEVEL)((g_xglReplaySettings.debugLevel <= 4) ? (unsigned int) XGL_VALIDATION_LEVEL_0 + g_xglReplaySettings.debugLevel : (unsigned int) XGL_VALIDATION_LEVEL_0); - pPacket->pCreateInfo = &cInfo; - replayResult = m_xglFuncs.real_xglCreateDevice(remap(pPacket->gpu), pPacket->pCreateInfo, &device); - // restore the packet for next replay - ci->pNext = NULL; - pPacket->pCreateInfo = pCreateInfoSaved; - release_enableLayer_list(layersStr); - if (xglDbgRegisterMsgCallback(g_fpDbgMsgCallback, NULL) != XGL_SUCCESS) - glv_LogError("Failed to register xgl callback for replayer error handling\n"); -#if !defined(_WIN32) - m_pDSDump = (DRAW_STATE_DUMP_DOT_FILE) m_xglFuncs.real_xglGetProcAddr(remap(pPacket->gpu), "drawStateDumpDotFile"); - m_pCBDump = (DRAW_STATE_DUMP_COMMAND_BUFFER_DOT_FILE) m_xglFuncs.real_xglGetProcAddr(remap(pPacket->gpu), "drawStateDumpCommandBufferDotFile"); - m_pGlvSnapshotPrint = (GLVSNAPSHOT_PRINT_OBJECTS) m_xglFuncs.real_xglGetProcAddr(remap(pPacket->gpu), "glvSnapshotPrintObjects"); -#endif - } - else - replayResult = m_xglFuncs.real_xglCreateDevice(remap(pPacket->gpu), pPacket->pCreateInfo, &device); - CHECK_RETURN_VALUE(xglCreateDevice); - if (replayResult == XGL_SUCCESS) - { - add_to_map(pPacket->pDevice, &device); - } - } + returnValue = manually_handle_xglCreateDevice(pPacket); break; } case GLV_TPI_XGL_xglDestroyDevice: @@ -756,26 +254,7 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglGetExtensionSupport: { struct_xglGetExtensionSupport* pPacket = (struct_xglGetExtensionSupport*)(packet->pBody); - if (!m_display->m_initedXGL) { - replayResult = m_xglFuncs.real_xglGetExtensionSupport(remap(pPacket->gpu), pPacket->pExtName); - CHECK_RETURN_VALUE(xglGetExtensionSupport); - if (replayResult == XGL_SUCCESS) { - for (unsigned int ext = 0; ext < sizeof(g_extensions) / sizeof(g_extensions[0]); ext++) - { - if (!strncmp(g_extensions[ext], pPacket->pExtName, strlen(g_extensions[ext]))) { - bool extInList = false; - for (unsigned int j = 0; j < m_display->m_extensions.size(); ++j) { - if (!strncmp(m_display->m_extensions[j], g_extensions[ext], strlen(g_extensions[ext]))) - extInList = true; - break; - } - if (!extInList) - m_display->m_extensions.push_back((char *) g_extensions[ext]); - break; - } - } - } - } + returnValue = manually_handle_xglGetExtensionSupport(pPacket); break; } case GLV_TPI_XGL_xglEnumerateLayers: @@ -806,30 +285,7 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglQueueSubmit: { struct_xglQueueSubmit* pPacket = (struct_xglQueueSubmit*)(packet->pBody); - XGL_CMD_BUFFER *remappedBuffers = NULL; - if (pPacket->pCmdBuffers != NULL) - { - remappedBuffers = GLV_NEW_ARRAY( XGL_CMD_BUFFER, pPacket->cmdBufferCount); - for (uint32_t i = 0; i < pPacket->cmdBufferCount; i++) - { - *(remappedBuffers + i) = remap(*(pPacket->pCmdBuffers + i)); - } - } - XGL_MEMORY_REF* memRefs = NULL; - if (pPacket->pMemRefs != NULL) - { - memRefs = GLV_NEW_ARRAY(XGL_MEMORY_REF, pPacket->memRefCount); - memcpy(memRefs, pPacket->pMemRefs, sizeof(XGL_MEMORY_REF) * pPacket->memRefCount); - for (uint32_t i = 0; i < pPacket->memRefCount; i++) - { - memRefs[i].mem = remap(pPacket->pMemRefs[i].mem); - } - } - replayResult = m_xglFuncs.real_xglQueueSubmit(remap(pPacket->queue), pPacket->cmdBufferCount, remappedBuffers, pPacket->memRefCount, - memRefs, remap(pPacket->fence)); - GLV_DELETE(remappedBuffers); - GLV_DELETE(memRefs); - CHECK_RETURN_VALUE(xglQueueSubmit); + returnValue = manually_handle_xglQueueSubmit(pPacket); break; } case GLV_TPI_XGL_xglQueueSetGlobalMemReferences: @@ -869,14 +325,7 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglFreeMemory: { struct_xglFreeMemory* pPacket = (struct_xglFreeMemory*)(packet->pBody); - XGL_GPU_MEMORY handle = remap(pPacket->mem); - replayResult = m_xglFuncs.real_xglFreeMemory(handle); - if (replayResult == XGL_SUCCESS) - { - rm_entry_from_mapData(handle); - rm_from_map(pPacket->mem); - } - CHECK_RETURN_VALUE(xglFreeMemory); + returnValue = manually_handle_xglFreeMemory(pPacket); break; } case GLV_TPI_XGL_xglSetMemoryPriority: @@ -889,21 +338,13 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglMapMemory: { struct_xglMapMemory* pPacket = (struct_xglMapMemory*)(packet->pBody); - XGL_GPU_MEMORY handle = remap(pPacket->mem); - void* pData; - replayResult = m_xglFuncs.real_xglMapMemory(handle, pPacket->flags, &pData); - if (replayResult == XGL_SUCCESS) - add_mapping_to_mapData(handle, pData); - CHECK_RETURN_VALUE(xglMapMemory); + returnValue = manually_handle_xglMapMemory(pPacket); break; } case GLV_TPI_XGL_xglUnmapMemory: { struct_xglUnmapMemory* pPacket = (struct_xglUnmapMemory*)(packet->pBody); - XGL_GPU_MEMORY handle = remap(pPacket->mem); - rm_mapping_from_mapData(handle, pPacket->pData); // copies data from packet into memory buffer - replayResult = m_xglFuncs.real_xglUnmapMemory(handle); - CHECK_RETURN_VALUE(xglUnmapMemory); + returnValue = manually_handle_xglUnmapMemory(pPacket); break; } case GLV_TPI_XGL_xglPinSystemMemory: @@ -921,12 +362,7 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglGetMultiGpuCompatibility: { struct_xglGetMultiGpuCompatibility* pPacket = (struct_xglGetMultiGpuCompatibility*)(packet->pBody); - XGL_GPU_COMPATIBILITY_INFO cInfo; - XGL_PHYSICAL_GPU handle0, handle1; - handle0 = remap(pPacket->gpu0); - handle1 = remap(pPacket->gpu1); - replayResult = m_xglFuncs.real_xglGetMultiGpuCompatibility(handle0, handle1, &cInfo); - CHECK_RETURN_VALUE(xglGetMultiGpuCompatibility); + returnValue = manually_handle_xglGetMultiGpuCompatibility(pPacket); break; } case GLV_TPI_XGL_xglOpenSharedMemory: @@ -973,39 +409,13 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglDestroyObject: { struct_xglDestroyObject* pPacket = (struct_xglDestroyObject*)(packet->pBody); - XGL_OBJECT object = remap(pPacket->object); - if (object != XGL_NULL_HANDLE) - replayResult = m_xglFuncs.real_xglDestroyObject(object); - if (replayResult == XGL_SUCCESS) - rm_from_map(pPacket->object); - CHECK_RETURN_VALUE(xglDestroyObject); + returnValue = manually_handle_xglDestroyObject(pPacket); break; } case GLV_TPI_XGL_xglGetObjectInfo: { struct_xglGetObjectInfo* pPacket = (struct_xglGetObjectInfo*)(packet->pBody); - size_t size = 0; - void* pData = NULL; - if (pPacket->pData != NULL && pPacket->pDataSize != NULL) - { - size = *pPacket->pDataSize; - pData = glv_malloc(*pPacket->pDataSize); - memcpy(pData, pPacket->pData, *pPacket->pDataSize); - } - replayResult = m_xglFuncs.real_xglGetObjectInfo(remap(pPacket->object), pPacket->infoType, &size, pData); - if (replayResult == XGL_SUCCESS) - { - if (size != *pPacket->pDataSize && pData != NULL) - { - glv_LogWarn("xglGetObjectInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\n", size, *pPacket->pDataSize); - } - else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0) - { - glv_LogWarn("xglGetObjectInfo returned differing data contents than the trace file contained.\n"); - } - } - glv_free(pData); - CHECK_RETURN_VALUE(xglGetObjectInfo); + returnValue = manually_handle_xglGetObjectInfo(pPacket); break; } case GLV_TPI_XGL_xglBindObjectMemory: @@ -1054,14 +464,7 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglWaitForFences: { struct_xglWaitForFences* pPacket = (struct_xglWaitForFences*)(packet->pBody); - XGL_FENCE *pFence = GLV_NEW_ARRAY(XGL_FENCE, pPacket->fenceCount); - for (uint32_t i = 0; i < pPacket->fenceCount; i++) - { - *(pFence + i) = remap(*(pPacket->pFences + i)); - } - replayResult = m_xglFuncs.real_xglWaitForFences(remap(pPacket->device), pPacket->fenceCount, pFence, pPacket->waitAll, pPacket->timeout); - GLV_DELETE(pFence); - CHECK_RETURN_VALUE(xglWaitForFences); + returnValue = manually_handle_xglWaitForFences(pPacket); break; } case GLV_TPI_XGL_xglCreateQueueSemaphore: @@ -1148,27 +551,7 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglGetFormatInfo: { struct_xglGetFormatInfo* pPacket = (struct_xglGetFormatInfo*)(packet->pBody); - size_t size = 0; - void* pData = NULL; - if (pPacket->pData != NULL && pPacket->pDataSize != NULL) - { - size = *pPacket->pDataSize; - pData = glv_malloc(*pPacket->pDataSize); - } - replayResult = m_xglFuncs.real_xglGetFormatInfo(remap(pPacket->device), pPacket->format, pPacket->infoType, &size, pData); - if (replayResult == XGL_SUCCESS) - { - if (size != *pPacket->pDataSize && pData != NULL) - { - glv_LogWarn("xglGetFormatInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\n", size, *pPacket->pDataSize); - } - else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0) - { - glv_LogWarn("xglGetFormatInfo returned differing data contents than the trace file contained.\n"); - } - } - glv_free(pData); - CHECK_RETURN_VALUE(xglGetFormatInfo); + returnValue = manually_handle_xglGetFormatInfo(pPacket); break; } case GLV_TPI_XGL_xglCreateBuffer: @@ -1227,27 +610,7 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglGetImageSubresourceInfo: { struct_xglGetImageSubresourceInfo* pPacket = (struct_xglGetImageSubresourceInfo*)(packet->pBody); - size_t size = 0; - void* pData = NULL; - if (pPacket->pData != NULL && pPacket->pDataSize != NULL) - { - size = *pPacket->pDataSize; - pData = glv_malloc(*pPacket->pDataSize); - } - replayResult = m_xglFuncs.real_xglGetImageSubresourceInfo(remap(pPacket->image), pPacket->pSubresource, pPacket->infoType, &size, pData); - if (replayResult == XGL_SUCCESS) - { - if (size != *pPacket->pDataSize && pData != NULL) - { - glv_LogWarn("xglGetImageSubresourceInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\n", size, *pPacket->pDataSize); - } - else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0) - { - glv_LogWarn("xglGetImageSubresourceInfo returned differing data contents than the trace file contained.\n"); - } - } - glv_free(pData); - CHECK_RETURN_VALUE(xglGetImageSubresourceInfo); + returnValue = manually_handle_xglGetImageSubresourceInfo(pPacket); break; } case GLV_TPI_XGL_xglCreateImageView: @@ -1310,34 +673,7 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglCreateGraphicsPipeline: { struct_xglCreateGraphicsPipeline* pPacket = (struct_xglCreateGraphicsPipeline*)(packet->pBody); - XGL_GRAPHICS_PIPELINE_CREATE_INFO createInfo; - struct shaderPair saveShader[10]; - unsigned int idx = 0; - memcpy(&createInfo, pPacket->pCreateInfo, sizeof(XGL_GRAPHICS_PIPELINE_CREATE_INFO)); - createInfo.lastSetLayout = remap(createInfo.lastSetLayout); - // Cast to shader type, as those are of primariy interest and all structs in LL have same header w/ sType & pNext - XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pPacketNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pPacket->pCreateInfo->pNext; - XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)createInfo.pNext; - while (XGL_NULL_HANDLE != pPacketNext) - { - if (XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO == pNext->sType) - { - saveShader[idx].val = pNext->shader.shader; - saveShader[idx++].addr = &(pNext->shader.shader); - pNext->shader.shader = remap(pPacketNext->shader.shader); - } - pPacketNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pPacketNext->pNext; - pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pNext->pNext; - } - XGL_PIPELINE pipeline; - replayResult = m_xglFuncs.real_xglCreateGraphicsPipeline(remap(pPacket->device), &createInfo, &pipeline); - if (replayResult == XGL_SUCCESS) - { - add_to_map(pPacket->pPipeline, &pipeline); - } - for (unsigned int i = 0; i < idx; i++) - *(saveShader[i].addr) = saveShader[i].val; - CHECK_RETURN_VALUE(xglCreateGraphicsPipeline); + returnValue = manually_handle_xglCreateGraphicsPipeline(pPacket); break; } case GLV_TPI_XGL_xglCreateComputePipeline: @@ -1358,27 +694,7 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglStorePipeline: { struct_xglStorePipeline* pPacket = (struct_xglStorePipeline*)(packet->pBody); - size_t size = 0; - void* pData = NULL; - if (pPacket->pData != NULL && pPacket->pDataSize != NULL) - { - size = *pPacket->pDataSize; - pData = glv_malloc(*pPacket->pDataSize); - } - replayResult = m_xglFuncs.real_xglStorePipeline(remap(pPacket->pipeline), &size, pData); - if (replayResult == XGL_SUCCESS) - { - if (size != *pPacket->pDataSize && pData != NULL) - { - glv_LogWarn("xglStorePipeline returned a differing data size: replay (%d bytes) vs trace (%d bytes)\n", size, *pPacket->pDataSize); - } - else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0) - { - glv_LogWarn("xglStorePipeline returned differing data contents than the trace file contained.\n"); - } - } - glv_free(pData); - CHECK_RETURN_VALUE(xglStorePipeline); + returnValue = manually_handle_xglStorePipeline(pPacket); break; } case GLV_TPI_XGL_xglLoadPipeline: @@ -1420,23 +736,7 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglCreateDescriptorSetLayout: { struct_xglCreateDescriptorSetLayout* pPacket = (struct_xglCreateDescriptorSetLayout*)(packet->pBody); - XGL_SAMPLER saveSampler; - if (pPacket->pSetLayoutInfoList != NULL) { - XGL_SAMPLER *pSampler = (XGL_SAMPLER *) &pPacket->pSetLayoutInfoList->immutableSampler; - saveSampler = pPacket->pSetLayoutInfoList->immutableSampler; - *pSampler = remap(saveSampler); - } - XGL_DESCRIPTOR_SET_LAYOUT setLayout; - replayResult = m_xglFuncs.real_xglCreateDescriptorSetLayout(remap(pPacket->device), pPacket->stageFlags, pPacket->pSetBindPoints, remap(pPacket->priorSetLayout), pPacket->pSetLayoutInfoList, &setLayout); - if (replayResult == XGL_SUCCESS) - { - add_to_map(pPacket->pSetLayout, &setLayout); - } - if (pPacket->pSetLayoutInfoList != NULL) { - XGL_SAMPLER *pSampler = (XGL_SAMPLER *) &pPacket->pSetLayoutInfoList->immutableSampler; - *pSampler = saveSampler; - } - CHECK_RETURN_VALUE(xglCreateDescriptorSetLayout); + returnValue = manually_handle_xglCreateDescriptorSetLayout(pPacket); break; } case GLV_TPI_XGL_xglBeginDescriptorRegionUpdate: @@ -1508,122 +808,7 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglUpdateDescriptors: { struct_xglUpdateDescriptors* pPacket = (struct_xglUpdateDescriptors*)(packet->pBody); - XGL_UPDATE_SAMPLERS* pUpdateChain = (XGL_UPDATE_SAMPLERS*)pPacket->pUpdateChain; - std::queue saveSamplers; - std::queue saveBufferViews; - std::queue saveImageViews; - std::queue saveDescSets; - while (pUpdateChain) { - switch(pUpdateChain->sType) - { - case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS: - for (uint32_t i = 0; i < ((XGL_UPDATE_SAMPLERS*)pUpdateChain)->count; i++) { - XGL_SAMPLER* pLocalSampler = (XGL_SAMPLER*) &((XGL_UPDATE_SAMPLERS*)pUpdateChain)->pSamplers[i]; - saveSamplers.push(*pLocalSampler); - *pLocalSampler = remap(((XGL_UPDATE_SAMPLERS*)pUpdateChain)->pSamplers[i]); - } - break; - case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES: - { - XGL_UPDATE_SAMPLER_TEXTURES *pUST = (XGL_UPDATE_SAMPLER_TEXTURES *) pUpdateChain; - for (uint32_t i = 0; i < pUST->count; i++) { - XGL_SAMPLER *pLocalSampler = (XGL_SAMPLER *) &pUST->pSamplerImageViews[i].pSampler; - saveSamplers.push(*pLocalSampler); - *pLocalSampler = remap(pUST->pSamplerImageViews[i].pSampler); - XGL_IMAGE_VIEW *pLocalView = (XGL_IMAGE_VIEW *) &pUST->pSamplerImageViews[i].pImageView->view; - saveImageViews.push(*pLocalView); - *pLocalView = remap(pUST->pSamplerImageViews[i].pImageView->view); - } - break; - } - case XGL_STRUCTURE_TYPE_UPDATE_IMAGES: - { - XGL_UPDATE_IMAGES *pUI = (XGL_UPDATE_IMAGES*) pUpdateChain; - for (uint32_t i = 0; i < pUI->count; i++) { - XGL_IMAGE_VIEW* pLocalView = (XGL_IMAGE_VIEW*) &pUI->pImageViews[i]->view; - saveImageViews.push(*pLocalView); - *pLocalView = remap(pUI->pImageViews[i]->view); - } - break; - } - case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS: - { - XGL_UPDATE_BUFFERS *pUB = (XGL_UPDATE_BUFFERS *) pUpdateChain; - for (uint32_t i = 0; i < pUB->count; i++) { - XGL_BUFFER_VIEW* pLocalView = (XGL_BUFFER_VIEW*) &pUB->pBufferViews[i]->view; - saveBufferViews.push(*pLocalView); - *pLocalView = remap(pUB->pBufferViews[i]->view); - } - break; - } - case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY: - saveDescSets.push(((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet); - ((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet = remap(((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet); - break; - default: - assert(0); - break; - } - pUpdateChain = (XGL_UPDATE_SAMPLERS*) pUpdateChain->pNext; - } - m_xglFuncs.real_xglUpdateDescriptors(remap(pPacket->descriptorSet), pPacket->pUpdateChain); - pUpdateChain = (XGL_UPDATE_SAMPLERS*) pPacket->pUpdateChain; - while (pUpdateChain) { - switch(pUpdateChain->sType) - { - case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS: - for (uint32_t i = 0; i < ((XGL_UPDATE_SAMPLERS*)pUpdateChain)->count; i++) { - XGL_SAMPLER* pLocalSampler = (XGL_SAMPLER*) &((XGL_UPDATE_SAMPLERS*)pUpdateChain)->pSamplers[i]; - *pLocalSampler = saveSamplers.front(); - saveSamplers.pop(); - } - break; - case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES: - { - XGL_UPDATE_SAMPLER_TEXTURES *pUST = (XGL_UPDATE_SAMPLER_TEXTURES *) pUpdateChain; - for (uint32_t i = 0; i < pUST->count; i++) { - XGL_SAMPLER *plocalSampler = (XGL_SAMPLER *) &pUST->pSamplerImageViews[i].pSampler; - *plocalSampler = saveSamplers.front(); - saveSamplers.pop(); - XGL_IMAGE_VIEW *pLocalView = (XGL_IMAGE_VIEW *) &pUST->pSamplerImageViews[i].pImageView->view; - *pLocalView = saveImageViews.front(); - saveImageViews.pop(); - } - break; - } - case XGL_STRUCTURE_TYPE_UPDATE_IMAGES: - { - XGL_UPDATE_IMAGES *pUI = (XGL_UPDATE_IMAGES*) pUpdateChain; - for (uint32_t i = 0; i < pUI->count; i++) { - XGL_IMAGE_VIEW* pLocalView = (XGL_IMAGE_VIEW*) &pUI->pImageViews[i]->view; - *pLocalView = saveImageViews.front(); - saveImageViews.pop(); - } - break; - } - case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS: - { - XGL_UPDATE_BUFFERS *pUB = (XGL_UPDATE_BUFFERS *) pUpdateChain; - for (uint32_t i = 0; i < pUB->count; i++) { - XGL_BUFFER_VIEW* pLocalView = (XGL_BUFFER_VIEW*) &pUB->pBufferViews[i]->view; - *pLocalView = saveBufferViews.front(); - saveBufferViews.pop(); - } - break; - } - case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY: - ((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet = saveDescSets.front(); - saveDescSets.pop(); - //pFreeMe = (XGL_UPDATE_SAMPLERS*)pLocalUpdateChain; - //pLocalUpdateChain = (void*)((XGL_UPDATE_SAMPLERS*)pLocalUpdateChain)->pNext; - //free(pFreeMe); - break; - default: - assert(0); - break; - } - pUpdateChain = (XGL_UPDATE_SAMPLERS*) pUpdateChain->pNext; - } + returnValue = manually_handle_xglUpdateDescriptors(pPacket); break; } case GLV_TPI_XGL_xglCreateDynamicViewportState: @@ -1689,27 +874,7 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglBeginCommandBuffer: { struct_xglBeginCommandBuffer* pPacket = (struct_xglBeginCommandBuffer*)(packet->pBody); - XGL_CMD_BUFFER_BEGIN_INFO* pInfo = (XGL_CMD_BUFFER_BEGIN_INFO*)pPacket->pBeginInfo; - // assume only zero or one graphics_begin_info in the chain - XGL_RENDER_PASS savedRP, *pRP; - XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO *pGInfo = NULL; - while (pInfo != NULL) - { - - if (pInfo->sType == XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO) - { - pGInfo = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO *) pInfo; - savedRP = pGInfo->renderPass; - pRP = &(pGInfo->renderPass); - *pRP = remap(pGInfo->renderPass); - break; - } - pInfo = (XGL_CMD_BUFFER_BEGIN_INFO*) pInfo->pNext; - } - replayResult = m_xglFuncs.real_xglBeginCommandBuffer(remap(pPacket->cmdBuffer), pPacket->pBeginInfo); - if (pGInfo != NULL) - pGInfo->renderPass = savedRP; - CHECK_RETURN_VALUE(xglBeginCommandBuffer); + returnValue = manually_handle_xglBeginCommandBuffer(pPacket); break; } case GLV_TPI_XGL_xglEndCommandBuffer: @@ -1879,84 +1044,13 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglCmdWaitEvents: { struct_xglCmdWaitEvents* pPacket = (struct_xglCmdWaitEvents*)(packet->pBody); - XGL_EVENT saveEvent[100]; - uint32_t idx, numRemapBuf=0, numRemapImg=0; - assert(pPacket->pWaitInfo && pPacket->pWaitInfo->eventCount <= 100); - for (idx = 0; idx < pPacket->pWaitInfo->eventCount; idx++) - { - XGL_EVENT *pEvent = (XGL_EVENT *) &(pPacket->pWaitInfo->pEvents[idx]); - saveEvent[idx] = pPacket->pWaitInfo->pEvents[idx]; - *pEvent = remap(pPacket->pWaitInfo->pEvents[idx]); - } - - XGL_BUFFER saveBuf[100]; - XGL_IMAGE saveImg[100]; - for (idx = 0; idx < pPacket->pWaitInfo->memBarrierCount; idx++) - { - XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx]; - assert(pNext); - if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) { - XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx]; - assert(numRemapBuf < 100); - saveBuf[numRemapBuf++] = pNextBuf->buffer; - pNextBuf->buffer = remap(pNextBuf->buffer); - } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) { - XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx]; - assert(numRemapImg < 100); - saveImg[numRemapImg++] = pNextImg->image; - pNextImg->image = remap(pNextImg->image); - } - } - m_xglFuncs.real_xglCmdWaitEvents(remap(pPacket->cmdBuffer), pPacket->pWaitInfo); - for (idx = 0; idx < pPacket->pWaitInfo->memBarrierCount; idx++) { - XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx]; - if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) { - XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx]; - pNextBuf->buffer = saveBuf[idx]; - } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) { - XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx]; - pNextImg->image = saveImg[idx]; - } - } - for (idx = 0; idx < pPacket->pWaitInfo->eventCount; idx++) { - XGL_EVENT *pEvent = (XGL_EVENT *) &(pPacket->pWaitInfo->pEvents[idx]); - *pEvent = saveEvent[idx]; - } + returnValue = manually_handle_xglCmdWaitEvents(pPacket); break; } case GLV_TPI_XGL_xglCmdPipelineBarrier: { struct_xglCmdPipelineBarrier* pPacket = (struct_xglCmdPipelineBarrier*)(packet->pBody); - uint32_t idx, numRemapBuf=0, numRemapImg=0; - XGL_BUFFER saveBuf[100]; - XGL_IMAGE saveImg[100]; - for (idx = 0; idx < pPacket->pBarrier->memBarrierCount; idx++) - { - XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx]; - assert(pNext); - if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) { - XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx]; - assert(numRemapBuf < 100); - saveBuf[numRemapBuf++] = pNextBuf->buffer; - pNextBuf->buffer = remap(pNextBuf->buffer); - } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) { - XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx]; - assert(numRemapImg < 100); - saveImg[numRemapImg++] = pNextImg->image; - pNextImg->image = remap(pNextImg->image); - } - } - m_xglFuncs.real_xglCmdPipelineBarrier(remap(pPacket->cmdBuffer), pPacket->pBarrier); - for (idx = 0; idx < pPacket->pBarrier->memBarrierCount; idx++) { - XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx]; - if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) { - XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx]; - pNextBuf->buffer = saveBuf[idx]; - } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) { - XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx]; - pNextImg->image = saveImg[idx]; - } - } + returnValue = manually_handle_xglCmdPipelineBarrier(pPacket); break; } case GLV_TPI_XGL_xglCmdBeginQuery: @@ -2004,64 +1098,13 @@ glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet) case GLV_TPI_XGL_xglCreateFramebuffer: { struct_xglCreateFramebuffer* pPacket = (struct_xglCreateFramebuffer*)(packet->pBody); - XGL_FRAMEBUFFER_CREATE_INFO *pInfo = (XGL_FRAMEBUFFER_CREATE_INFO *) pPacket->pCreateInfo; - XGL_COLOR_ATTACHMENT_BIND_INFO *pColorAttachments, *pSavedColor = (XGL_COLOR_ATTACHMENT_BIND_INFO*)pInfo->pColorAttachments; - bool allocatedColorAttachments = false; - if (pSavedColor != NULL) - { - allocatedColorAttachments = true; - pColorAttachments = GLV_NEW_ARRAY(XGL_COLOR_ATTACHMENT_BIND_INFO, pInfo->colorAttachmentCount); - memcpy(pColorAttachments, pSavedColor, sizeof(XGL_COLOR_ATTACHMENT_BIND_INFO) * pInfo->colorAttachmentCount); - for (uint32_t i = 0; i < pInfo->colorAttachmentCount; i++) - { - pColorAttachments[i].view = remap(pInfo->pColorAttachments[i].view); - } - pInfo->pColorAttachments = pColorAttachments; - } - // remap depth stencil target - const XGL_DEPTH_STENCIL_BIND_INFO *pSavedDS = pInfo->pDepthStencilAttachment; - XGL_DEPTH_STENCIL_BIND_INFO depthTarget; - if (pSavedDS != NULL) - { - memcpy(&depthTarget, pSavedDS, sizeof(XGL_DEPTH_STENCIL_BIND_INFO)); - depthTarget.view = remap(pSavedDS->view); - pInfo->pDepthStencilAttachment = &depthTarget; - } - XGL_FRAMEBUFFER local_framebuffer; - replayResult = m_xglFuncs.real_xglCreateFramebuffer(remap(pPacket->device), pPacket->pCreateInfo, &local_framebuffer); - pInfo->pColorAttachments = pSavedColor; - pInfo->pDepthStencilAttachment = pSavedDS; - if (replayResult == XGL_SUCCESS) - { - add_to_map(pPacket->pFramebuffer, &local_framebuffer); - } - if (allocatedColorAttachments) - { - GLV_DELETE((void*)pColorAttachments); - } - CHECK_RETURN_VALUE(xglCreateFramebuffer); + returnValue = manually_handle_xglCreateFramebuffer(pPacket); break; } case GLV_TPI_XGL_xglCreateRenderPass: { struct_xglCreateRenderPass* pPacket = (struct_xglCreateRenderPass*)(packet->pBody); - XGL_RENDER_PASS_CREATE_INFO *pInfo = (XGL_RENDER_PASS_CREATE_INFO *) pPacket->pCreateInfo; - // remap framebuffer - XGL_FRAMEBUFFER savedFB = 0, *pFB = &(pInfo->framebuffer); - if (*pFB != NULL) - { - savedFB = pInfo->framebuffer; - *pFB = remap(pInfo->framebuffer); - } - XGL_RENDER_PASS local_renderpass; - replayResult = m_xglFuncs.real_xglCreateRenderPass(remap(pPacket->device), pPacket->pCreateInfo, &local_renderpass); - if (*pFB != NULL) - pInfo->framebuffer = savedFB; - if (replayResult == XGL_SUCCESS) - { - add_to_map(pPacket->pRenderPass, &local_renderpass); - } - CHECK_RETURN_VALUE(xglCreateRenderPass); + returnValue = manually_handle_xglCreateRenderPass(pPacket); break; } case GLV_TPI_XGL_xglCmdBeginRenderPass: diff --git a/tools/glave/src/glv_extensions/glvreplay_xgl/glvreplay_xgl_xgldisplay.cpp b/tools/glave/src/glv_extensions/glvreplay_xgl/glvreplay_xgl_xgldisplay.cpp new file mode 100644 index 0000000..4ff95f8 --- /dev/null +++ b/tools/glave/src/glv_extensions/glvreplay_xgl/glvreplay_xgl_xgldisplay.cpp @@ -0,0 +1,269 @@ +/* + * Vulkan + * + * Copyright (C) 2014 LunarG, Inc. + * Copyright (C) 2015 Valve Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "glvreplay_xgl_replay.h" + +xglDisplay::xglDisplay() + : m_initedXGL(false), + m_windowWidth(0), + m_windowHeight(0) +{ +#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) + m_WsiConnection.pConnection = NULL; + m_WsiConnection.root = 0; + m_WsiConnection.provider = 0; + m_pXcbScreen = NULL; + m_XcbWindow = 0; +#elif defined(WIN32) + m_windowHandle = NULL; +#endif +} + +xglDisplay::~xglDisplay() +{ +#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) + if (m_XcbWindow != 0) + { + xcb_destroy_window(m_WsiConnection.pConnection, m_XcbWindow); + } + if (m_WsiConnection.pConnection != NULL) + { + xcb_disconnect(m_WsiConnection.pConnection); + } +#endif +} + +XGL_RESULT xglDisplay::init_xgl(unsigned int gpu_idx) +{ +#if 0 + XGL_APPLICATION_INFO appInfo = {}; + appInfo.pAppName = APP_NAME; + appInfo.pEngineName = ""; + appInfo.apiVersion = XGL_API_VERSION; + XGL_RESULT res = xglInitAndEnumerateGpus(&appInfo, NULL, XGL_MAX_PHYSICAL_GPUS, &m_gpuCount, m_gpus); + if ( res == XGL_SUCCESS ) { + // retrieve the GPU information for all GPUs + for( uint32_t gpu = 0; gpu < m_gpuCount; gpu++) + { + size_t gpuInfoSize = sizeof(m_gpuProps[0]); + + // get the GPU physical properties: + res = xglGetGpuInfo( m_gpus[gpu], XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES, &gpuInfoSize, &m_gpuProps[gpu]); + if (res != XGL_SUCCESS) + glv_LogWarn("Failed to retrieve properties for gpu[%d] result %d\n", gpu, res); + } + res = XGL_SUCCESS; + } else if ((gpu_idx + 1) > m_gpuCount) { + glv_LogError("xglInitAndEnumerate number of gpus does not include requested index: num %d, requested %d\n", m_gpuCount, gpu_idx); + return -1; + } else { + glv_LogError("xglInitAndEnumerate failed\n"); + return res; + } + // TODO add multi-gpu support always use gpu[gpu_idx] for now + // get all extensions supported by this device gpu[gpu_idx] + // first check if extensions are available and save a list of them + bool foundWSIExt = false; + for( int ext = 0; ext < sizeof( extensions ) / sizeof( extensions[0] ); ext++) + { + res = xglGetExtensionSupport( m_gpus[gpu_idx], extensions[ext] ); + if (res == XGL_SUCCESS) { + m_extensions.push_back((char *) extensions[ext]); + if (!strcmp(extensions[ext], "XGL_WSI_WINDOWS")) + foundWSIExt = true; + } + } + if (!foundWSIExt) { + glv_LogError("XGL_WSI_WINDOWS extension not supported by gpu[%d]\n", gpu_idx); + return XGL_ERROR_INCOMPATIBLE_DEVICE; + } + // TODO generalize this: use one universal queue for now + XGL_DEVICE_QUEUE_CREATE_INFO dqci = {}; + dqci.queueCount = 1; + dqci.queueType = XGL_QUEUE_UNIVERSAL; + // create the device enabling validation level 4 + const char * const * extNames = &m_extensions[0]; + XGL_DEVICE_CREATE_INFO info = {}; + info.queueRecordCount = 1; + info.pRequestedQueues = &dqci; + info.extensionCount = static_cast (m_extensions.size()); + info.ppEnabledExtensionNames = extNames; + info.flags = XGL_DEVICE_CREATE_VALIDATION; + info.maxValidationLevel = XGL_VALIDATION_LEVEL_4; + bool32_t xglTrue = XGL_TRUE; + res = xglDbgSetGlobalOption( XGL_DBG_OPTION_BREAK_ON_ERROR, sizeof( xglTrue ), &xglTrue ); + if (res != XGL_SUCCESS) + glv_LogWarn("Could not set debug option break on error\n"); + res = xglCreateDevice( m_gpus[0], &info, &m_dev[gpu_idx]); + return res; +#else + return XGL_ERROR_INITIALIZATION_FAILED; +#endif +} + +int xglDisplay::init(const unsigned int gpu_idx) +{ + //m_gpuIdx = gpu_idx; +#if 0 + XGL_RESULT result = init_xgl(gpu_idx); + if (result != XGL_SUCCESS) { + glv_LogError("could not init xgl library"); + return -1; + } else { + m_initedXGL = true; + } +#endif +#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) + const xcb_setup_t *setup; + xcb_screen_iterator_t iter; + int scr; + xcb_connection_t *pConnection; + pConnection = xcb_connect(NULL, &scr); + setup = xcb_get_setup(pConnection); + iter = xcb_setup_roots_iterator(setup); + while (scr-- > 0) + xcb_screen_next(&iter); + m_pXcbScreen = iter.data; + m_WsiConnection.pConnection = pConnection; + m_WsiConnection.root = m_pXcbScreen->root; +#endif + return 0; +} + +#if defined(WIN32) +LRESULT WINAPI WindowProcXgl( HWND window, unsigned int msg, WPARAM wp, LPARAM lp) +{ + switch(msg) + { + case WM_CLOSE: + DestroyWindow( window); + // fall-thru + case WM_DESTROY: + PostQuitMessage(0) ; + return 0L ; + default: + return DefWindowProc( window, msg, wp, lp ) ; + } +} +#endif + +int xglDisplay::set_window(glv_window_handle hWindow, unsigned int width, unsigned int height) +{ +#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) + m_XcbWindow = hWindow; +#elif defined(WIN32) + m_windowHandle = hWindow; +#endif + m_windowWidth = width; + m_windowHeight = height; + return 0; +} + +int xglDisplay::create_window(const unsigned int width, const unsigned int height) +{ +#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) + + uint32_t value_mask, value_list[32]; + m_XcbWindow = xcb_generate_id(m_WsiConnection.pConnection); + + value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; + value_list[0] = m_pXcbScreen->black_pixel; + value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | + XCB_EVENT_MASK_EXPOSURE; + + xcb_create_window(m_WsiConnection.pConnection, + XCB_COPY_FROM_PARENT, + m_XcbWindow, m_WsiConnection.root, + 0, 0, width, height, 0, + XCB_WINDOW_CLASS_INPUT_OUTPUT, + m_pXcbScreen->root_visual, + value_mask, value_list); + + xcb_map_window(m_WsiConnection.pConnection, m_XcbWindow); + xcb_flush(m_WsiConnection.pConnection); + return 0; +#elif defined(WIN32) + // Register Window class + WNDCLASSEX wcex = {}; + wcex.cbSize = sizeof( WNDCLASSEX); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = WindowProcXgl; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = GetModuleHandle(0); + wcex.hIcon = LoadIcon(wcex.hInstance, MAKEINTRESOURCE( IDI_ICON)); + wcex.hCursor = LoadCursor( NULL, IDC_ARROW); + wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1); + wcex.lpszMenuName = NULL; + wcex.lpszClassName = APP_NAME; + wcex.hIconSm = LoadIcon( wcex.hInstance, MAKEINTRESOURCE( IDI_ICON)); + if( !RegisterClassEx( &wcex)) + { + glv_LogError("Failed to register windows class\n"); + return -1; + } + + // create the window + m_windowHandle = CreateWindow(APP_NAME, APP_NAME, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, 0, 0, + width, height, NULL, NULL, wcex.hInstance, NULL); + + if (m_windowHandle) + { + ShowWindow( m_windowHandle, SW_SHOWDEFAULT); + m_windowWidth = width; + m_windowHeight = height; + } else { + glv_LogError("Failed to create window\n"); + return -1; + } + return 0; +#endif +} + +void xglDisplay::resize_window(const unsigned int width, const unsigned int height) +{ +#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) + if (width != m_windowWidth || height != m_windowHeight) + { + uint32_t values[2]; + values[0] = width; + values[1] = height; + xcb_configure_window(m_WsiConnection.pConnection, m_XcbWindow, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values); + m_windowWidth = width; + m_windowHeight = height; + } +#elif defined(WIN32) + if (width != m_windowWidth || height != m_windowHeight) + { + SetWindowPos(get_window_handle(), HWND_TOP, 0, 0, width, height, SWP_NOMOVE); + m_windowWidth = width; + m_windowHeight = height; + } +#endif +} + +void xglDisplay::process_event() +{ +} diff --git a/tools/glave/src/glv_extensions/glvreplay_xgl/glvreplay_xgl_xgldisplay.h b/tools/glave/src/glv_extensions/glvreplay_xgl/glvreplay_xgl_xgldisplay.h new file mode 100644 index 0000000..841a9a6 --- /dev/null +++ b/tools/glave/src/glv_extensions/glvreplay_xgl/glvreplay_xgl_xgldisplay.h @@ -0,0 +1,71 @@ +/* + * Vulkan + * + * Copyright (C) 2014 LunarG, Inc. + * Copyright (C) 2015 Valve Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#include "glvreplay_xgl_replay.h" + +class xglDisplay: public glv_replay::DisplayImp { +friend class xglReplay; +public: + xglDisplay(); + ~xglDisplay(); + int init(const unsigned int gpu_idx); + int set_window(glv_window_handle hWindow, unsigned int width, unsigned int height); + int create_window(const unsigned int width, const unsigned int height); + void resize_window(const unsigned int width, const unsigned int height); + void process_event(); + // XGL_DEVICE get_device() { return m_dev[m_gpuIdx];} +#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) + xcb_window_t get_window_handle() { return m_XcbWindow; } +#elif defined(WIN32) + HWND get_window_handle() { return m_windowHandle; } +#endif +private: + XGL_RESULT init_xgl(const unsigned int gpu_idx); + bool m_initedXGL; +#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA) + XGL_WSI_X11_CONNECTION_INFO m_WsiConnection; + xcb_screen_t *m_pXcbScreen; + xcb_window_t m_XcbWindow; +#elif defined(WIN32) + HWND m_windowHandle; +#endif + unsigned int m_windowWidth; + unsigned int m_windowHeight; + unsigned int m_frameNumber; + std::vector imageWidth; + std::vector imageHeight; + std::vector imageHandles; + std::vector imageMemory; +#if 0 + XGL_DEVICE m_dev[XGL_MAX_PHYSICAL_GPUS]; + uint32_t m_gpuCount; + unsigned int m_gpuIdx; + XGL_PHYSICAL_GPU m_gpus[XGL_MAX_PHYSICAL_GPUS]; + XGL_PHYSICAL_GPU_PROPERTIES m_gpuProps[XGL_MAX_PHYSICAL_GPUS]; +#endif + std::vectorm_extensions; +}; diff --git a/tools/glave/src/glv_extensions/glvreplay_xgl/glvreplay_xgl_xglreplay.cpp b/tools/glave/src/glv_extensions/glvreplay_xgl/glvreplay_xgl_xglreplay.cpp new file mode 100644 index 0000000..9ed889c --- /dev/null +++ b/tools/glave/src/glv_extensions/glvreplay_xgl/glvreplay_xgl_xglreplay.cpp @@ -0,0 +1,948 @@ +/* + * Vulkan + * + * Copyright (C) 2014 LunarG, Inc. + * Copyright (C) 2015 Valve Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "xgl.h" +#include "glvreplay_xgl_replay.h" +#include "glvreplay_xgl.h" +#include "glvreplay_xgl_settings.h" + +#include +#include + +extern "C" { +#include "glv_vk_vk_structs.h" +#include "xgl_enum_string_helper.h" +} + +glvreplay_settings *g_pReplaySettings; + +static const char* g_extensions[] = +{ + "XGL_WSI_WINDOWS", + "XGL_TIMER_QUEUE", + "XGL_GPU_TIMESTAMP_CALIBRATION", + "XGL_DMA_QUEUE", + "XGL_COMMAND_BUFFER_CONTROL_FLOW", + "XGL_COPY_OCCLUSION_QUERY_DATA", + "XGL_ADVANCED_MULTISAMPLING", + "XGL_BORDER_COLOR_PALETTE" +}; + +xglReplay::xglReplay(glvreplay_settings *pReplaySettings) +{ + g_pReplaySettings = pReplaySettings; + m_display = new xglDisplay(); + m_pDSDump = NULL; + m_pCBDump = NULL; + m_pGlvSnapshotPrint = NULL; + if (g_pReplaySettings && g_pReplaySettings->screenshotList) { + process_screenshot_list(g_pReplaySettings->screenshotList); + } +} + +xglReplay::~xglReplay() +{ + delete m_display; + glv_platform_close_library(m_xglFuncs.m_libHandle); +} + +int xglReplay::init(glv_replay::Display & disp) +{ + int err; +#if defined PLATFORM_LINUX + void * handle = dlopen("libXGL.so", RTLD_LAZY); +#else + HMODULE handle = LoadLibrary("xgl.dll" ); +#endif + + if (handle == NULL) { + glv_LogError("Failed to open xgl library.\n"); + return -1; + } + m_xglFuncs.init_funcs(handle); + disp.set_implementation(m_display); + if ((err = m_display->init(disp.get_gpu())) != 0) { + glv_LogError("Failed to init XGL display.\n"); + return err; + } + if (disp.get_window_handle() == 0) + { + if ((err = m_display->create_window(disp.get_width(), disp.get_height())) != 0) { + glv_LogError("Failed to create Window\n"); + return err; + } + } + else + { + if ((err = m_display->set_window(disp.get_window_handle(), disp.get_width(), disp.get_height())) != 0) + { + glv_LogError("Failed to set Window\n"); + return err; + } + } + return 0; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::handle_replay_errors(const char* entrypointName, const XGL_RESULT resCall, const XGL_RESULT resTrace, const glv_replay::GLV_REPLAY_RESULT resIn) +{ + glv_replay::GLV_REPLAY_RESULT res = resIn; + if (resCall != resTrace) { + glv_LogWarn("Mismatched return from API call (%s) traced result %s, replay result %s\n", entrypointName, + string_XGL_RESULT((XGL_RESULT)resTrace), string_XGL_RESULT((XGL_RESULT)resCall)); + res = glv_replay::GLV_REPLAY_BAD_RETURN; + } +#if 0 + if (resCall != XGL_SUCCESS) { + glv_LogWarn("API call (%s) returned failed result %s\n", entrypointName, string_XGL_RESULT(resCall)); + } +#endif + return res; +} + +void xglReplay::push_validation_msg(XGL_VALIDATION_LEVEL validationLevel, XGL_BASE_OBJECT srcObject, size_t location, int32_t msgCode, const char * pMsg) +{ + struct validationMsg msgObj; + msgObj.validationLevel = validationLevel; + msgObj.srcObject = srcObject; + msgObj.location = location; + msgObj.msgCode = msgCode; + strncpy(msgObj.msg, pMsg, 256); + msgObj.msg[255] = '\0'; + m_validationMsgs.push_back(msgObj); +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::pop_validation_msgs() +{ + if (m_validationMsgs.size() == 0) + return glv_replay::GLV_REPLAY_SUCCESS; + m_validationMsgs.clear(); + return glv_replay::GLV_REPLAY_VALIDATION_ERROR; +} + +int xglReplay::dump_validation_data() +{ + if (m_pDSDump && m_pCBDump) + { + m_pDSDump((char *) "pipeline_dump.dot"); + m_pCBDump((char *) "cb_dump.dot"); + } + if (m_pGlvSnapshotPrint != NULL) { m_pGlvSnapshotPrint(); } + return 0; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglCreateDevice(struct_xglCreateDevice* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + if (!m_display->m_initedXGL) + { + XGL_DEVICE device; + if (g_xglReplaySettings.debugLevel > 0) + { + XGL_DEVICE_CREATE_INFO cInfo, *ci, *pCreateInfoSaved; + unsigned int numLayers = 0; + char ** layersStr = get_enableLayers_list(&numLayers); + apply_layerSettings_overrides(); + XGL_LAYER_CREATE_INFO layerInfo; + pCreateInfoSaved = (XGL_DEVICE_CREATE_INFO *) pPacket->pCreateInfo; + ci = (XGL_DEVICE_CREATE_INFO *) pPacket->pCreateInfo; + if (layersStr != NULL && numLayers > 0) + { + while (ci->pNext != NULL) + ci = (XGL_DEVICE_CREATE_INFO *) ci->pNext; + ci->pNext = &layerInfo; + layerInfo.sType = XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO; + layerInfo.pNext = 0; + layerInfo.layerCount = numLayers; + layerInfo.ppActiveLayerNames = layersStr; + } + memcpy(&cInfo, pPacket->pCreateInfo, sizeof(XGL_DEVICE_CREATE_INFO)); + cInfo.flags = pPacket->pCreateInfo->flags | XGL_DEVICE_CREATE_VALIDATION_BIT; + cInfo.maxValidationLevel = (XGL_VALIDATION_LEVEL)((g_xglReplaySettings.debugLevel <= 4) ? (unsigned int) XGL_VALIDATION_LEVEL_0 + g_xglReplaySettings.debugLevel : (unsigned int) XGL_VALIDATION_LEVEL_0); + pPacket->pCreateInfo = &cInfo; + replayResult = m_xglFuncs.real_xglCreateDevice(remap(pPacket->gpu), pPacket->pCreateInfo, &device); + // restore the packet for next replay + ci->pNext = NULL; + pPacket->pCreateInfo = pCreateInfoSaved; + release_enableLayer_list(layersStr); + if (xglDbgRegisterMsgCallback(g_fpDbgMsgCallback, NULL) != XGL_SUCCESS) + glv_LogError("Failed to register xgl callback for replayer error handling\n"); +#if !defined(_WIN32) + m_pDSDump = (DRAW_STATE_DUMP_DOT_FILE) m_xglFuncs.real_xglGetProcAddr(remap(pPacket->gpu), "drawStateDumpDotFile"); + m_pCBDump = (DRAW_STATE_DUMP_COMMAND_BUFFER_DOT_FILE) m_xglFuncs.real_xglGetProcAddr(remap(pPacket->gpu), "drawStateDumpCommandBufferDotFile"); + m_pGlvSnapshotPrint = (GLVSNAPSHOT_PRINT_OBJECTS) m_xglFuncs.real_xglGetProcAddr(remap(pPacket->gpu), "glvSnapshotPrintObjects"); +#endif + } + else + replayResult = m_xglFuncs.real_xglCreateDevice(remap(pPacket->gpu), pPacket->pCreateInfo, &device); + CHECK_RETURN_VALUE(xglCreateDevice); + if (replayResult == XGL_SUCCESS) + { + add_to_map(pPacket->pDevice, &device); + } + } + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglEnumerateGpus(struct_xglEnumerateGpus* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + if (!m_display->m_initedXGL) + { + uint32_t gpuCount; + XGL_PHYSICAL_GPU gpus[XGL_MAX_PHYSICAL_GPUS]; + uint32_t maxGpus = (pPacket->maxGpus < XGL_MAX_PHYSICAL_GPUS) ? pPacket->maxGpus : XGL_MAX_PHYSICAL_GPUS; + replayResult = m_xglFuncs.real_xglEnumerateGpus(remap(pPacket->instance), maxGpus, &gpuCount, &gpus[0]); + CHECK_RETURN_VALUE(xglEnumerateGpus); + //TODO handle different number of gpus in trace versus replay + if (gpuCount != *(pPacket->pGpuCount)) + { + glv_LogWarn("number of gpus mismatched in replay %u versus trace %u\n", gpuCount, *(pPacket->pGpuCount)); + } + else if (gpuCount == 0) + { + glv_LogError("xglEnumerateGpus number of gpus is zero\n"); + } + else + { + glv_LogInfo("Enumerated %d GPUs in the system\n", gpuCount); + } + // TODO handle enumeration results in a different order from trace to replay + for (uint32_t i = 0; i < gpuCount; i++) + { + if (pPacket->pGpus) + add_to_map(&(pPacket->pGpus[i]), &(gpus[i])); + } + } + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglGetGpuInfo(struct_xglGetGpuInfo* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + if (!m_display->m_initedXGL) + { + switch (pPacket->infoType) { + case XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES: + { + XGL_PHYSICAL_GPU_PROPERTIES gpuProps; + size_t dataSize = sizeof(XGL_PHYSICAL_GPU_PROPERTIES); + replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &dataSize, + (pPacket->pData == NULL) ? NULL : &gpuProps); + if (pPacket->pData != NULL) + { + glv_LogInfo("Replay Gpu Properties\n"); + glv_LogInfo("Vendor ID %x, Device ID %x, name %s\n",gpuProps.vendorId, gpuProps.deviceId, gpuProps.gpuName); + glv_LogInfo("API version %u, Driver version %u, gpu Type %u\n",gpuProps.apiVersion, gpuProps.driverVersion, gpuProps.gpuType); + } + break; + } + case XGL_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE: + { + XGL_PHYSICAL_GPU_PERFORMANCE gpuPerfs; + size_t dataSize = sizeof(XGL_PHYSICAL_GPU_PERFORMANCE); + replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &dataSize, + (pPacket->pData == NULL) ? NULL : &gpuPerfs); + if (pPacket->pData != NULL) + { + glv_LogInfo("Replay Gpu Performance\n"); + glv_LogInfo("Max GPU clock %f, max shader ALUs/clock %f, max texel fetches/clock %f\n",gpuPerfs.maxGpuClock, gpuPerfs.aluPerClock, gpuPerfs.texPerClock); + glv_LogInfo("Max primitives/clock %f, Max pixels/clock %f\n",gpuPerfs.primsPerClock, gpuPerfs.pixelsPerClock); + } + break; + } + case XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES: + { + XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *pGpuQueue, *pQ; + size_t dataSize = sizeof(XGL_PHYSICAL_GPU_QUEUE_PROPERTIES); + size_t numQueues = 1; + assert(pPacket->pDataSize); + if ((*(pPacket->pDataSize) % dataSize) != 0) + glv_LogWarn("xglGetGpuInfo() for GPU_QUEUE_PROPERTIES not an integral data size assuming 1\n"); + else + numQueues = *(pPacket->pDataSize) / dataSize; + dataSize = numQueues * dataSize; + pQ = static_cast < XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *> (glv_malloc(dataSize)); + pGpuQueue = pQ; + replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &dataSize, + (pPacket->pData == NULL) ? NULL : pGpuQueue); + if (pPacket->pData != NULL) + { + for (unsigned int i = 0; i < numQueues; i++) + { + glv_LogInfo("Replay Gpu Queue Property for index %d, flags %u\n", i, pGpuQueue->queueFlags); + glv_LogInfo("Max available count %u, max atomic counters %u, supports timestamps %u\n",pGpuQueue->queueCount, pGpuQueue->maxAtomicCounters, pGpuQueue->supportsTimestamps); + pGpuQueue++; + } + } + glv_free(pQ); + break; + } + default: + { + size_t size = 0; + void* pData = NULL; + if (pPacket->pData != NULL && pPacket->pDataSize != NULL) + { + size = *pPacket->pDataSize; + pData = glv_malloc(*pPacket->pDataSize); + } + replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &size, pData); + if (replayResult == XGL_SUCCESS) + { + if (size != *pPacket->pDataSize && pData != NULL) + { + glv_LogWarn("xglGetGpuInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\n", size, *pPacket->pDataSize); + } + else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0) + { + glv_LogWarn("xglGetGpuInfo returned differing data contents than the trace file contained.\n"); + } + } + glv_free(pData); + break; + } + }; + CHECK_RETURN_VALUE(xglGetGpuInfo); + } + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglGetExtensionSupport(struct_xglGetExtensionSupport* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + if (!m_display->m_initedXGL) { + replayResult = m_xglFuncs.real_xglGetExtensionSupport(remap(pPacket->gpu), pPacket->pExtName); + CHECK_RETURN_VALUE(xglGetExtensionSupport); + if (replayResult == XGL_SUCCESS) { + for (unsigned int ext = 0; ext < sizeof(g_extensions) / sizeof(g_extensions[0]); ext++) + { + if (!strncmp(g_extensions[ext], pPacket->pExtName, strlen(g_extensions[ext]))) { + bool extInList = false; + for (unsigned int j = 0; j < m_display->m_extensions.size(); ++j) { + if (!strncmp(m_display->m_extensions[j], g_extensions[ext], strlen(g_extensions[ext]))) + extInList = true; + break; + } + if (!extInList) + m_display->m_extensions.push_back((char *) g_extensions[ext]); + break; + } + } + } + } + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglQueueSubmit(struct_xglQueueSubmit* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_CMD_BUFFER *remappedBuffers = NULL; + if (pPacket->pCmdBuffers != NULL) + { + remappedBuffers = GLV_NEW_ARRAY( XGL_CMD_BUFFER, pPacket->cmdBufferCount); + for (uint32_t i = 0; i < pPacket->cmdBufferCount; i++) + { + *(remappedBuffers + i) = remap(*(pPacket->pCmdBuffers + i)); + } + } + XGL_MEMORY_REF* memRefs = NULL; + if (pPacket->pMemRefs != NULL) + { + memRefs = GLV_NEW_ARRAY(XGL_MEMORY_REF, pPacket->memRefCount); + memcpy(memRefs, pPacket->pMemRefs, sizeof(XGL_MEMORY_REF) * pPacket->memRefCount); + for (uint32_t i = 0; i < pPacket->memRefCount; i++) + { + memRefs[i].mem = remap(pPacket->pMemRefs[i].mem); + } + } + replayResult = m_xglFuncs.real_xglQueueSubmit(remap(pPacket->queue), pPacket->cmdBufferCount, remappedBuffers, pPacket->memRefCount, + memRefs, remap(pPacket->fence)); + GLV_DELETE(remappedBuffers); + GLV_DELETE(memRefs); + CHECK_RETURN_VALUE(xglQueueSubmit); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglGetObjectInfo(struct_xglGetObjectInfo* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + size_t size = 0; + void* pData = NULL; + if (pPacket->pData != NULL && pPacket->pDataSize != NULL) + { + size = *pPacket->pDataSize; + pData = glv_malloc(*pPacket->pDataSize); + memcpy(pData, pPacket->pData, *pPacket->pDataSize); + } + replayResult = m_xglFuncs.real_xglGetObjectInfo(remap(pPacket->object), pPacket->infoType, &size, pData); + if (replayResult == XGL_SUCCESS) + { + if (size != *pPacket->pDataSize && pData != NULL) + { + glv_LogWarn("xglGetObjectInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\n", size, *pPacket->pDataSize); + } + else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0) + { + glv_LogWarn("xglGetObjectInfo returned differing data contents than the trace file contained.\n"); + } + } + glv_free(pData); + CHECK_RETURN_VALUE(xglGetObjectInfo); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglGetFormatInfo(struct_xglGetFormatInfo* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + size_t size = 0; + void* pData = NULL; + if (pPacket->pData != NULL && pPacket->pDataSize != NULL) + { + size = *pPacket->pDataSize; + pData = glv_malloc(*pPacket->pDataSize); + } + replayResult = m_xglFuncs.real_xglGetFormatInfo(remap(pPacket->device), pPacket->format, pPacket->infoType, &size, pData); + if (replayResult == XGL_SUCCESS) + { + if (size != *pPacket->pDataSize && pData != NULL) + { + glv_LogWarn("xglGetFormatInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\n", size, *pPacket->pDataSize); + } + else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0) + { + glv_LogWarn("xglGetFormatInfo returned differing data contents than the trace file contained.\n"); + } + } + glv_free(pData); + CHECK_RETURN_VALUE(xglGetFormatInfo); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglGetImageSubresourceInfo(struct_xglGetImageSubresourceInfo* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + size_t size = 0; + void* pData = NULL; + if (pPacket->pData != NULL && pPacket->pDataSize != NULL) + { + size = *pPacket->pDataSize; + pData = glv_malloc(*pPacket->pDataSize); + } + replayResult = m_xglFuncs.real_xglGetImageSubresourceInfo(remap(pPacket->image), pPacket->pSubresource, pPacket->infoType, &size, pData); + if (replayResult == XGL_SUCCESS) + { + if (size != *pPacket->pDataSize && pData != NULL) + { + glv_LogWarn("xglGetImageSubresourceInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\n", size, *pPacket->pDataSize); + } + else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0) + { + glv_LogWarn("xglGetImageSubresourceInfo returned differing data contents than the trace file contained.\n"); + } + } + glv_free(pData); + CHECK_RETURN_VALUE(xglGetImageSubresourceInfo); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglUpdateDescriptors(struct_xglUpdateDescriptors* pPacket) +{ + // 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 + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_UPDATE_SAMPLERS* pUpdateChain = (XGL_UPDATE_SAMPLERS*)pPacket->pUpdateChain; + std::queue saveSamplers; + std::queue saveBufferViews; + std::queue saveImageViews; + std::queue saveDescSets; + while (pUpdateChain) { + switch(pUpdateChain->sType) + { + case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS: + for (uint32_t i = 0; i < ((XGL_UPDATE_SAMPLERS*)pUpdateChain)->count; i++) { + XGL_SAMPLER* pLocalSampler = (XGL_SAMPLER*) &((XGL_UPDATE_SAMPLERS*)pUpdateChain)->pSamplers[i]; + saveSamplers.push(*pLocalSampler); + *pLocalSampler = remap(((XGL_UPDATE_SAMPLERS*)pUpdateChain)->pSamplers[i]); + } + break; + case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES: + { + XGL_UPDATE_SAMPLER_TEXTURES *pUST = (XGL_UPDATE_SAMPLER_TEXTURES *) pUpdateChain; + for (uint32_t i = 0; i < pUST->count; i++) { + XGL_SAMPLER *pLocalSampler = (XGL_SAMPLER *) &pUST->pSamplerImageViews[i].pSampler; + saveSamplers.push(*pLocalSampler); + *pLocalSampler = remap(pUST->pSamplerImageViews[i].pSampler); + XGL_IMAGE_VIEW *pLocalView = (XGL_IMAGE_VIEW *) &pUST->pSamplerImageViews[i].pImageView->view; + saveImageViews.push(*pLocalView); + *pLocalView = remap(pUST->pSamplerImageViews[i].pImageView->view); + } + break; + } + case XGL_STRUCTURE_TYPE_UPDATE_IMAGES: + { + XGL_UPDATE_IMAGES *pUI = (XGL_UPDATE_IMAGES*) pUpdateChain; + for (uint32_t i = 0; i < pUI->count; i++) { + XGL_IMAGE_VIEW* pLocalView = (XGL_IMAGE_VIEW*) &pUI->pImageViews[i]->view; + saveImageViews.push(*pLocalView); + *pLocalView = remap(pUI->pImageViews[i]->view); + } + break; + } + case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS: + { + XGL_UPDATE_BUFFERS *pUB = (XGL_UPDATE_BUFFERS *) pUpdateChain; + for (uint32_t i = 0; i < pUB->count; i++) { + XGL_BUFFER_VIEW* pLocalView = (XGL_BUFFER_VIEW*) &pUB->pBufferViews[i]->view; + saveBufferViews.push(*pLocalView); + *pLocalView = remap(pUB->pBufferViews[i]->view); + } + break; + } + case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY: + saveDescSets.push(((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet); + ((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet = remap(((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet); + break; + default: + assert(0); + break; + } + pUpdateChain = (XGL_UPDATE_SAMPLERS*) pUpdateChain->pNext; + } + m_xglFuncs.real_xglUpdateDescriptors(remap(pPacket->descriptorSet), pPacket->pUpdateChain); + pUpdateChain = (XGL_UPDATE_SAMPLERS*) pPacket->pUpdateChain; + while (pUpdateChain) { + switch(pUpdateChain->sType) + { + case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS: + for (uint32_t i = 0; i < ((XGL_UPDATE_SAMPLERS*)pUpdateChain)->count; i++) { + XGL_SAMPLER* pLocalSampler = (XGL_SAMPLER*) &((XGL_UPDATE_SAMPLERS*)pUpdateChain)->pSamplers[i]; + *pLocalSampler = saveSamplers.front(); + saveSamplers.pop(); + } + break; + case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES: + { + XGL_UPDATE_SAMPLER_TEXTURES *pUST = (XGL_UPDATE_SAMPLER_TEXTURES *) pUpdateChain; + for (uint32_t i = 0; i < pUST->count; i++) { + XGL_SAMPLER *plocalSampler = (XGL_SAMPLER *) &pUST->pSamplerImageViews[i].pSampler; + *plocalSampler = saveSamplers.front(); + saveSamplers.pop(); + XGL_IMAGE_VIEW *pLocalView = (XGL_IMAGE_VIEW *) &pUST->pSamplerImageViews[i].pImageView->view; + *pLocalView = saveImageViews.front(); + saveImageViews.pop(); + } + break; + } + case XGL_STRUCTURE_TYPE_UPDATE_IMAGES: + { + XGL_UPDATE_IMAGES *pUI = (XGL_UPDATE_IMAGES*) pUpdateChain; + for (uint32_t i = 0; i < pUI->count; i++) { + XGL_IMAGE_VIEW* pLocalView = (XGL_IMAGE_VIEW*) &pUI->pImageViews[i]->view; + *pLocalView = saveImageViews.front(); + saveImageViews.pop(); + } + break; + } + case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS: + { + XGL_UPDATE_BUFFERS *pUB = (XGL_UPDATE_BUFFERS *) pUpdateChain; + for (uint32_t i = 0; i < pUB->count; i++) { + XGL_BUFFER_VIEW* pLocalView = (XGL_BUFFER_VIEW*) &pUB->pBufferViews[i]->view; + *pLocalView = saveBufferViews.front(); + saveBufferViews.pop(); + } + break; + } + case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY: + ((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet = saveDescSets.front(); + saveDescSets.pop(); + //pFreeMe = (XGL_UPDATE_SAMPLERS*)pLocalUpdateChain; + //pLocalUpdateChain = (void*)((XGL_UPDATE_SAMPLERS*)pLocalUpdateChain)->pNext; + //free(pFreeMe); + break; + default: + assert(0); + break; + } + pUpdateChain = (XGL_UPDATE_SAMPLERS*) pUpdateChain->pNext; + } + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglCreateDescriptorSetLayout(struct_xglCreateDescriptorSetLayout* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_SAMPLER saveSampler; + if (pPacket->pSetLayoutInfoList != NULL) { + XGL_SAMPLER *pSampler = (XGL_SAMPLER *) &pPacket->pSetLayoutInfoList->immutableSampler; + saveSampler = pPacket->pSetLayoutInfoList->immutableSampler; + *pSampler = remap(saveSampler); + } + XGL_DESCRIPTOR_SET_LAYOUT setLayout; + replayResult = m_xglFuncs.real_xglCreateDescriptorSetLayout(remap(pPacket->device), pPacket->stageFlags, pPacket->pSetBindPoints, remap(pPacket->priorSetLayout), pPacket->pSetLayoutInfoList, &setLayout); + if (replayResult == XGL_SUCCESS) + { + add_to_map(pPacket->pSetLayout, &setLayout); + } + if (pPacket->pSetLayoutInfoList != NULL) { + XGL_SAMPLER *pSampler = (XGL_SAMPLER *) &pPacket->pSetLayoutInfoList->immutableSampler; + *pSampler = saveSampler; + } + CHECK_RETURN_VALUE(xglCreateDescriptorSetLayout); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglCreateGraphicsPipeline(struct_xglCreateGraphicsPipeline* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_GRAPHICS_PIPELINE_CREATE_INFO createInfo; + struct shaderPair saveShader[10]; + unsigned int idx = 0; + memcpy(&createInfo, pPacket->pCreateInfo, sizeof(XGL_GRAPHICS_PIPELINE_CREATE_INFO)); + createInfo.lastSetLayout = remap(createInfo.lastSetLayout); + // Cast to shader type, as those are of primariy interest and all structs in LL have same header w/ sType & pNext + XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pPacketNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pPacket->pCreateInfo->pNext; + XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)createInfo.pNext; + while (XGL_NULL_HANDLE != pPacketNext) + { + if (XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO == pNext->sType) + { + saveShader[idx].val = pNext->shader.shader; + saveShader[idx++].addr = &(pNext->shader.shader); + pNext->shader.shader = remap(pPacketNext->shader.shader); + } + pPacketNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pPacketNext->pNext; + pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pNext->pNext; + } + XGL_PIPELINE pipeline; + replayResult = m_xglFuncs.real_xglCreateGraphicsPipeline(remap(pPacket->device), &createInfo, &pipeline); + if (replayResult == XGL_SUCCESS) + { + add_to_map(pPacket->pPipeline, &pipeline); + } + for (unsigned int i = 0; i < idx; i++) + *(saveShader[i].addr) = saveShader[i].val; + CHECK_RETURN_VALUE(xglCreateGraphicsPipeline); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglCmdWaitEvents(struct_xglCmdWaitEvents* pPacket) +{ + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_EVENT saveEvent[100]; + uint32_t idx, numRemapBuf=0, numRemapImg=0; + assert(pPacket->pWaitInfo && pPacket->pWaitInfo->eventCount <= 100); + for (idx = 0; idx < pPacket->pWaitInfo->eventCount; idx++) + { + XGL_EVENT *pEvent = (XGL_EVENT *) &(pPacket->pWaitInfo->pEvents[idx]); + saveEvent[idx] = pPacket->pWaitInfo->pEvents[idx]; + *pEvent = remap(pPacket->pWaitInfo->pEvents[idx]); + } + + XGL_BUFFER saveBuf[100]; + XGL_IMAGE saveImg[100]; + for (idx = 0; idx < pPacket->pWaitInfo->memBarrierCount; idx++) + { + XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx]; + assert(pNext); + if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) { + XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx]; + assert(numRemapBuf < 100); + saveBuf[numRemapBuf++] = pNextBuf->buffer; + pNextBuf->buffer = remap(pNextBuf->buffer); + } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) { + XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx]; + assert(numRemapImg < 100); + saveImg[numRemapImg++] = pNextImg->image; + pNextImg->image = remap(pNextImg->image); + } + } + m_xglFuncs.real_xglCmdWaitEvents(remap(pPacket->cmdBuffer), pPacket->pWaitInfo); + for (idx = 0; idx < pPacket->pWaitInfo->memBarrierCount; idx++) { + XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx]; + if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) { + XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx]; + pNextBuf->buffer = saveBuf[idx]; + } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) { + XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx]; + pNextImg->image = saveImg[idx]; + } + } + for (idx = 0; idx < pPacket->pWaitInfo->eventCount; idx++) { + XGL_EVENT *pEvent = (XGL_EVENT *) &(pPacket->pWaitInfo->pEvents[idx]); + *pEvent = saveEvent[idx]; + } + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglCmdPipelineBarrier(struct_xglCmdPipelineBarrier* pPacket) +{ + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + uint32_t idx, numRemapBuf=0, numRemapImg=0; + XGL_BUFFER saveBuf[100]; + XGL_IMAGE saveImg[100]; + for (idx = 0; idx < pPacket->pBarrier->memBarrierCount; idx++) + { + XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx]; + assert(pNext); + if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) { + XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx]; + assert(numRemapBuf < 100); + saveBuf[numRemapBuf++] = pNextBuf->buffer; + pNextBuf->buffer = remap(pNextBuf->buffer); + } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) { + XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx]; + assert(numRemapImg < 100); + saveImg[numRemapImg++] = pNextImg->image; + pNextImg->image = remap(pNextImg->image); + } + } + m_xglFuncs.real_xglCmdPipelineBarrier(remap(pPacket->cmdBuffer), pPacket->pBarrier); + for (idx = 0; idx < pPacket->pBarrier->memBarrierCount; idx++) { + XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx]; + if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) { + XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx]; + pNextBuf->buffer = saveBuf[idx]; + } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) { + XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx]; + pNextImg->image = saveImg[idx]; + } + } + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglCreateFramebuffer(struct_xglCreateFramebuffer* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_FRAMEBUFFER_CREATE_INFO *pInfo = (XGL_FRAMEBUFFER_CREATE_INFO *) pPacket->pCreateInfo; + XGL_COLOR_ATTACHMENT_BIND_INFO *pColorAttachments, *pSavedColor = (XGL_COLOR_ATTACHMENT_BIND_INFO*)pInfo->pColorAttachments; + bool allocatedColorAttachments = false; + if (pSavedColor != NULL) + { + allocatedColorAttachments = true; + pColorAttachments = GLV_NEW_ARRAY(XGL_COLOR_ATTACHMENT_BIND_INFO, pInfo->colorAttachmentCount); + memcpy(pColorAttachments, pSavedColor, sizeof(XGL_COLOR_ATTACHMENT_BIND_INFO) * pInfo->colorAttachmentCount); + for (uint32_t i = 0; i < pInfo->colorAttachmentCount; i++) + { + pColorAttachments[i].view = remap(pInfo->pColorAttachments[i].view); + } + pInfo->pColorAttachments = pColorAttachments; + } + // remap depth stencil target + const XGL_DEPTH_STENCIL_BIND_INFO *pSavedDS = pInfo->pDepthStencilAttachment; + XGL_DEPTH_STENCIL_BIND_INFO depthTarget; + if (pSavedDS != NULL) + { + memcpy(&depthTarget, pSavedDS, sizeof(XGL_DEPTH_STENCIL_BIND_INFO)); + depthTarget.view = remap(pSavedDS->view); + pInfo->pDepthStencilAttachment = &depthTarget; + } + XGL_FRAMEBUFFER local_framebuffer; + replayResult = m_xglFuncs.real_xglCreateFramebuffer(remap(pPacket->device), pPacket->pCreateInfo, &local_framebuffer); + pInfo->pColorAttachments = pSavedColor; + pInfo->pDepthStencilAttachment = pSavedDS; + if (replayResult == XGL_SUCCESS) + { + add_to_map(pPacket->pFramebuffer, &local_framebuffer); + } + if (allocatedColorAttachments) + { + GLV_DELETE((void*)pColorAttachments); + } + CHECK_RETURN_VALUE(xglCreateFramebuffer); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglCreateRenderPass(struct_xglCreateRenderPass* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_RENDER_PASS_CREATE_INFO *pInfo = (XGL_RENDER_PASS_CREATE_INFO *) pPacket->pCreateInfo; + // remap framebuffer + XGL_FRAMEBUFFER savedFB = 0, *pFB = &(pInfo->framebuffer); + if (*pFB != NULL) + { + savedFB = pInfo->framebuffer; + *pFB = remap(pInfo->framebuffer); + } + XGL_RENDER_PASS local_renderpass; + replayResult = m_xglFuncs.real_xglCreateRenderPass(remap(pPacket->device), pPacket->pCreateInfo, &local_renderpass); + if (*pFB != NULL) + pInfo->framebuffer = savedFB; + if (replayResult == XGL_SUCCESS) + { + add_to_map(pPacket->pRenderPass, &local_renderpass); + } + CHECK_RETURN_VALUE(xglCreateRenderPass); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglBeginCommandBuffer(struct_xglBeginCommandBuffer* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_CMD_BUFFER_BEGIN_INFO* pInfo = (XGL_CMD_BUFFER_BEGIN_INFO*)pPacket->pBeginInfo; + // assume only zero or one graphics_begin_info in the chain + XGL_RENDER_PASS savedRP, *pRP; + XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO *pGInfo = NULL; + while (pInfo != NULL) + { + + if (pInfo->sType == XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO) + { + pGInfo = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO *) pInfo; + savedRP = pGInfo->renderPass; + pRP = &(pGInfo->renderPass); + *pRP = remap(pGInfo->renderPass); + break; + } + pInfo = (XGL_CMD_BUFFER_BEGIN_INFO*) pInfo->pNext; + } + replayResult = m_xglFuncs.real_xglBeginCommandBuffer(remap(pPacket->cmdBuffer), pPacket->pBeginInfo); + if (pGInfo != NULL) + pGInfo->renderPass = savedRP; + CHECK_RETURN_VALUE(xglBeginCommandBuffer); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglStorePipeline(struct_xglStorePipeline* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + size_t size = 0; + void* pData = NULL; + if (pPacket->pData != NULL && pPacket->pDataSize != NULL) + { + size = *pPacket->pDataSize; + pData = glv_malloc(*pPacket->pDataSize); + } + replayResult = m_xglFuncs.real_xglStorePipeline(remap(pPacket->pipeline), &size, pData); + if (replayResult == XGL_SUCCESS) + { + if (size != *pPacket->pDataSize && pData != NULL) + { + glv_LogWarn("xglStorePipeline returned a differing data size: replay (%d bytes) vs trace (%d bytes)\n", size, *pPacket->pDataSize); + } + else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0) + { + glv_LogWarn("xglStorePipeline returned differing data contents than the trace file contained.\n"); + } + } + glv_free(pData); + CHECK_RETURN_VALUE(xglStorePipeline); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglGetMultiGpuCompatibility(struct_xglGetMultiGpuCompatibility* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_GPU_COMPATIBILITY_INFO cInfo; + XGL_PHYSICAL_GPU handle0, handle1; + handle0 = remap(pPacket->gpu0); + handle1 = remap(pPacket->gpu1); + replayResult = m_xglFuncs.real_xglGetMultiGpuCompatibility(handle0, handle1, &cInfo); + CHECK_RETURN_VALUE(xglGetMultiGpuCompatibility); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglDestroyObject(struct_xglDestroyObject* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_OBJECT object = remap(pPacket->object); + if (object != XGL_NULL_HANDLE) + replayResult = m_xglFuncs.real_xglDestroyObject(object); + if (replayResult == XGL_SUCCESS) + rm_from_map(pPacket->object); + CHECK_RETURN_VALUE(xglDestroyObject); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglWaitForFences(struct_xglWaitForFences* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_FENCE *pFence = GLV_NEW_ARRAY(XGL_FENCE, pPacket->fenceCount); + for (uint32_t i = 0; i < pPacket->fenceCount; i++) + { + *(pFence + i) = remap(*(pPacket->pFences + i)); + } + replayResult = m_xglFuncs.real_xglWaitForFences(remap(pPacket->device), pPacket->fenceCount, pFence, pPacket->waitAll, pPacket->timeout); + GLV_DELETE(pFence); + CHECK_RETURN_VALUE(xglWaitForFences); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglFreeMemory(struct_xglFreeMemory* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_GPU_MEMORY handle = remap(pPacket->mem); + replayResult = m_xglFuncs.real_xglFreeMemory(handle); + if (replayResult == XGL_SUCCESS) + { + rm_entry_from_mapData(handle); + rm_from_map(pPacket->mem); + } + CHECK_RETURN_VALUE(xglFreeMemory); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglMapMemory(struct_xglMapMemory* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_GPU_MEMORY handle = remap(pPacket->mem); + void* pData; + replayResult = m_xglFuncs.real_xglMapMemory(handle, pPacket->flags, &pData); + if (replayResult == XGL_SUCCESS) + add_mapping_to_mapData(handle, pData); + CHECK_RETURN_VALUE(xglMapMemory); + return returnValue; +} + +glv_replay::GLV_REPLAY_RESULT xglReplay::manually_handle_xglUnmapMemory(struct_xglUnmapMemory* pPacket) +{ + XGL_RESULT replayResult = XGL_ERROR_UNKNOWN; + glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS; + XGL_GPU_MEMORY handle = remap(pPacket->mem); + rm_mapping_from_mapData(handle, pPacket->pData); // copies data from packet into memory buffer + replayResult = m_xglFuncs.real_xglUnmapMemory(handle); + CHECK_RETURN_VALUE(xglUnmapMemory); + return returnValue; +} + -- 2.7.4