misc: Add xglRecordMemoryRange entrypoint and use it in Glave
authorJon Ashburn <jon@lunarg.com>
Fri, 27 Feb 2015 19:53:41 +0000 (12:53 -0700)
committerTobin Ehlis <tobin@lunarg.com>
Mon, 2 Mar 2015 23:11:50 +0000 (16:11 -0700)
glave-generate.py
include/xgl.h
include/xglLayer.h
xgl.py

index ad82aa3c2c91972ccbd7582cc3e5e9e9c5a6f290..0b45ff646c28fd2639b7382d8870e3577ef080ea 100755 (executable)
@@ -318,38 +318,83 @@ class Subcommand(object):
         um_body.append('    XGL_RESULT result;')
         um_body.append('    struct_xglUnmapMemory* pPacket;')
         um_body.append('    XGLAllocInfo *entry;')
-        um_body.append('    SEND_ENTRYPOINT_PARAMS("xglUnmapMemory(mem %p)\\n", mem);')
+        um_body.append('    size_t siz = 0;')
         um_body.append('    // insert into packet the data that was written by CPU between the xglMapMemory call and here')
         um_body.append('    // Note must do this prior to the real xglUnMap() or else may get a FAULT')
         um_body.append('    glv_enter_critical_section(&g_memInfoLock);')
         um_body.append('    entry = find_mem_info_entry(mem);')
-        um_body.append('    CREATE_TRACE_PACKET(xglUnmapMemory, (entry) ? entry->size : 0);')
+        um_body.append('    if (entry != NULL && entry->rangeSize == 0 && entry->rangeOffset == 0)')
+        um_body.append('        // no xglRecordMemoryRange has occured so copy entire buffer')
+        um_body.append('        siz = entry->size;')
+        um_body.append('    CREATE_TRACE_PACKET(xglUnmapMemory, siz);')
         um_body.append('    pPacket = interpret_body_as_xglUnmapMemory(pHeader);')
-        um_body.append('    if (entry)')
+        um_body.append('    if (siz)')
         um_body.append('    {')
         um_body.append('        assert(entry->handle == mem);')
-        um_body.append('        glv_add_buffer_to_trace_packet(pHeader, (void**) &(pPacket->pData), entry->size, entry->pData);')
+        um_body.append('        glv_add_buffer_to_trace_packet(pHeader, (void**) &(pPacket->pData), siz, entry->pData);')
         um_body.append('        glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pData));')
         um_body.append('        entry->pData = NULL;')
-        um_body.append('    } else')
-        um_body.append('    {')
-        um_body.append('         glv_LogError("Failed to copy app memory into trace packet (idx = %u) on xglUnmapMemory\\n", pHeader->global_packet_index);')
         um_body.append('    }')
         um_body.append('    glv_leave_critical_section(&g_memInfoLock);')
         um_body.append('    result = real_xglUnmapMemory(mem);')
         um_body.append('    pPacket->mem = mem;')
+        um_body.append('    pPacket->size = siz;')
         um_body.append('    pPacket->result = result;')
         um_body.append('    FINISH_TRACE_PACKET();')
         um_body.append('    return result;')
         um_body.append('}\n')
         return "\n".join(um_body)
 
+    def _gen_record_memory_range(self):
+        rmr_body = []
+        rmr_body.append('GLVTRACER_EXPORT XGL_RESULT XGLAPI __HOOKED_xglRecordMemoryRange(')
+        rmr_body.append('    XGL_GPU_MEMORY mem,')
+        rmr_body.append('    XGL_GPU_SIZE rangeSize,')
+        rmr_body.append('    XGL_GPU_SIZE rangeOffset)')
+        rmr_body.append('{')
+        rmr_body.append('    glv_trace_packet_header* pHeader;')
+        rmr_body.append('    XGL_RESULT result;')
+        rmr_body.append('    size_t siz;')
+        rmr_body.append('    XGLAllocInfo *entry;')
+        rmr_body.append('    struct_xglRecordMemoryRange* pPacket;')
+        rmr_body.append('    // insert into packet the data that was written by CPU between the xglMapMemory call and here')
+        rmr_body.append('    glv_enter_critical_section(&g_memInfoLock);')
+        rmr_body.append('    entry = find_mem_info_entry(mem);')
+        rmr_body.append('    siz = (entry) ? rangeSize : 0;')
+        rmr_body.append('    CREATE_TRACE_PACKET(xglRecordMemoryRange, siz);')
+        rmr_body.append('    pPacket = interpret_body_as_xglRecordMemoryRange(pHeader);')
+        rmr_body.append('    if (siz)')
+        rmr_body.append('    {')
+        rmr_body.append('        assert(entry->size >= rangeSize + rangeOffset);')
+        rmr_body.append('        assert(entry->handle == mem);')
+        rmr_body.append('        glv_add_buffer_to_trace_packet(pHeader, (void**) &(pPacket->pData), siz, entry->pData + rangeOffset);')
+        rmr_body.append('        glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pData));')
+        rmr_body.append('        entry->pData = NULL;')
+        rmr_body.append('        entry->rangeSize = rangeSize;')
+        rmr_body.append('        entry->rangeOffset = (rangeSize == 0) ? 0 : rangeOffset;')
+        rmr_body.append('    } else')
+        rmr_body.append('    {')
+        rmr_body.append('         glv_LogError("Failed to copy app memory into trace packet (idx = %u) on xglUnmapMemory\\n", pHeader->global_packet_index);')
+        rmr_body.append('    }')
+        rmr_body.append('    glv_leave_critical_section(&g_memInfoLock);')
+        rmr_body.append('    result = real_xglRecordMemoryRange(mem, rangeSize, rangeOffset);')
+        rmr_body.append('    pPacket->mem = mem;')
+        rmr_body.append('    pPacket->rangeSize = rangeSize;')
+        rmr_body.append('    pPacket->rangeOffset = rangeOffset;')
+        rmr_body.append('    pPacket->result = result;')
+        rmr_body.append('    FINISH_TRACE_PACKET();')
+        rmr_body.append('    return result;')
+        rmr_body.append('}\n')
+        return "\n".join(rmr_body)
+
     # Generate functions used to trace API calls and store the input and result data into a packet
     def _generate_trace_funcs(self):
         func_body = []
         for proto in self.protos:
             if 'UnmapMemory' == proto.name:
                 func_body.append(self._gen_unmap_memory())
