Skip to content

Commit 903a8b7

Browse files
committed
(slang_reflection) Rewrite code from C++11 to C++98
1 parent 9dc9b79 commit 903a8b7

File tree

2 files changed

+95
-66
lines changed

2 files changed

+95
-66
lines changed

gfx/drivers_shader/slang_reflection.cpp

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static const char *texture_semantic_names[] = {
3131
"PassOutput",
3232
"PassFeedback",
3333
"User",
34-
nullptr
34+
NULL
3535
};
3636

3737
static const char *texture_semantic_uniform_names[] = {
@@ -41,7 +41,7 @@ static const char *texture_semantic_uniform_names[] = {
4141
"PassOutputSize",
4242
"PassFeedbackSize",
4343
"UserSize",
44-
nullptr
44+
NULL
4545
};
4646

4747
static const char *semantic_uniform_names[] = {
@@ -74,8 +74,9 @@ static slang_texture_semantic slang_name_to_texture_semantic(
7474
const std::unordered_map<std::string, slang_texture_semantic_map> &semantic_map,
7575
const std::string &name, unsigned *index)
7676
{
77-
auto itr = semantic_map.find(name);
78-
if (itr != end(semantic_map))
77+
std::unordered_map<std::string, slang_texture_semantic_map>::const_iterator itr =
78+
semantic_map.find(name);
79+
if (itr != semantic_map.end())
7980
{
8081
*index = itr->second.index;
8182
return itr->second.semantic;
@@ -89,8 +90,9 @@ static slang_texture_semantic slang_uniform_name_to_texture_semantic(
8990
const std::unordered_map<std::string, slang_texture_semantic_map> &semantic_map,
9091
const std::string &name, unsigned *index)
9192
{
92-
auto itr = semantic_map.find(name);
93-
if (itr != end(semantic_map))
93+
std::unordered_map<std::string, slang_texture_semantic_map>::const_iterator itr =
94+
semantic_map.find(name);
95+
if (itr != semantic_map.end())
9496
{
9597
*index = itr->second.index;
9698
return itr->second.semantic;
@@ -105,21 +107,21 @@ static slang_semantic slang_uniform_name_to_semantic(
105107
const std::string &name, unsigned *index)
106108
{
107109
unsigned i = 0;
108-
auto itr = semantic_map.find(name);
110+
std::unordered_map<std::string, slang_semantic_map>::const_iterator itr =
111+
semantic_map.find(name);
109112

110-
if (itr != end(semantic_map))
113+
if (itr != semantic_map.end())
111114
{
112115
*index = itr->second.index;
113116
return itr->second.semantic;
114117
}
115118

116119
/* No builtin semantics are arrayed. */
117120
*index = 0;
118-
for (auto n : semantic_uniform_names)
121+
for (i = 0; i < sizeof(semantic_uniform_names) / sizeof(semantic_uniform_names[0]); i++)
119122
{
120-
if (name == n)
123+
if (name == semantic_uniform_names[i])
121124
return static_cast<slang_semantic>(i);
122-
i++;
123125
}
124126

125127
return SLANG_INVALID_SEMANTIC;
@@ -140,7 +142,7 @@ static bool set_ubo_texture_offset(
140142
{
141143
resize_minimum(reflection->semantic_textures[semantic], index + 1);
142144
slang_texture_semantic_meta &sem = reflection->semantic_textures[semantic][index];
143-
bool &active = push_constant ? sem.push_constant : sem.uniform;
145+
bool &active = push_constant ? sem.push_constant : sem.uniform;
144146
size_t &active_offset = push_constant ? sem.push_constant_offset : sem.ubo_offset;
145147

146148
if (active)
@@ -209,7 +211,7 @@ static bool set_ubo_offset(
209211
size_t offset, unsigned num_components, bool push_constant)
210212
{
211213
slang_semantic_meta &sem = reflection->semantics[semantic];
212-
bool &active = push_constant ? sem.push_constant : sem.uniform;
214+
bool &active = push_constant ? sem.push_constant : sem.uniform;
213215
size_t &active_offset = push_constant ? sem.push_constant_offset : sem.ubo_offset;
214216

215217
if (active)
@@ -223,7 +225,6 @@ static bool set_ubo_offset(
223225
unsigned(offset));
224226
return false;
225227
}
226-
227228
}
228229

229230
if ( (sem.num_components != num_components) &&
@@ -372,7 +373,8 @@ static bool add_active_buffer_ranges(
372373
{
373374
unsigned i;
374375
/* Get which uniforms are actually in use by this shader. */
375-
auto ranges = compiler.get_active_buffer_ranges(resource.id);
376+
spirv_cross::SmallVector<spirv_cross::BufferRange> ranges =
377+
compiler.get_active_buffer_ranges(resource.id);
376378

377379
for (i = 0; i < ranges.size(); i++)
378380
{
@@ -389,7 +391,8 @@ static bool add_active_buffer_ranges(
389391
*reflection->texture_semantic_uniform_map,
390392
name, &tex_sem_index);
391393

392-
if (tex_sem == SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT && tex_sem_index >= reflection->pass_number)
394+
if (tex_sem == SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT &&
395+
tex_sem_index >= reflection->pass_number)
393396
{
394397
RARCH_ERR("[Slang] Non causal filter chain detected. "
395398
"Shader is trying to use output from pass #%u,"
@@ -447,9 +450,17 @@ static bool add_active_buffer_ranges(
447450

448451

449452
slang_reflection::slang_reflection()
453+
: ubo_size(0),
454+
push_constant_size(0),
455+
ubo_binding(0),
456+
ubo_stage_mask(0),
457+
push_constant_stage_mask(0),
458+
texture_semantic_map(NULL),
459+
texture_semantic_uniform_map(NULL),
460+
semantic_map(NULL),
461+
pass_number(0)
450462
{
451463
unsigned i;
452-
453464
for (i = 0; i < SLANG_NUM_TEXTURE_SEMANTICS; i++)
454465
semantic_textures[i].resize(
455466
slang_texture_semantic_is_array(
@@ -537,14 +548,18 @@ bool slang_reflect(
537548

538549
if (fragment.push_constant_buffers.size() > 1)
539550
{
540-
RARCH_ERR("[Slang] Fragment must use zero or one push cosntant buffer.\n");
551+
RARCH_ERR("[Slang] Fragment must use zero or one push constant buffer.\n");
541552
return false;
542553
}
543554

544-
uint32_t vertex_ubo = vertex.uniform_buffers.empty() ? 0 : (uint32_t)vertex.uniform_buffers[0].id;
545-
uint32_t fragment_ubo = fragment.uniform_buffers.empty() ? 0 : (uint32_t)fragment.uniform_buffers[0].id;
546-
uint32_t vertex_push = vertex.push_constant_buffers.empty() ? 0 : (uint32_t)vertex.push_constant_buffers[0].id;
547-
uint32_t fragment_push = fragment.push_constant_buffers.empty() ? 0 : (uint32_t)fragment.push_constant_buffers[0].id;
555+
uint32_t vertex_ubo = vertex.uniform_buffers.empty()
556+
? 0 : (uint32_t)vertex.uniform_buffers[0].id;
557+
uint32_t fragment_ubo = fragment.uniform_buffers.empty()
558+
? 0 : (uint32_t)fragment.uniform_buffers[0].id;
559+
uint32_t vertex_push = vertex.push_constant_buffers.empty()
560+
? 0 : (uint32_t)vertex.push_constant_buffers[0].id;
561+
uint32_t fragment_push = fragment.push_constant_buffers.empty()
562+
? 0 : (uint32_t)fragment.push_constant_buffers[0].id;
548563

549564
if (vertex_ubo &&
550565
vertex_compiler.get_decoration(
@@ -564,21 +579,21 @@ bool slang_reflect(
564579

565580
unsigned vertex_ubo_binding = vertex_ubo
566581
? vertex_compiler.get_decoration(vertex_ubo, spv::DecorationBinding)
567-
: -1u;
582+
: (unsigned)-1;
568583
unsigned fragment_ubo_binding = fragment_ubo
569584
? fragment_compiler.get_decoration(fragment_ubo, spv::DecorationBinding)
570-
: -1u;
585+
: (unsigned)-1;
571586
bool has_ubo = vertex_ubo || fragment_ubo;
572587

573-
if ( (vertex_ubo_binding != -1u) &&
574-
(fragment_ubo_binding != -1u) &&
588+
if ( (vertex_ubo_binding != (unsigned)-1) &&
589+
(fragment_ubo_binding != (unsigned)-1) &&
575590
(vertex_ubo_binding != fragment_ubo_binding))
576591
{
577592
RARCH_ERR("[Slang] Vertex and fragment uniform buffer must have same binding.\n");
578593
return false;
579594
}
580595

581-
unsigned ubo_binding = (vertex_ubo_binding != -1u)
596+
unsigned ubo_binding = (vertex_ubo_binding != (unsigned)-1)
582597
? vertex_ubo_binding
583598
: fragment_ubo_binding;
584599

@@ -696,7 +711,8 @@ bool slang_reflect(
696711
*reflection->texture_semantic_map,
697712
fragment.sampled_images[i].name, &array_index);
698713

699-
if (index == SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT && array_index >= reflection->pass_number)
714+
if (index == SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT &&
715+
array_index >= reflection->pass_number)
700716
{
701717
RARCH_ERR("[Slang] Non causal filter chain detected. "
702718
"Shader is trying to use output from pass #%u,"
@@ -728,8 +744,10 @@ bool slang_reflect(
728744
for (i = 0; i < SLANG_NUM_TEXTURE_SEMANTICS; i++)
729745
{
730746
unsigned index = 0;
731-
for (auto &sem : reflection->semantic_textures[i])
747+
unsigned j;
748+
for (j = 0; j < reflection->semantic_textures[i].size(); j++)
732749
{
750+
const slang_texture_semantic_meta &sem = reflection->semantic_textures[i][j];
733751
if (sem.texture)
734752
RARCH_LOG("[Slang] %s (#%u)\n",
735753
texture_semantic_names[i], index);
@@ -764,8 +782,10 @@ bool slang_reflect(
764782
for (i = 0; i < SLANG_NUM_TEXTURE_SEMANTICS; i++)
765783
{
766784
unsigned index = 0;
767-
for (auto &sem : reflection->semantic_textures[i])
785+
unsigned j;
786+
for (j = 0; j < reflection->semantic_textures[i].size(); j++)
768787
{
788+
const slang_texture_semantic_meta &sem = reflection->semantic_textures[i][j];
769789
if (sem.uniform)
770790
{
771791
RARCH_LOG("[Slang] %s (#%u) (Offset: %u)\n",
@@ -789,18 +809,14 @@ bool slang_reflect(
789809

790810
for (i = 0; i < reflection->semantic_float_parameters.size(); i++)
791811
{
792-
slang_semantic_meta *param = (slang_semantic_meta*)
793-
&reflection->semantic_float_parameters[i];
794-
795-
if (!param)
796-
continue;
812+
const slang_semantic_meta &param = reflection->semantic_float_parameters[i];
797813

798-
if (param->uniform)
814+
if (param.uniform)
799815
RARCH_LOG("[Slang] #%u (Offset: %u)\n", i,
800-
(unsigned int)param->ubo_offset);
801-
if (param->push_constant)
816+
(unsigned int)param.ubo_offset);
817+
if (param.push_constant)
802818
RARCH_LOG("[Slang] #%u (PushOffset: %u)\n", i,
803-
(unsigned int)param->push_constant_offset);
819+
(unsigned int)param.push_constant_offset);
804820
}
805821
#endif
806822

gfx/drivers_shader/slang_reflection.hpp

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,69 +23,82 @@
2323

2424
struct slang_semantic_location
2525
{
26-
int ubo_vertex = -1;
27-
int push_vertex = -1;
28-
int ubo_fragment = -1;
29-
int push_fragment = -1;
26+
int ubo_vertex;
27+
int push_vertex;
28+
int ubo_fragment;
29+
int push_fragment;
30+
31+
slang_semantic_location()
32+
: ubo_vertex(-1), push_vertex(-1),
33+
ubo_fragment(-1), push_fragment(-1) {}
3034
};
3135

3236
struct slang_texture_semantic_meta
3337
{
34-
size_t ubo_offset = 0;
35-
size_t push_constant_offset = 0;
36-
unsigned binding = 0;
37-
uint32_t stage_mask = 0;
38+
size_t ubo_offset;
39+
size_t push_constant_offset;
40+
unsigned binding;
41+
uint32_t stage_mask;
3842

39-
bool texture = false;
40-
bool uniform = false;
41-
bool push_constant = false;
43+
bool texture;
44+
bool uniform;
45+
bool push_constant;
4246

4347
/* For APIs which need location information ala legacy GL.
4448
* API user fills this struct in. */
4549
slang_semantic_location location;
50+
51+
slang_texture_semantic_meta()
52+
: ubo_offset(0), push_constant_offset(0),
53+
binding(0), stage_mask(0),
54+
texture(false), uniform(false), push_constant(false) {}
4655
};
4756

4857
struct slang_semantic_meta
4958
{
50-
size_t ubo_offset = 0;
51-
size_t push_constant_offset = 0;
52-
unsigned num_components = 0;
53-
bool uniform = false;
54-
bool push_constant = false;
59+
size_t ubo_offset;
60+
size_t push_constant_offset;
61+
unsigned num_components;
62+
bool uniform;
63+
bool push_constant;
5564

5665
/* For APIs which need location information ala legacy GL. */
5766
slang_semantic_location location;
67+
68+
slang_semantic_meta()
69+
: ubo_offset(0), push_constant_offset(0),
70+
num_components(0), uniform(false), push_constant(false) {}
5871
};
5972

6073
struct slang_reflection
6174
{
6275
slang_reflection();
6376

64-
size_t ubo_size = 0;
65-
size_t push_constant_size = 0;
77+
size_t ubo_size;
78+
size_t push_constant_size;
6679

67-
unsigned ubo_binding = 0;
68-
uint32_t ubo_stage_mask = 0;
69-
uint32_t push_constant_stage_mask = 0;
80+
unsigned ubo_binding;
81+
uint32_t ubo_stage_mask;
82+
uint32_t push_constant_stage_mask;
7083

7184
std::vector<slang_texture_semantic_meta>
7285
semantic_textures[SLANG_NUM_TEXTURE_SEMANTICS];
7386
slang_semantic_meta semantics[SLANG_NUM_SEMANTICS];
7487
std::vector<slang_semantic_meta> semantic_float_parameters;
7588

76-
const std::unordered_map<std::string, slang_texture_semantic_map> *texture_semantic_map = nullptr;
77-
const std::unordered_map<std::string, slang_texture_semantic_map> *texture_semantic_uniform_map = nullptr;
78-
const std::unordered_map<std::string, slang_semantic_map> *semantic_map = nullptr;
79-
unsigned pass_number = 0;
89+
const std::unordered_map<std::string, slang_texture_semantic_map> *texture_semantic_map;
90+
const std::unordered_map<std::string, slang_texture_semantic_map> *texture_semantic_uniform_map;
91+
const std::unordered_map<std::string, slang_semantic_map> *semantic_map;
92+
unsigned pass_number;
8093
};
8194

8295
template <typename P>
8396
static bool slang_set_unique_map(std::unordered_map<std::string, P> &m,
8497
const std::string &name, const P &p)
8598
{
86-
auto itr = m.find(name);
99+
typename std::unordered_map<std::string, P>::iterator itr = m.find(name);
87100
/* Alias already exists? */
88-
if (itr != end(m))
101+
if (itr != m.end())
89102
return false;
90103
m[name] = p;
91104
return true;

0 commit comments

Comments
 (0)