Skip to content

Commit 5515446

Browse files
committed
(gfx/drivers_shader) Replace stdstring versions
1 parent 6e99451 commit 5515446

2 files changed

Lines changed: 51 additions & 71 deletions

File tree

gfx/drivers_shader/glslang_util.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ enum slang_texture_semantic slang_name_to_texture_semantic_array(
184184
return semantic;
185185
}
186186
}
187-
else if (string_is_equal(name, *names))
187+
else if (strcmp(name, *names) == 0)
188188
{
189189
*index = 0;
190190
return semantic;
@@ -194,9 +194,8 @@ enum slang_texture_semantic slang_name_to_texture_semantic_array(
194194
}
195195

196196
/* -------------------------------------------------------------------
197-
* glslang_read_shader_file — rewritten to use shader_line_buf
197+
* glslang_read_shader_file
198198
* ------------------------------------------------------------------- */
199-
200199
bool glslang_read_shader_file(const char *path,
201200
struct shader_line_buf *output, bool root_file, bool is_optional)
202201
{
@@ -209,12 +208,12 @@ bool glslang_read_shader_file(const char *path,
209208
tmp[0] = '\0';
210209

211210
/* Sanity check */
212-
if (string_is_empty(path) || !output)
211+
if (!path || path[0] == '\0' || !output)
213212
return false;
214213

215214
basename = path_basename_nocompression(path);
216215

217-
if (string_is_empty(basename))
216+
if (!basename || basename[0] == '\0')
218217
return false;
219218

220219
/* Read file contents */
@@ -239,7 +238,7 @@ bool glslang_read_shader_file(const char *path,
239238
/* If this is the 'parent' shader file and a slang file,
240239
* ensure that first line is a 'VERSION' string */
241240
bool check_version = root_file
242-
&& string_is_equal(path_get_extension(path), "slang");
241+
&& (strcmp(path_get_extension(path), "slang") == 0);
243242

244243
while (*cursor != '\0')
245244
{
@@ -259,7 +258,7 @@ bool glslang_read_shader_file(const char *path,
259258

260259
if (check_version)
261260
{
262-
if (strncmp("#version ", line_start, STRLEN_CONST("#version ")))
261+
if (strncmp("#version ", line_start, sizeof("#version ")-1))
263262
{
264263
RARCH_ERR("[Slang] First line of the shader must contain a valid "
265264
"#version string.\n");
@@ -277,16 +276,16 @@ bool glslang_read_shader_file(const char *path,
277276
* errors easier. */
278277
if (!shader_line_buf_append(output,
279278
"#extension GL_GOOGLE_cpp_style_line_directive : require",
280-
STRLEN_CONST("#extension GL_GOOGLE_cpp_style_line_directive : require")))
279+
sizeof("#extension GL_GOOGLE_cpp_style_line_directive : require")-1))
281280
{
282281
*newline = saved;
283282
goto cleanup;
284283
}
285284

286285
/* Append feature defines */
287-
if (!shader_line_buf_append(output, "#define _HAS_ORIGINALASPECT_UNIFORMS", STRLEN_CONST("#define _HAS_ORIGINALASPECT_UNIFORMS"))
288-
|| !shader_line_buf_append(output, "#define _HAS_FRAMETIME_UNIFORMS", STRLEN_CONST("#define _HAS_FRAMETIME_UNIFORMS"))
289-
|| !shader_line_buf_append(output, "#define _HAS_SENSOR_UNIFORMS", STRLEN_CONST("#define _HAS_SENSOR_UNIFORMS")))
286+
if (!shader_line_buf_append(output, "#define _HAS_ORIGINALASPECT_UNIFORMS", sizeof("#define _HAS_ORIGINALASPECT_UNIFORMS")-1)
287+
|| !shader_line_buf_append(output, "#define _HAS_FRAMETIME_UNIFORMS", sizeof("#define _HAS_FRAMETIME_UNIFORMS")-1)
288+
|| !shader_line_buf_append(output, "#define _HAS_SENSOR_UNIFORMS", sizeof("#define _HAS_SENSOR_UNIFORMS")-1))
290289
{
291290
*newline = saved;
292291
goto cleanup;
@@ -309,9 +308,9 @@ bool glslang_read_shader_file(const char *path,
309308
/* Non-root or non-slang: emit feature defines + #line once */
310309
if (root_file)
311310
{
312-
if (!shader_line_buf_append(output, "#define _HAS_ORIGINALASPECT_UNIFORMS", STRLEN_CONST("#define _HAS_ORIGINALASPECT_UNIFORMS"))
313-
|| !shader_line_buf_append(output, "#define _HAS_FRAMETIME_UNIFORMS", STRLEN_CONST("#define _HAS_FRAMETIME_UNIFORMS"))
314-
|| !shader_line_buf_append(output, "#define _HAS_SENSOR_UNIFORMS", STRLEN_CONST("#define _HAS_SENSOR_UNIFORMS")))
311+
if (!shader_line_buf_append(output, "#define _HAS_ORIGINALASPECT_UNIFORMS", sizeof("#define _HAS_ORIGINALASPECT_UNIFORMS")-1)
312+
|| !shader_line_buf_append(output, "#define _HAS_FRAMETIME_UNIFORMS", sizeof("#define _HAS_FRAMETIME_UNIFORMS")-1)
313+
|| !shader_line_buf_append(output, "#define _HAS_SENSOR_UNIFORMS", sizeof("#define _HAS_SENSOR_UNIFORMS")-1))
315314
{
316315
*newline = saved;
317316
goto cleanup;
@@ -326,9 +325,9 @@ bool glslang_read_shader_file(const char *path,
326325
}
327326
else
328327
{
329-
if (!shader_line_buf_append(output, "#define _HAS_ORIGINALASPECT_UNIFORMS", STRLEN_CONST("#define _HAS_ORIGINALASPECT_UNIFORMS"))
330-
|| !shader_line_buf_append(output, "#define _HAS_FRAMETIME_UNIFORMS", STRLEN_CONST("#define _HAS_FRAMETIME_UNIFORMS"))
331-
|| !shader_line_buf_append(output, "#define _HAS_SENSOR_UNIFORMS", STRLEN_CONST("#define _HAS_SENSOR_UNIFORMS")))
328+
if (!shader_line_buf_append(output, "#define _HAS_ORIGINALASPECT_UNIFORMS", sizeof("#define _HAS_ORIGINALASPECT_UNIFORMS")-1)
329+
|| !shader_line_buf_append(output, "#define _HAS_FRAMETIME_UNIFORMS", sizeof("#define _HAS_FRAMETIME_UNIFORMS")-1)
330+
|| !shader_line_buf_append(output, "#define _HAS_SENSOR_UNIFORMS", sizeof("#define _HAS_SENSOR_UNIFORMS")-1))
332331
{
333332
*newline = saved;
334333
goto cleanup;
@@ -356,16 +355,16 @@ bool glslang_read_shader_file(const char *path,
356355
/* Process the line */
357356
{
358357
bool include_optional = !strncmp("#pragma include_optional ",
359-
line_start, STRLEN_CONST("#pragma include_optional "));
358+
line_start, sizeof("#pragma include_optional ")-1);
360359

361-
if ( !strncmp("#include ", line_start, STRLEN_CONST("#include "))
360+
if ( !strncmp("#include ", line_start, sizeof("#include ")-1)
362361
|| include_optional)
363362
{
364363
char include_path[PATH_MAX_LENGTH];
365364
char *include_file = slang_get_include_file(
366365
line_start, strlen(line_start));
367366

368-
if (string_is_empty(include_file))
367+
if (!include_file || include_file[0] == '\0')
369368
{
370369
RARCH_ERR("[Slang] Invalid include statement \"%s\".\n",
371370
line_start);
@@ -393,8 +392,8 @@ bool glslang_read_shader_file(const char *path,
393392
if (!shader_line_buf_append_str(output, tmp))
394393
goto cleanup;
395394
}
396-
else if ( !strncmp("#endif", line_start, STRLEN_CONST("#endif"))
397-
|| !strncmp("#pragma", line_start, STRLEN_CONST("#pragma")))
395+
else if ( !strncmp("#endif", line_start, sizeof("#endif")-1)
396+
|| !strncmp("#pragma", line_start, sizeof("#pragma")-1))
398397
{
399398
if (!shader_line_buf_append_str(output, line_start))
400399
{
@@ -483,8 +482,13 @@ const char *glslang_format_to_string(enum glslang_format fmt)
483482

484483
enum glslang_format glslang_find_format(const char *fmt)
485484
{
485+
size_t len = strlen(fmt);
486486
#undef FMT
487-
#define FMT(x) if (string_is_equal(fmt, #x)) return SLANG_FORMAT_ ## x
487+
#define FMT(x) do { \
488+
static const char s[] = #x; \
489+
if (sizeof(s) - 1 == len && memcmp(fmt, s, sizeof(s) - 1) == 0) \
490+
return SLANG_FORMAT_ ## x; \
491+
} while(0)
488492
FMT(R8_UNORM);
489493
FMT(R8_UINT);
490494
FMT(R8_SINT);
@@ -495,10 +499,8 @@ enum glslang_format glslang_find_format(const char *fmt)
495499
FMT(R8G8B8A8_UINT);
496500
FMT(R8G8B8A8_SINT);
497501
FMT(R8G8B8A8_SRGB);
498-
499502
FMT(A2B10G10R10_UNORM_PACK32);
500503
FMT(A2B10G10R10_UINT_PACK32);
501-
502504
FMT(R16_UINT);
503505
FMT(R16_SINT);
504506
FMT(R16_SFLOAT);
@@ -508,7 +510,6 @@ enum glslang_format glslang_find_format(const char *fmt)
508510
FMT(R16G16B16A16_UINT);
509511
FMT(R16G16B16A16_SINT);
510512
FMT(R16G16B16A16_SFLOAT);
511-
512513
FMT(R32_UINT);
513514
FMT(R32_SINT);
514515
FMT(R32_SFLOAT);
@@ -518,7 +519,6 @@ enum glslang_format glslang_find_format(const char *fmt)
518519
FMT(R32G32B32A32_UINT);
519520
FMT(R32G32B32A32_SINT);
520521
FMT(R32G32B32A32_SFLOAT);
521-
522522
return SLANG_FORMAT_UNKNOWN;
523523
}
524524

gfx/drivers_shader/slang_process.cpp

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
#include <compat/strl.h>
2121
#include <retro_miscellaneous.h>
2222
#include <string>
23-
#include <stdio.h>
2423
#include <stdint.h>
2524
#include <vector>
26-
#include <string/stdstring.h>
2725

2826
#include "glslang_util.h"
2927
#if defined(HAVE_GLSLANG)
@@ -468,105 +466,94 @@ static std::string build_stage_source(
468466
bool active = true;
469467
if (!lines || lines->num_lines < 1)
470468
return "";
471-
/* Reserve a rough estimate to reduce reallocations */
472469
str.reserve(lines->len);
473-
474470
/* Version header (line 0). */
475471
str.append(shader_line_buf_get(lines, 0));
476472
str.append("\n");
477-
478473
for (i = 1; i < lines->num_lines; i++)
479474
{
480475
const char *line = shader_line_buf_get(lines, i);
481-
482-
if (string_starts_with_size(line, "#pragma", STRLEN_CONST("#pragma")))
476+
if (!memcmp(line, "#pragma", sizeof("#pragma")-1))
483477
{
484-
/* Identify 'stage' (fragment/vertex) */
485-
if (!strncmp("#pragma stage ", line, STRLEN_CONST("#pragma stage ")))
478+
if (!memcmp(line, "#pragma stage ", sizeof("#pragma stage ")-1))
486479
{
487-
if (!string_is_empty(stage))
480+
if (stage && *stage)
488481
{
489482
char expected[128];
490483
size_t _len = strlcpy(expected, "#pragma stage ", sizeof(expected));
491484
strlcpy(expected + _len, stage, sizeof(expected) - _len);
492-
active = string_is_equal(expected, line);
485+
active = !strcmp(expected, line);
493486
}
494487
}
495488
else if (
496-
!strncmp("#pragma name ", line,
497-
STRLEN_CONST("#pragma name "))
498-
|| !strncmp("#pragma format ", line,
499-
STRLEN_CONST("#pragma format ")))
489+
!memcmp(line, "#pragma name ", sizeof("#pragma name ")-1)
490+
|| !memcmp(line, "#pragma format ", sizeof("#pragma format ")-1))
500491
{
501492
/* Ignore */
502493
}
503494
else if (active)
495+
{
504496
str.append(line);
497+
str.append("\n");
498+
}
505499
}
506500
else if (active)
501+
{
507502
str.append(line);
508-
509-
str.append("\n");
503+
str.append("\n");
504+
}
510505
}
511-
512506
return str;
513507
}
514508

515509
static bool glslang_parse_meta(const struct shader_line_buf *lines,
516-
glslang_meta *meta)
510+
glslang_meta *meta)
517511
{
518512
char id[64];
519513
char desc[64];
520514
size_t i;
521-
522515
id[0] = '\0';
523516
desc[0] = '\0';
524-
525517
for (i = 0; i < lines->num_lines; i++)
526518
{
527519
const char *line = shader_line_buf_get(lines, i);
528-
529-
if (string_starts_with_size(line, "#pragma", STRLEN_CONST("#pragma")))
520+
if (!line)
521+
continue;
522+
if (!memcmp(line, "#pragma", sizeof("#pragma")-1))
530523
{
531524
/* Check for shader identifier */
532-
if (!strncmp("#pragma name ", line,
533-
STRLEN_CONST("#pragma name ")))
525+
if (!memcmp(line, "#pragma name ",
526+
sizeof("#pragma name ")-1))
534527
{
535528
const char *str = NULL;
536-
537529
if (!meta->name.empty())
538530
{
539531
RARCH_ERR("[Slang] Trying to declare multiple names for file.\n");
540532
return false;
541533
}
542-
543-
str = line + STRLEN_CONST("#pragma name ");
534+
str = line + (sizeof("#pragma name ")-1);
544535
while (*str == ' ')
545536
str++;
546-
547537
meta->name = str;
548538
}
549539
/* Check for shader parameters */
550-
else if (!strncmp("#pragma parameter ", line,
551-
STRLEN_CONST("#pragma parameter ")))
540+
else if (!memcmp(line, "#pragma parameter ",
541+
sizeof("#pragma parameter ")-1))
552542
{
553543
float initial, minimum, maximum, step;
554544
int ret = sscanf(
555545
line, "#pragma parameter %63s \"%63[^\"]\" %f %f %f %f",
556546
id, desc, &initial, &minimum, &maximum, &step);
557-
558547
if (ret == 5)
559548
{
560549
step = 0.1f * (maximum - minimum);
561550
ret = 6;
562551
}
563-
564552
if (ret == 6)
565553
{
566554
bool parameter_found = false;
567555
size_t parameter_index = 0;
568556
size_t j;
569-
570557
for (j = 0; j < meta->parameters.size(); j++)
571558
{
572559
/* Note: LHS is a std:string, RHS is a C string.
@@ -578,14 +565,12 @@ static bool glslang_parse_meta(const struct shader_line_buf *lines,
578565
break;
579566
}
580567
}
581-
582568
/* Allow duplicate #pragma parameter, but only
583569
* if they are exactly the same. */
584570
if (parameter_found)
585571
{
586572
const glslang_parameter *parameter =
587573
&meta->parameters[parameter_index];
588-
589574
if ( (parameter->desc != desc)
590575
|| (parameter->initial != initial)
591576
|| (parameter->minimum != minimum)
@@ -608,23 +593,19 @@ static bool glslang_parse_meta(const struct shader_line_buf *lines,
608593
}
609594
}
610595
/* Check for framebuffer format */
611-
else if (!strncmp("#pragma format ", line,
612-
STRLEN_CONST("#pragma format ")))
596+
else if (!memcmp(line, "#pragma format ",
597+
sizeof("#pragma format ")-1))
613598
{
614599
const char *str = NULL;
615-
616600
if (meta->rt_format != SLANG_FORMAT_UNKNOWN)
617601
{
618602
RARCH_ERR("[Slang] Trying to declare format multiple times for file.\n");
619603
return false;
620604
}
621-
622-
str = line + STRLEN_CONST("#pragma format ");
605+
str = line + (sizeof("#pragma format ")-1);
623606
while (*str == ' ')
624607
str++;
625-
626608
meta->rt_format = glslang_find_format(str);
627-
628609
if (meta->rt_format == SLANG_FORMAT_UNKNOWN)
629610
{
630611
RARCH_ERR("[Slang] Failed to find format \"%s\".\n", str);
@@ -633,7 +614,6 @@ static bool glslang_parse_meta(const struct shader_line_buf *lines,
633614
}
634615
}
635616
}
636-
637617
return true;
638618
}
639619

0 commit comments

Comments
 (0)