+            elif 'RecordMemoryRange' == proto.name:
+                func_body.append(self._gen_record_memory_range())
             elif 'Dbg' not in proto.name and 'Wsi' not in proto.name:
                 packet_update_txt = ''
                 return_txt = ''
@@ -726,6 +771,8 @@ class Subcommand(object):
         hf_body.append('    XGL_GPU_SIZE   size;')
         hf_body.append('    XGL_GPU_MEMORY handle;')
         hf_body.append('    void           *pData;')
+        hf_body.append('    XGL_GPU_SIZE   rangeOffset;')
+        hf_body.append('    XGL_GPU_SIZE   rangeSize;')
         hf_body.append('    BOOL           valid;')
         hf_body.append('} XGLAllocInfo;')
         hf_body.append('typedef struct _XGLMemInfo {')
@@ -739,15 +786,7 @@ class Subcommand(object):
         hf_body.append('')
         hf_body.append('static void init_mem_info_entrys(XGLAllocInfo *ptr, const unsigned int num)')
         hf_body.append('{')
-        hf_body.append('    unsigned int i;')
-        hf_body.append('    for (i = 0; i < num; i++)')
-        hf_body.append('    {')
-        hf_body.append('        XGLAllocInfo *entry = ptr + i;')
-        hf_body.append('        entry->pData = NULL;')
-        hf_body.append('        entry->size  = 0;')
-        hf_body.append('        entry->handle = NULL;')
-        hf_body.append('        entry->valid = FALSE;')
-        hf_body.append('    }')
+        hf_body.append('    memset(ptr, 0, num * sizeof(XGLAllocInfo));')
         hf_body.append('}')
         hf_body.append('')
         hf_body.append('// caller must hold the g_memInfoLock')
@@ -868,6 +907,8 @@ class Subcommand(object):
         hf_body.append('    if (entry)')
         hf_body.append('    {')
         hf_body.append('        entry->pData = pData;')
+        hf_body.append('        entry->rangeSize = 0;')
+        hf_body.append('        entry->rangeOffset = 0;')
         hf_body.append('    }')
         hf_body.append('    g_memInfo.pLastMapped = entry;')
         hf_body.append('    glv_leave_critical_section(&g_memInfoLock);')
@@ -884,6 +925,8 @@ class Subcommand(object):
         hf_body.append('        entry->valid = FALSE;')
         hf_body.append('        entry->pData = NULL;')
         hf_body.append('        entry->size = 0;')
+        hf_body.append('        entry->rangeSize = 0;')
+        hf_body.append('        entry->rangeOffset = 0;')
         hf_body.append('        entry->handle = NULL;')
         hf_body.append('')
         hf_body.append('        if (entry == g_memInfo.pLastMapped)')
@@ -1771,6 +1814,9 @@ class Subcommand(object):
         for proto in self.protos:
             if 'Wsi' not in proto.name and 'Dbg' not in proto.name:
                 if 'UnmapMemory' == proto.name:
+                    proto.params.append(xgl.Param("XGL_GPU_SIZE", "size"))
+                    proto.params.append(xgl.Param("void*", "pData"))
+                elif 'RecordMemoryRange' == proto.name:
                     proto.params.append(xgl.Param("void*", "pData"))
                 if_body.append('typedef struct struct_xgl%s {' % proto.name)
                 if_body.append('    glv_trace_packet_header* header;')
