#include "xgl_dispatch_table_helper.h"
#include "xgl_struct_string_helper.h"
#include "xgl_struct_graphviz_helper.h"
+#include "xgl_struct_size_helper.h"
#include "draw_state.h"
#include "layers_config.h"
// The following is #included again to catch certain OS-specific functions
assert(g_maxTID < MAX_TID);
return retVal;
}
-// Return the size of the underlying struct based on struct type
-static size_t sTypeStructSize(XGL_STRUCTURE_TYPE sType)
-{
- switch (sType)
- {
- case XGL_STRUCTURE_TYPE_APPLICATION_INFO:
- return sizeof(XGL_APPLICATION_INFO);
- case XGL_STRUCTURE_TYPE_DEVICE_CREATE_INFO:
- return sizeof(XGL_DEVICE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO:
- return sizeof(XGL_MEMORY_ALLOC_INFO);
- case XGL_STRUCTURE_TYPE_MEMORY_OPEN_INFO:
- return sizeof(XGL_MEMORY_OPEN_INFO);
- case XGL_STRUCTURE_TYPE_PEER_MEMORY_OPEN_INFO:
- return sizeof(XGL_PEER_MEMORY_OPEN_INFO);
- case XGL_STRUCTURE_TYPE_BUFFER_VIEW_ATTACH_INFO:
- return sizeof(XGL_BUFFER_VIEW_ATTACH_INFO);
- case XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO:
- return sizeof(XGL_IMAGE_VIEW_ATTACH_INFO);
- case XGL_STRUCTURE_TYPE_EVENT_WAIT_INFO:
- return sizeof(XGL_EVENT_WAIT_INFO);
- case XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO:
- return sizeof(XGL_IMAGE_VIEW_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO:
- return sizeof(XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO:
- return sizeof(XGL_DEPTH_STENCIL_VIEW_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO:
- return sizeof(XGL_SHADER_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO:
- return sizeof(XGL_COMPUTE_PIPELINE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO:
- return sizeof(XGL_SAMPLER_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO:
- return sizeof(XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
- return sizeof(XGL_DYNAMIC_VP_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
- return sizeof(XGL_DYNAMIC_RS_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
- return sizeof(XGL_DYNAMIC_CB_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
- return sizeof(XGL_DYNAMIC_DS_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO:
- return sizeof(XGL_CMD_BUFFER_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_EVENT_CREATE_INFO:
- return sizeof(XGL_EVENT_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_FENCE_CREATE_INFO:
- return sizeof(XGL_FENCE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_QUEUE_SEMAPHORE_CREATE_INFO:
- return sizeof(XGL_QUEUE_SEMAPHORE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_QUEUE_SEMAPHORE_OPEN_INFO:
- return sizeof(XGL_QUEUE_SEMAPHORE_OPEN_INFO);
- case XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO:
- return sizeof(XGL_QUERY_POOL_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
- return sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO:
- return sizeof(XGL_GRAPHICS_PIPELINE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
- return sizeof(XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
- return sizeof(XGL_PIPELINE_IA_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
- return sizeof(XGL_PIPELINE_TESS_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
- return sizeof(XGL_PIPELINE_VP_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
- return sizeof(XGL_PIPELINE_RS_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
- return sizeof(XGL_PIPELINE_MS_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
- return sizeof(XGL_PIPELINE_CB_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
- return sizeof(XGL_PIPELINE_DS_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO:
- return sizeof(XGL_IMAGE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_BUFFER_CREATE_INFO:
- return sizeof(XGL_BUFFER_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO:
- return sizeof(XGL_BUFFER_VIEW_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO:
- return sizeof(XGL_FRAMEBUFFER_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO:
- return sizeof(XGL_CMD_BUFFER_BEGIN_INFO);
- case XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO:
- return sizeof(XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO);
- case XGL_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO:
- return sizeof(XGL_RENDER_PASS_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO:
- return sizeof(XGL_LAYER_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_PIPELINE_BARRIER:
- return sizeof(XGL_PIPELINE_BARRIER);
- case XGL_STRUCTURE_TYPE_MEMORY_BARRIER:
- return sizeof(XGL_MEMORY_BARRIER);
- case XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER:
- return sizeof(XGL_BUFFER_MEMORY_BARRIER);
- case XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER:
- return sizeof(XGL_IMAGE_MEMORY_BARRIER);
- case XGL_STRUCTURE_TYPE_DESCRIPTOR_REGION_CREATE_INFO:
- return sizeof(XGL_DESCRIPTOR_REGION_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:
- return sizeof(XGL_UPDATE_SAMPLERS);
- case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
- return sizeof(XGL_UPDATE_SAMPLER_TEXTURES);
- case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:
- return sizeof(XGL_UPDATE_IMAGES);
- case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:
- return sizeof(XGL_UPDATE_BUFFERS);
- case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:
- return sizeof(XGL_UPDATE_AS_COPY);
- case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_BUFFER_INFO:
- return sizeof(XGL_MEMORY_ALLOC_BUFFER_INFO);
- case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO:
- return sizeof(XGL_MEMORY_ALLOC_IMAGE_INFO);
- default:
- return 0;
- }
-}
-// Return the size of the underlying struct based on sType
-static size_t dynStateCreateInfoSize(XGL_STRUCTURE_TYPE sType)
-{
- switch (sType)
- {
- case XGL_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
- return sizeof(XGL_DYNAMIC_VP_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
- return sizeof(XGL_DYNAMIC_RS_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
- return sizeof(XGL_DYNAMIC_DS_STATE_CREATE_INFO);
- case XGL_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
- return sizeof(XGL_DYNAMIC_CB_STATE_CREATE_INFO);
- default:
- return 0;
- }
-}
// Return a string representation of CMD_TYPE enum
static char* cmdTypeToString(CMD_TYPE cmd)
{
pStateNode->pNext = g_pDynamicStateHead[bindPoint];
g_pDynamicStateHead[bindPoint] = pStateNode;
pStateNode->stateObj = state;
- pStateNode->pCreateInfo = (GENERIC_HEADER*)malloc(dynStateCreateInfoSize(pCreateInfo->sType));
+ pStateNode->pCreateInfo = (GENERIC_HEADER*)malloc(get_dynamic_struct_size(pCreateInfo));
#if ALLOC_DEBUG
printf("Alloc2 #%lu pStateNode->pCreateInfo addr(%p)\n", ++g_alloc_count, (void*)pStateNode->pCreateInfo);
#endif
- memcpy(pStateNode->pCreateInfo, pCreateInfo, dynStateCreateInfoSize(pCreateInfo->sType));
+ memcpy(pStateNode->pCreateInfo, pCreateInfo, get_dynamic_struct_size(pCreateInfo));
// VP has embedded ptr so need to handle that as special case
if (XGL_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO == pCreateInfo->sType) {
XGL_DYNAMIC_VP_STATE_CREATE_INFO* pVPCI = (XGL_DYNAMIC_VP_STATE_CREATE_INFO*)pStateNode->pCreateInfo;
GENERIC_HEADER *pTrav = (GENERIC_HEADER*)pCreateInfo->pNext;
while (pTrav) {
// Shadow the struct
- pShadowTrav->pNext = (GENERIC_HEADER*)malloc(sTypeStructSize(pTrav->sType));
+ pShadowTrav->pNext = (GENERIC_HEADER*)malloc(get_dynamic_struct_size(pTrav));
#if ALLOC_DEBUG
printf("Alloc6 #%lu pShadowTrav->pNext addr(%p)\n", ++g_alloc_count, (void*)pShadowTrav->pNext);
#endif
// Typically pNext is const so have to cast to avoid warning when we modify it here
- memcpy((void*)pShadowTrav->pNext, pTrav, sTypeStructSize(pTrav->sType));
+ memcpy((void*)pShadowTrav->pNext, pTrav, get_dynamic_struct_size(pTrav));
pShadowTrav = (GENERIC_HEADER*)pShadowTrav->pNext;
// Special copy of Vtx info as it has embedded array
if (XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO == pTrav->sType) {
if self.struct_dict[s][m]['dyn_array']:
if self.struct_dict[s][m]['full_type'].count('*') > 1:
if not is_type(self.struct_dict[s][m]['type'], 'struct') and not 'char' in self.struct_dict[s][m]['type'].lower():
- sh_funcs.append('%sstructSize += pStruct->%s*(sizeof(%s*) + sizeof(%s));' % (indent, self.struct_dict[s][m]['array_size'], self.struct_dict[s][m]['type'], self.struct_dict[s][m]['type']))
+ if 'ppMemBarriers' == self.struct_dict[s][m]['name']:
+ # TODO : For now be conservative and consider all memBarrier ptrs as largest possible struct
+ sh_funcs.append('%sstructSize += pStruct->%s*(sizeof(%s*) + sizeof(XGL_IMAGE_MEMORY_BARRIER));' % (indent, self.struct_dict[s][m]['array_size'], self.struct_dict[s][m]['type']))
+ else:
+ sh_funcs.append('%sstructSize += pStruct->%s*(sizeof(%s*) + sizeof(%s));' % (indent, self.struct_dict[s][m]['array_size'], self.struct_dict[s][m]['type'], self.struct_dict[s][m]['type']))
else: # This is an array of char* or array of struct ptrs
if not i_decl:
sh_funcs.append('%suint32_t i = 0;' % (indent))
sh_funcs.append('%sstructSize += sizeof(%s)*(1+strlen(pStruct->%s));' % (indent, self.struct_dict[s][m]['type'], self.struct_dict[s][m]['name']))
elif is_type(self.struct_dict[s][m]['type'], 'struct'):
sh_funcs.append('%sstructSize += %s(pStruct->%s);' % (indent, self._get_size_helper_func_name(self.struct_dict[s][m]['type']), self.struct_dict[s][m]['name']))
- else:
+ elif 'void' not in self.struct_dict[s][m]['type'].lower():
sh_funcs.append('%sstructSize += sizeof(%s);' % (indent, self.struct_dict[s][m]['type']))
elif 'size_t' == self.struct_dict[s][m]['type'].lower():
sh_funcs.append('%sstructSize += pStruct->%s;' % (indent, self.struct_dict[s][m]['name']))
indent = ' '
sh_funcs.append('%s}' % (indent))
sh_funcs.append("%sreturn structSize;\n}" % (indent))
- # Now generate generic function to loop over struct chain (or handle generic structs)
- sh_funcs.append('size_t get_struct_chain_size(const void* pStruct)\n{')
- sh_funcs.append(' // Just use XGL_APPLICATION_INFO as struct until actual type is resolved')
- sh_funcs.append(' XGL_APPLICATION_INFO* pNext = (XGL_APPLICATION_INFO*)pStruct;')
- sh_funcs.append(' size_t structSize = 0;')
- sh_funcs.append(' while (pNext) {')
- sh_funcs.append(' switch (pNext->sType) {')
- for e in enum_type_dict:
- if '_STRUCTURE_TYPE' in e:
- for v in sorted(enum_type_dict[e]):
- struct_name = v.replace("_STRUCTURE_TYPE", "")
- sh_funcs.append(' case %s:\n {' % (v))
- sh_funcs.append(' structSize += %s((%s*)pNext);' % (self._get_size_helper_func_name(struct_name), struct_name))
- sh_funcs.append(' break;')
- sh_funcs.append(' }')
- sh_funcs.append(" default:")
- sh_funcs.append(" assert(0);")
- sh_funcs.append(" structSize += 0;")
- sh_funcs.append(' }')
- sh_funcs.append(' pNext = (XGL_APPLICATION_INFO*)pNext->pNext;')
- sh_funcs.append(' }')
- sh_funcs.append(' return structSize;\n}')
+ # Now generate generic functions to loop over entire struct chain (or just handle single generic structs)
+ for follow_chain in [True, False]:
+ if follow_chain:
+ sh_funcs.append('size_t get_struct_chain_size(const void* pStruct)\n{')
+ else:
+ sh_funcs.append('size_t get_dynamic_struct_size(const void* pStruct)\n{')
+ indent = ' '
+ sh_funcs.append('%s// Just use XGL_APPLICATION_INFO as struct until actual type is resolved' % (indent))
+ sh_funcs.append('%sXGL_APPLICATION_INFO* pNext = (XGL_APPLICATION_INFO*)pStruct;' % (indent))
+ sh_funcs.append('%ssize_t structSize = 0;' % (indent))
+ if follow_chain:
+ sh_funcs.append('%swhile (pNext) {' % (indent))
+ indent = ' '
+ sh_funcs.append('%sswitch (pNext->sType) {' % (indent))
+ indent += ' '
+ for e in enum_type_dict:
+ if '_STRUCTURE_TYPE' in e:
+ for v in sorted(enum_type_dict[e]):
+ struct_name = v.replace("_STRUCTURE_TYPE", "")
+ sh_funcs.append('%scase %s:' % (indent, v))
+ sh_funcs.append('%s{' % (indent))
+ indent += ' '
+ sh_funcs.append('%sstructSize += %s((%s*)pNext);' % (indent, self._get_size_helper_func_name(struct_name), struct_name))
+ sh_funcs.append('%sbreak;' % (indent))
+ indent = indent[:-4]
+ sh_funcs.append('%s}' % (indent))
+ sh_funcs.append('%sdefault:' % (indent))
+ indent += ' '
+ sh_funcs.append('%sassert(0);' % (indent))
+ sh_funcs.append('%sstructSize += 0;' % (indent))
+ indent = indent[:-4]
+ indent = indent[:-4]
+ sh_funcs.append('%s}' % (indent))
+ if follow_chain:
+ sh_funcs.append('%spNext = (XGL_APPLICATION_INFO*)pNext->pNext;' % (indent))
+ indent = indent[:-4]
+ sh_funcs.append('%s}' % (indent))
+ sh_funcs.append('%sreturn structSize;\n}' % indent)
return "\n".join(sh_funcs)
def _generateSizeHelperHeader(self):
header.append("#include <%s>\n" % f)
header.append('\n// Function Prototypes\n')
header.append("size_t get_struct_chain_size(const void* pStruct);\n")
+ header.append("size_t get_dynamic_struct_size(const void* pStruct);\n")
return "".join(header)
def _generateHeader(self):