scripts: Fix VkShaderModuleCreateInfo safe struct
authorMike Schuchardt <mikes@lunarg.com>
Mon, 4 Sep 2017 17:38:42 +0000 (11:38 -0600)
committerMike Schuchardt <mikes@lunarg.com>
Thu, 7 Sep 2017 21:19:31 +0000 (14:19 -0700)
Allocate and copy the entire shader program instead of just the first 4
bytes.

Change-Id: I24dd136d59952f9e8b690bf4fe1702106482a3be

scripts/helper_file_generator.py

index f486a8d777024784600db623789f6a59665d40a7..a9d9390fff6ed689dde182c277380a00f316fce3 100644 (file)
@@ -787,7 +787,15 @@ class HelperFileOutputGenerator(OutputGenerator):
                                     '        break;\n'
                                     '        default:\n'
                                     '        break;\n'
+                                    '    }\n',
+                                    'VkShaderModuleCreateInfo' :
+                                    '    if (in_struct->pCode) {\n'
+                                    '        pCode = reinterpret_cast<uint32_t *>(new uint8_t[codeSize]);\n'
+                                    '        memcpy((void *)pCode, (void *)in_struct->pCode, codeSize);\n'
                                     '    }\n'}
+            custom_destruct_txt = {'VkShaderModuleCreateInfo' :
+                                   '    if (pCode)\n'
+                                   '        delete[] reinterpret_cast<const uint8_t *>(pCode);\n' }
 
             for member in item.members:
                 m_type = member.type
@@ -864,6 +872,8 @@ class HelperFileOutputGenerator(OutputGenerator):
                 init_list = init_list[:-1] # hack off final comma
             if item.name in custom_construct_txt:
                 construct_txt = custom_construct_txt[item.name]
+            if item.name in custom_destruct_txt:
+                destruct_txt = custom_destruct_txt[item.name]
             safe_struct_body.append("\n%s::%s(const %s* in_struct) :%s\n{\n%s}" % (ss_name, ss_name, item.name, init_list, construct_txt))
             if '' != default_init_list:
                 default_init_list = " :%s" % (default_init_list[:-1])