@@ -1879,6 +1925,7 @@ class Subcommand(object):
         cd_body.append('typedef struct _XGLAllocInfo {')
         cd_body.append('    XGL_GPU_SIZE size;')
         cd_body.append('    void *pData;')
+        cd_body.append('    bool rangeUpdated;')
         cd_body.append('} XGLAllocInfo;')
         return "\n".join(cd_body)
 
@@ -1967,6 +2014,7 @@ class Subcommand(object):
         rc_body.append('        XGLAllocInfo info;')
         rc_body.append('        info.pData = NULL;')
         rc_body.append('        info.size = size;')
+        rc_body.append('        info.rangeUpdated = false;')
         rc_body.append('        m_mapData.insert(std::pair<XGL_GPU_MEMORY, XGLAllocInfo>(handle, info));')
         rc_body.append('    }')
         rc_body.append('    void add_mapping_to_mapData(XGL_GPU_MEMORY handle, void *pData)')
@@ -1991,24 +2039,29 @@ class Subcommand(object):
         rc_body.append('            return;')
         rc_body.append('        m_mapData.erase(it);')
         rc_body.append('    }')
-        rc_body.append('    void rm_mapping_from_mapData(XGL_GPU_MEMORY handle, void* pData)')
+        rc_body.append('    void copy_data_mapData(XGL_GPU_MEMORY handle, void* pData, XGL_GPU_SIZE size, XGL_GPU_SIZE offset, bool rangeUpdate)')
         rc_body.append('    {')
         rc_body.append('        std::map<XGL_GPU_MEMORY,XGLAllocInfo>::iterator it = m_mapData.find(handle);')
         rc_body.append('        if (it == m_mapData.end())')
         rc_body.append('            return;\n')
         rc_body.append('        XGLAllocInfo &info = it->second;')
-        rc_body.append('        if (!pData || !info.pData)')
+        rc_body.append('        if (!pData && size > 0)')
         rc_body.append('        {')
-        rc_body.append('            if (!pData)')
-        rc_body.append('                glv_LogWarn("rm_mapping_from_mapData() null src pointer\\n");')
-        rc_body.append('            else')
-        rc_body.append('                glv_LogWarn("rm_mapping_from_mapData() null dest pointer size=%u\\n", info.size);')
+        rc_body.append('            glv_LogError("copy_data_mapData() null src pointer\\n");')
         rc_body.append('            info.pData = NULL;')
         rc_body.append('            return;')
         rc_body.append('        }')
-        rc_body.append('        memcpy(info.pData, pData, info.size);')
-        rc_body.append('        info.pData = NULL;')
+        rc_body.append('        if (!info.pData)')
+        rc_body.append('        {')
+        rc_body.append('            glv_LogError("copy_data_mapData() null dest pointer size=%u\\n", info.size);')
+        rc_body.append('            return;')
+        rc_body.append('        }')
+        rc_body.append('        memcpy((char *) info.pData + offset, pData, size);')
+        rc_body.append('        info.rangeUpdated = rangeUpdate;')
+        rc_body.append('        if (!rangeUpdate)')
+        rc_body.append('            info.pData = NULL;')
         rc_body.append('    }\n')
+        rc_body.append('')
         rc_body.append('    /*std::map<XGL_PHYSICAL_GPU, XGL_PHYSICAL_GPU> m_gpus;')
         rc_body.append('    void add_to_map(XGL_PHYSICAL_GPU* pTraceGpu, XGL_PHYSICAL_GPU* pReplayGpu)')
         rc_body.append('    {')
@@ -3237,10 +3290,18 @@ class Subcommand(object):
     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('            // copies data from packet into memory buffer')
+        um_body.append('            copy_data_mapData(handle, pPacket->pData, pPacket->size, 0, false);')
         um_body.append('            replayResult = m_xglFuncs.real_xglUnmapMemory(handle);')
         return "\n".join(um_body)
 
+    def _gen_replay_record_memory_range(self):
+        rmr_body = []
+        rmr_body.append('            XGL_GPU_MEMORY handle = remap(pPacket->mem);')
+        rmr_body.append('            copy_data_mapData(handle, pPacket->pData, pPacket->rangeSize, pPacket->rangeOffset, true);')
+        rmr_body.append('            replayResult = m_xglFuncs.real_xglRecordMemoryRange(handle, pPacket->rangeSize, pPacket->rangeOffset);')
+        return "\n".join(rmr_body)
+
     def _gen_replay_bind_dynamic_memory_view(self):
         bdmv_body = []
         bdmv_body.append('            XGL_MEMORY_VIEW_ATTACH_INFO memView;')
