aboutsummaryrefslogtreecommitdiff
path: root/source/ext_inst.cpp
diff options
context:
space:
mode:
authorLei Zhang <antiagainst@gmail.com>2017-09-21 17:24:57 -0400
committerDavid Neto <dneto@google.com>2017-09-26 10:59:15 -0400
commit16981f87fe93f11b554fb2bfcacbdc160d7a6c8b (patch)
tree69e1ee4957b64aa538c7e5aaa791a5edb0f5373e /source/ext_inst.cpp
parentc25b5bea352d269ce93ecb5d3c636ca67e8cf341 (diff)
downloadspirv-tools-16981f87fe93f11b554fb2bfcacbdc160d7a6c8b.tar.gz
Avoid using global static variables
Previously we have several grammar tables defined as global static variables and these grammar table entries contains non-POD struct fields (CapabilitySet/ExtensionSet). The initialization of these non-POD struct fields may require calling operator new. If used as a library and the caller defines its own operator new, things can screw up. This pull request changes all global static variables into function static variables, which is lazy evaluated in a thread safe way as guaranteed by C++11.
Diffstat (limited to 'source/ext_inst.cpp')
-rw-r--r--source/ext_inst.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/source/ext_inst.cpp b/source/ext_inst.cpp
index 12930f19..71f72fc9 100644
--- a/source/ext_inst.cpp
+++ b/source/ext_inst.cpp
@@ -23,33 +23,34 @@
#include "macro.h"
-static const spv_ext_inst_desc_t glslStd450Entries_1_0[] = {
+spv_result_t spvExtInstTableGet(spv_ext_inst_table* pExtInstTable,
+ spv_target_env env) {
+ if (!pExtInstTable) return SPV_ERROR_INVALID_POINTER;
+
+ static const spv_ext_inst_desc_t glslStd450Entries_1_0[] = {
#include "glsl.std.450.insts-1.0.inc"
-};
+ };
-static const spv_ext_inst_desc_t openclEntries_1_0[] = {
+ static const spv_ext_inst_desc_t openclEntries_1_0[] = {
#include "opencl.std.insts-1.0.inc"
-};
+ };
-static const spv_ext_inst_desc_t spv_amd_shader_explicit_vertex_parameter_entries[] = {
+ static const spv_ext_inst_desc_t
+ spv_amd_shader_explicit_vertex_parameter_entries[] = {
#include "spv-amd-shader-explicit-vertex-parameter.insts.inc"
-};
+ };
-static const spv_ext_inst_desc_t spv_amd_shader_trinary_minmax_entries[] = {
+ static const spv_ext_inst_desc_t spv_amd_shader_trinary_minmax_entries[] = {
#include "spv-amd-shader-trinary-minmax.insts.inc"
-};
+ };
-static const spv_ext_inst_desc_t spv_amd_gcn_shader_entries[] = {
+ static const spv_ext_inst_desc_t spv_amd_gcn_shader_entries[] = {
#include "spv-amd-gcn-shader.insts.inc"
-};
+ };
-static const spv_ext_inst_desc_t spv_amd_shader_ballot_entries[] = {
+ static const spv_ext_inst_desc_t spv_amd_shader_ballot_entries[] = {
#include "spv-amd-shader-ballot.insts.inc"
-};
-
-spv_result_t spvExtInstTableGet(spv_ext_inst_table* pExtInstTable,
- spv_target_env env) {
- if (!pExtInstTable) return SPV_ERROR_INVALID_POINTER;
+ };
static const spv_ext_inst_group_t groups_1_0[] = {
{SPV_EXT_INST_TYPE_GLSL_STD_450, ARRAY_SIZE(glslStd450Entries_1_0),
@@ -57,13 +58,16 @@ spv_result_t spvExtInstTableGet(spv_ext_inst_table* pExtInstTable,
{SPV_EXT_INST_TYPE_OPENCL_STD, ARRAY_SIZE(openclEntries_1_0),
openclEntries_1_0},
{SPV_EXT_INST_TYPE_SPV_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER,
- ARRAY_SIZE(spv_amd_shader_explicit_vertex_parameter_entries), spv_amd_shader_explicit_vertex_parameter_entries},
+ ARRAY_SIZE(spv_amd_shader_explicit_vertex_parameter_entries),
+ spv_amd_shader_explicit_vertex_parameter_entries},
{SPV_EXT_INST_TYPE_SPV_AMD_SHADER_TRINARY_MINMAX,
- ARRAY_SIZE(spv_amd_shader_trinary_minmax_entries), spv_amd_shader_trinary_minmax_entries},
+ ARRAY_SIZE(spv_amd_shader_trinary_minmax_entries),
+ spv_amd_shader_trinary_minmax_entries},
{SPV_EXT_INST_TYPE_SPV_AMD_GCN_SHADER,
ARRAY_SIZE(spv_amd_gcn_shader_entries), spv_amd_gcn_shader_entries},
{SPV_EXT_INST_TYPE_SPV_AMD_SHADER_BALLOT,
- ARRAY_SIZE(spv_amd_shader_ballot_entries), spv_amd_shader_ballot_entries},
+ ARRAY_SIZE(spv_amd_shader_ballot_entries),
+ spv_amd_shader_ballot_entries},
};
static const spv_ext_inst_table_t table_1_0 = {ARRAY_SIZE(groups_1_0),