glave-generate: Replace asserts with proper error detection and error logging.
* On Linux debug builds, the asserts cause the debugger to abort, but the code wasn't handling the error case safely anyway, so even a release build would likely crash.
* These situations were being hit if trying to load a trace file from an earlier header version, but are likely to be conditions we'll see when new developers start to use the API.
* With these changes, the error is properly reported and error return values propogated so that the UI detects the invalid file and reports an error to the user.
* The new glv_LogError(..) messages get printed to the console, but are not yet passed to the UI. This will be done as part of a larger change sometime in the future.
diff --git a/glave-generate.py b/glave-generate.py
index ea9fa87..166a17f 100755
--- a/glave-generate.py
+++ b/glave-generate.py
@@ -1595,59 +1595,86 @@
' void** ppLocalMemBarriers = (void**)&pBarrier->ppMemBarriers[i];\n',
' *ppLocalMemBarriers = (void*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pBarrier->ppMemBarriers[i]);\n',
'}']},
- 'CreateDescriptorSetLayout' : {'param': 'pSetLayoutInfoList', 'txt': ['assert(pPacket->pSetLayoutInfoList->sType == XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO);\n',
- '// need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n',
- 'void** ppNextVoidPtr = (void**)&(pPacket->pSetLayoutInfoList->pNext);\n',
- '*ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pSetLayoutInfoList->pNext);\n',
- 'XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pNext = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pPacket->pSetLayoutInfoList->pNext;\n',
- 'while (NULL != pNext)\n', '{\n',
- ' switch(pNext->sType)\n', ' {\n',
- ' case XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO:\n',
- ' {\n',
- ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n',
- ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
- ' break;\n',
+ 'CreateDescriptorSetLayout' : {'param': 'pSetLayoutInfoList', 'txt': ['if (pPacket->pSetLayoutInfoList->sType == XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO) {\n',
+ ' // need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n',
+ ' void** ppNextVoidPtr = (void**)&(pPacket->pSetLayoutInfoList->pNext);\n',
+ ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pSetLayoutInfoList->pNext);\n',
+ ' XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pNext = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pPacket->pSetLayoutInfoList->pNext;\n',
+ ' while (NULL != pNext)\n', ' {\n',
+ ' switch(pNext->sType)\n', ' {\n',
+ ' case XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO:\n',
+ ' {\n' ,
+ ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n',
+ ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
+ ' break;\n',
+ ' }\n',
+ ' default:\n',
+ ' {\n',
+ ' glv_LogError("Encountered an unexpected type in descriptor set layout create list.\\n");\n',
+ ' pPacket->header = NULL;\n',
+ ' pNext->pNext = NULL;\n',
+ ' }\n',
' }\n',
- ' default:\n',
- ' assert(!"Encountered an unexpected type in descriptor set layout create list");\n',
- ' }\n',
- ' pNext = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pNext->pNext;\n',
+ ' pNext = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pNext->pNext;\n',
+ ' }\n',
+ '} else {\n',
+ ' // This is unexpected.\n',
+ ' glv_LogError("CreateDescriptorSetLayout must have LayoutInfoList stype of XGL_STRCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO\\n");\n',
+ ' pPacket->header = NULL;\n',
'}']},
- 'BeginCommandBuffer' : {'param': 'pBeginInfo', 'txt': ['assert(pPacket->pBeginInfo->sType == XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO);\n',
- '// need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n',
- 'XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO** ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO**)&(pPacket->pBeginInfo->pNext);\n',
- '*ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pBeginInfo->pNext);\n',
- 'XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO* pNext = *ppNext;\n',
- 'while (NULL != pNext)\n', '{\n',
- ' switch(pNext->sType)\n', ' {\n',
- ' case XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO:\n',
- ' {\n',
- ' ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO**) &pNext->pNext;\n',
- ' *ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
- ' break;\n',
+ 'BeginCommandBuffer' : {'param': 'pBeginInfo', 'txt': ['if (pPacket->pBeginInfo->sType == XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO) {\n',
+ ' // need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n',
+ ' XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO** ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO**)&(pPacket->pBeginInfo->pNext);\n',
+ ' *ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pBeginInfo->pNext);\n',
+ ' XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO* pNext = *ppNext;\n',
+ ' while (NULL != pNext)\n', ' {\n',
+ ' switch(pNext->sType)\n', ' {\n',
+ ' case XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO:\n',
+ ' {\n',
+ ' ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO**) &pNext->pNext;\n',
+ ' *ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
+ ' break;\n',
+ ' }\n',
+ ' default:\n',
+ ' {\n',
+ ' glv_LogError("Encountered an unexpected type in begin command buffer list.\\n");\n',
+ ' pPacket->header = NULL;\n',
+ ' pNext->pNext = NULL;\n',
+ ' }\n',
' }\n',
- ' default:\n',
- ' assert(!"Encountered an unexpected type in begin command buffer list");\n',
+ ' pNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*)pNext->pNext;\n',
' }\n',
- ' pNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*)pNext->pNext;\n',
+ '} else {\n',
+ ' // This is unexpected.\n',
+ ' glv_LogError("BeginCommandBuffer must have BeginInfo stype of XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO.\\n");\n',
+ ' pPacket->header = NULL;\n',
'}']},
- 'AllocMemory' : {'param': 'pAllocInfo', 'txt': ['assert(pPacket->pAllocInfo->sType == XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO);\n',
- 'XGL_MEMORY_ALLOC_INFO** ppNext = (XGL_MEMORY_ALLOC_INFO**) &(pPacket->pAllocInfo->pNext);\n',
- '*ppNext = (XGL_MEMORY_ALLOC_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pAllocInfo->pNext);\n',
- 'XGL_MEMORY_ALLOC_INFO* pNext = (XGL_MEMORY_ALLOC_INFO*) *ppNext;\n',
- 'while (NULL != pNext)\n', '{\n',
- ' switch(pNext->sType)\n', ' {\n',
- ' case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_BUFFER_INFO:\n',
- ' case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO:\n',
- ' {\n',
- ' ppNext = (XGL_MEMORY_ALLOC_INFO **) &(pNext->pNext);\n',
- ' *ppNext = (XGL_MEMORY_ALLOC_INFO*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
- ' break;\n',
+ 'AllocMemory' : {'param': 'pAllocInfo', 'txt': ['if (pPacket->pAllocInfo->sType == XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO) {\n',
+ ' XGL_MEMORY_ALLOC_INFO** ppNext = (XGL_MEMORY_ALLOC_INFO**) &(pPacket->pAllocInfo->pNext);\n',
+ ' *ppNext = (XGL_MEMORY_ALLOC_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pAllocInfo->pNext);\n',
+ ' XGL_MEMORY_ALLOC_INFO* pNext = (XGL_MEMORY_ALLOC_INFO*) *ppNext;\n',
+ ' while (NULL != pNext)\n', ' {\n',
+ ' switch(pNext->sType)\n', ' {\n',
+ ' case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_BUFFER_INFO:\n',
+ ' case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO:\n',
+ ' {\n',
+ ' ppNext = (XGL_MEMORY_ALLOC_INFO **) &(pNext->pNext);\n',
+ ' *ppNext = (XGL_MEMORY_ALLOC_INFO*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
+ ' break;\n',
+ ' }\n',
+ ' default:\n',
+ ' {\n',
+ ' glv_LogError("Encountered an unexpected type alloc memory list.\\n");\n',
+ ' pPacket->header = NULL;\n',
+ ' pNext->pNext = NULL;\n',
+ ' }\n',
' }\n',
- ' default:\n',
- ' assert(!"Encountered an unexpected type in alloc memory list");\n',
+ ' pNext = (XGL_MEMORY_ALLOC_INFO*)pNext->pNext;\n',
' }\n',
- ' pNext = (XGL_MEMORY_ALLOC_INFO*)pNext->pNext;\n',
+ '} else {\n',
+ ' // This is unexpected.\n',
+ ' glv_LogError("AllocMemory must have AllocInfo stype of XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO.\\n");\n',
+ ' pPacket->header = NULL;\n',
'}']},
'UpdateDescriptors' : {'param': 'pUpdateChain', 'txt': ['XGL_UPDATE_SAMPLERS* pNext = (XGL_UPDATE_SAMPLERS*)pPacket->pUpdateChain;\n',
'while ((NULL != pNext) && (XGL_NULL_HANDLE != pNext))\n', '{\n',
@@ -1708,56 +1735,69 @@
' break;\n',
' }\n',
' default:\n',
- ' assert(!"Encountered an unexpected type in update descriptors pUpdateChain");\n',
+ ' {\n',
+ ' glv_LogError("Encountered an unexpected type in update descriptors pUpdateChain.\\n");\n',
+ ' pPacket->header = NULL;\n',
+ ' pNext->pNext = NULL;\n',
+ ' }\n',
' }\n',
' pNext = (XGL_UPDATE_SAMPLERS*)pNext->pNext;\n',
'}']},
- 'CreateGraphicsPipeline' : {'param': 'pCreateInfo', 'txt': ['assert(pPacket->pCreateInfo->sType == XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO);\n',
- '// need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n',
- 'void** ppNextVoidPtr = (void**)&pPacket->pCreateInfo->pNext;\n',
- '*ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pNext);\n',
- 'XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pPacket->pCreateInfo->pNext;\n',
- 'while ((NULL != pNext) && (XGL_NULL_HANDLE != pNext))\n', '{\n',
- ' switch(pNext->sType)\n', ' {\n',
- ' case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:\n',
- ' case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:\n',
- ' case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:\n',
- ' case XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:\n',
- ' case XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:\n',
- ' case XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:\n',
- ' {\n',
- ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n',
- ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
- ' break;\n',
+ 'CreateGraphicsPipeline' : {'param': 'pCreateInfo', 'txt': ['if (pPacket->pCreateInfo->sType == XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO) {\n',
+ ' // need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n',
+ ' void** ppNextVoidPtr = (void**)&pPacket->pCreateInfo->pNext;\n',
+ ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pNext);\n',
+ ' XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pPacket->pCreateInfo->pNext;\n',
+ ' while ((NULL != pNext) && (XGL_NULL_HANDLE != pNext))\n', '{\n',
+ ' switch(pNext->sType)\n', ' {\n',
+ ' case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:\n',
+ ' case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:\n',
+ ' case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:\n',
+ ' case XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:\n',
+ ' case XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:\n',
+ ' case XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:\n',
+ ' {\n',
+ ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n',
+ ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
+ ' break;\n',
+ ' }\n',
+ ' case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:\n',
+ ' {\n',
+ ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n',
+ ' XGL_PIPELINE_CB_STATE_CREATE_INFO *pCb = (XGL_PIPELINE_CB_STATE_CREATE_INFO *) pNext;\n',
+ ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
+ ' pCb->pAttachments = (XGL_PIPELINE_CB_ATTACHMENT_STATE*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pCb->pAttachments);\n',
+ ' break;\n',
+ ' }\n',
+ ' case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:\n',
+ ' {\n',
+ ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n',
+ ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
+ ' interpret_pipeline_shader(pHeader, &pNext->shader);\n',
+ ' break;\n',
+ ' }\n',
+ ' case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:\n',
+ ' {\n',
+ ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n',
+ ' XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO *pVi = (XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO *) pNext;\n',
+ ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
+ ' pVi->pVertexBindingDescriptions = (XGL_VERTEX_INPUT_BINDING_DESCRIPTION*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pVi->pVertexBindingDescriptions);\n',
+ ' pVi->pVertexAttributeDescriptions = (XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pVi->pVertexAttributeDescriptions);\n',
+ ' break;\n',
+ ' }\n',
+ ' default:\n',
+ ' {\n',
+ ' glv_LogError("Encountered an unexpected type in pipeline state list.\\n");\n',
+ ' pPacket->header = NULL;\n',
+ ' pNext->pNext = NULL;\n',
+ ' }\n',
' }\n',
- ' case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:\n',
- ' {\n',
- ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n',
- ' XGL_PIPELINE_CB_STATE_CREATE_INFO *pCb = (XGL_PIPELINE_CB_STATE_CREATE_INFO *) pNext;\n',
- ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
- ' pCb->pAttachments = (XGL_PIPELINE_CB_ATTACHMENT_STATE*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pCb->pAttachments);\n',
- ' break;\n',
- ' }\n',
- ' case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:\n',
- ' {\n',
- ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n',
- ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
- ' interpret_pipeline_shader(pHeader, &pNext->shader);\n',
- ' break;\n',
- ' }\n',
- ' case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:\n',
- ' {\n',
- ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n',
- ' XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO *pVi = (XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO *) pNext;\n',
- ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n',
- ' pVi->pVertexBindingDescriptions = (XGL_VERTEX_INPUT_BINDING_DESCRIPTION*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pVi->pVertexBindingDescriptions);\n',
- ' pVi->pVertexAttributeDescriptions = (XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pVi->pVertexAttributeDescriptions);\n',
- ' break;\n',
- ' }\n',
- ' default:\n',
- ' assert(!"Encountered an unexpected type in pipeline state list");\n',
+ ' pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pNext->pNext;\n',
' }\n',
- ' pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pNext->pNext;\n',
+ '} else {\n',
+ ' // This is unexpected.\n',
+ ' glv_LogError("CreateGraphicsPipeline must have CreateInfo stype of XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO.\\n");\n',
+ ' pPacket->header = NULL;\n',
'}']},
'CreateComputePipeline' : {'param': 'pCreateInfo', 'txt': ['interpret_pipeline_shader(pHeader, (XGL_PIPELINE_SHADER*)(&pPacket->pCreateInfo->cs));']}}
if_body = []