@@ -3275,6 +3336,7 @@ class Subcommand(object):
                             'FreeMemory': self._gen_replay_free_memory,
                             'MapMemory': self._gen_replay_map_memory,
                             'UnmapMemory': self._gen_replay_unmap_memory,
+                            'RecordMemoryRange': self._gen_replay_record_memory_range,
                             'CmdBindDynamicMemoryView': self._gen_replay_bind_dynamic_memory_view,
                             'UpdateDescriptors': self._gen_replay_update_descriptors,
                             'CreateDescriptorSetLayout': self._gen_replay_create_descriptor_set_layout,
index ec71157ed1832a0741b08fb912d8953c079bc475..bdc3c8b060b573b28067177498b1e8860a762360 100644 (file)
@@ -33,7 +33,7 @@
 #include "xglPlatform.h"
 
 // XGL API version supported by this file
-#define XGL_API_VERSION XGL_MAKE_VERSION(0, 50, 1)
+#define XGL_API_VERSION XGL_MAKE_VERSION(0, 50, 2)
 
 #ifdef __cplusplus
 extern "C"
@@ -2241,6 +2241,7 @@ typedef XGL_RESULT (XGLAPI *xglFreeMemoryType)(XGL_GPU_MEMORY mem);
 typedef XGL_RESULT (XGLAPI *xglSetMemoryPriorityType)(XGL_GPU_MEMORY mem, XGL_MEMORY_PRIORITY priority);
 typedef XGL_RESULT (XGLAPI *xglMapMemoryType)(XGL_GPU_MEMORY mem, XGL_FLAGS flags, void** ppData);
 typedef XGL_RESULT (XGLAPI *xglUnmapMemoryType)(XGL_GPU_MEMORY mem);
+typedef XGL_RESULT (XGLAPI *xglRecordMemoryRangeType)(XGL_GPU_MEMORY mem, XGL_GPU_SIZE rangeSize, XGL_GPU_SIZE rangeOffset);
 typedef XGL_RESULT (XGLAPI *xglPinSystemMemoryType)(XGL_DEVICE device, const void* pSysMem, size_t memSize, XGL_GPU_MEMORY* pMem);
 typedef XGL_RESULT (XGLAPI *xglGetMultiGpuCompatibilityType)(XGL_PHYSICAL_GPU gpu0, XGL_PHYSICAL_GPU gpu1, XGL_GPU_COMPATIBILITY_INFO* pInfo);
 typedef XGL_RESULT (XGLAPI *xglOpenSharedMemoryType)(XGL_DEVICE device, const XGL_MEMORY_OPEN_INFO* pOpenInfo, XGL_GPU_MEMORY* pMem);
@@ -2439,6 +2440,11 @@ XGL_RESULT XGLAPI xglMapMemory(
 XGL_RESULT XGLAPI xglUnmapMemory(
     XGL_GPU_MEMORY                              mem);
 
+XGL_RESULT XGLAPI xglRecordMemoryRange(
+    XGL_GPU_MEMORY                              mem,
+    XGL_GPU_SIZE                                rangeSize,
+    XGL_GPU_SIZE                                rangeOffset);
+
 XGL_RESULT XGLAPI xglPinSystemMemory(
     XGL_DEVICE                                  device,
     const void*                                 pSysMem,
index fc192571e459fc6e988e62dea782e2a1bd71b4f1..8a823ab87a2e5cd2cd6976b101db63b041971594 100644 (file)
@@ -48,6 +48,7 @@ typedef struct _XGL_LAYER_DISPATCH_TABLE
     xglSetMemoryPriorityType SetMemoryPriority;
     xglMapMemoryType MapMemory;
     xglUnmapMemoryType UnmapMemory;
+    xglRecordMemoryRangeType RecordMemoryRange;
     xglPinSystemMemoryType PinSystemMemory;
     xglGetMultiGpuCompatibilityType GetMultiGpuCompatibility;
     xglOpenSharedMemoryType OpenSharedMemory;
diff --git a/xgl.py b/xgl.py
index c29cb8bf2a88a6e7a7c89bfba8aaad509ff07b39..91d7341943ecc0b7901b0c1c5ddf4e4fda3917e4 100644 (file)
--- a/xgl.py
+++ b/xgl.py
@@ -306,6 +306,11 @@ core = Extension(
         Proto("XGL_RESULT", "UnmapMemory",
             [Param("XGL_GPU_MEMORY", "mem")]),
 
+        Proto("XGL_RESULT", "RecordMemoryRange",
+            [Param("XGL_GPU_MEMORY", "mem"),
+             Param("XGL_GPU_SIZE", "rangeSize"),
+             Param("XGL_GPU_SIZE", "rangeOffset")]),
+
         Proto("XGL_RESULT", "PinSystemMemory",
             [Param("XGL_DEVICE", "device"),
              Param("const void*", "pSysMem"),