Skip to content

Commit a72e76e

Browse files
committed
RetroFX: updates
1 parent 0de3282 commit a72e76e

20 files changed

Lines changed: 91 additions & 89 deletions

thirdparty/slang/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ target_sources(slang PRIVATE
3232
)
3333
target_include_directories(slang PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
3434
target_link_libraries(slang PUBLIC godot-glslang spirv-cross icu4c)
35+
target_compile_features(slang PUBLIC cxx_std_20)
3536
target_compile_options(slang PRIVATE -fexceptions)
3637
set_target_properties(slang PROPERTIES CXX_STANDARD 20 C_STANDARD 11)

thirdparty/slang/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ target_sources(slang PRIVATE
4343
)
4444

4545
target_link_libraries(slang PRIVATE icu4c glslang spirv-cross)
46+
target_compile_features(slang PUBLIC cxx_std_20)
4647

4748
add_executable(slang_test test.cpp)
4849
target_link_libraries(slang_test PRIVATE slang icu4c glslang spirv-cross)

thirdparty/slang/src/ShaderModel.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "ShaderModel.h"
66
#include "scanner.h"
7-
#include "thirdparty/simdutf/simdutf.h"
87
#include "u32string.h"
98

109
#include <icu4c/common/unicode/uchar.h>

thirdparty/slang/src/ShaderModel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct ShaderPassModel {
5858
}
5959
}
6060

61-
ShaderPassModel() {}
61+
ShaderPassModel() : pass(0) {}
6262
ShaderPassModel(int p_pass, fs::path const &p_shader) :
6363
pass(p_pass), shader(p_shader) {}
6464
~ShaderPassModel() {}
@@ -80,7 +80,7 @@ struct ShaderParameterModel {
8080
u32string name;
8181
double value;
8282

83-
ShaderParameterModel() {}
83+
ShaderParameterModel() : value(0) {}
8484
ShaderParameterModel(const u32string &p_name, double p_value) :
8585
name(p_name), value(p_value) {}
8686
};

thirdparty/slang/src/ShaderPass.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ struct ShaderPass {
4848
}
4949

5050
ShaderPass(fs::path const &p_path, const ShaderPassModel &p_model);
51-
ShaderPass() {};
51+
ShaderPass() :
52+
index(0),
53+
frame_count_mod(0),
54+
filter(compiled::Filter::UNSPECIFIED),
55+
wrap_mode(compiled::Wrap::BORDER),
56+
is_float(false),
57+
is_sRGB(false),
58+
is_mipmap(false) {}
5259
};
5360

5461
} // namespace slang

thirdparty/slang/src/ShaderPassCompiler.cpp

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace slang {
2020
using STS = compiled::ShaderTextureSemantic;
2121
using SBS = compiled::ShaderBufferSemantic;
2222

23-
result::Result<compiled::Shader> ShaderPassCompiler::compile(const ShaderCompilerOptions &p_options) {
23+
result::Result<compiled::Shader> ShaderPassCompiler::compile(const ShaderCompilerOptions &p_options) const {
2424
std::vector<compiled::ShaderPass> passes;
2525
for (ShaderPass &pass : shader->passes) {
2626
// Compile the pass
@@ -88,7 +88,7 @@ result::Result<compiled::Shader> ShaderPassCompiler::compile(const ShaderCompile
8888
};
8989
}
9090

91-
result::Result<compiled::ShaderPass> ShaderPassCompiler::compile_pass(ShaderPass &p_pass, const ShaderCompilerOptions &p_options) {
91+
result::Result<compiled::ShaderPass> ShaderPassCompiler::compile_pass(ShaderPass &p_pass, const ShaderCompilerOptions &p_options) const {
9292
auto res = make_compilers_for_pass(p_pass, p_options);
9393
if (res.is_err()) {
9494
return res.take_err();
@@ -142,13 +142,6 @@ result::Result<compiled::ShaderPass> ShaderPassCompiler::compile_pass(ShaderPass
142142
};
143143
}
144144

145-
static spirv_cross::CompilerGLSL::Options default_options() {
146-
spirv_cross::CompilerGLSL::Options options;
147-
options.fragment.default_float_precision = spirv_cross::CompilerGLSL::Options::Precision::Highp;
148-
options.fragment.default_int_precision = spirv_cross::CompilerGLSL::Options::Precision::Highp;
149-
return options;
150-
}
151-
152145
static Compiler compiler_from_spirv(std::vector<uint32_t> &&p_spirv) {
153146
spirv_cross::Parser parser(std::move(p_spirv));
154147
parser.parse();
@@ -194,7 +187,7 @@ result::Result<std::vector<uint32_t>> ShaderPassCompiler::ir_for_pass(ShaderPass
194187

195188
auto messages = (EShMessages)(EShMsgSpvRules | EShMsgVulkanRules | EShMsgDebugInfo);
196189

197-
const int DefaultVersion = 110;
190+
constexpr int DefaultVersion = 110;
198191

199192
if (!glsl.parse(GetDefaultResources(), DefaultVersion, false, messages)) {
200193
std::string error = glsl.getInfoLog();
@@ -271,7 +264,7 @@ result::Result<ShaderSymbols> ShaderPassCompiler::make_symbols() const {
271264
return sym;
272265
}
273266

274-
bool ShaderPassCompiler::validate_resources(spirv_cross::ShaderResources &p_vert, spirv_cross::ShaderResources &p_frag) {
267+
bool ShaderPassCompiler::validate_resources(const spirv_cross::ShaderResources &p_vert, const spirv_cross::ShaderResources &p_frag) {
275268
return p_vert.sampled_images.empty() &&
276269
p_vert.storage_buffers.empty() &&
277270
p_vert.subpass_inputs.empty() &&
@@ -482,19 +475,19 @@ error::ErrorOpt ShaderPassCompiler::add_active_buffer_ranges(ShaderPassReflectio
482475
return {};
483476
}
484477

485-
compiled::UBOBufferDescriptor ShaderPassCompiler::make_ubo_descriptor(slang::ShaderPassReflection &p_ref) const {
478+
compiled::UBOBufferDescriptor ShaderPassCompiler::make_ubo_descriptor(slang::ShaderPassReflection &p_ref) {
486479
auto desc = make_descriptors(p_ref, ShaderBufferSemanticMeta::UBO);
487480

488481
return compiled::UBOBufferDescriptor(p_ref.ubo.binding, (compiled::Stage)p_ref.ubo.stage, p_ref.ubo.size, desc);
489482
}
490483

491-
compiled::PushBufferDescriptor ShaderPassCompiler::make_push_descriptor(slang::ShaderPassReflection &p_ref) const {
484+
compiled::PushBufferDescriptor ShaderPassCompiler::make_push_descriptor(slang::ShaderPassReflection &p_ref) {
492485
auto desc = make_descriptors(p_ref, ShaderBufferSemanticMeta::PUSH);
493486

494487
return compiled::PushBufferDescriptor((compiled::Stage)p_ref.push.stage, p_ref.push.size, desc);
495488
}
496489

497-
std::vector<compiled::BufferUniformDescriptor> ShaderPassCompiler::make_descriptors(slang::ShaderPassReflection &p_ref, ShaderBufferSemanticMeta::OffsetType p_type) const {
490+
std::vector<compiled::BufferUniformDescriptor> ShaderPassCompiler::make_descriptors(const slang::ShaderPassReflection &p_ref, ShaderBufferSemanticMeta::OffsetType p_type) {
498491
// Find bound global semantics, like MVP, FrameCount, etc
499492
std::vector<compiled::BufferUniformDescriptor> descriptors;
500493
for (auto &kv : p_ref.semantics) {
@@ -503,10 +496,10 @@ std::vector<compiled::BufferUniformDescriptor> ShaderPassCompiler::make_descript
503496
if (auto offset = meta->get_offset(p_type); offset.has_value()) {
504497
descriptors.push_back(
505498
compiled::BufferUniformDescriptor(sem,
506-
std::nullopt,
507-
meta->name,
508-
meta->number_of_components * sizeof(float),
509-
offset.value()));
499+
std::nullopt,
500+
meta->name,
501+
meta->number_of_components * sizeof(float),
502+
offset.value()));
510503
}
511504
}
512505

@@ -516,10 +509,10 @@ std::vector<compiled::BufferUniformDescriptor> ShaderPassCompiler::make_descript
516509
if (auto offset = meta->get_offset(p_type); offset.has_value()) {
517510
descriptors.push_back(
518511
compiled::BufferUniformDescriptor(SBS::FLOAT_PARAMETER,
519-
meta->index,
520-
meta->name,
521-
meta->number_of_components * sizeof(float),
522-
offset.value()));
512+
meta->index,
513+
meta->name,
514+
meta->number_of_components * sizeof(float),
515+
offset.value()));
523516
}
524517
}
525518

@@ -532,18 +525,18 @@ std::vector<compiled::BufferUniformDescriptor> ShaderPassCompiler::make_descript
532525
if (auto offset = meta->get_offset(p_type); offset.has_value()) {
533526
descriptors.push_back(
534527
compiled::BufferUniformDescriptor(sem,
535-
meta->index,
536-
meta->name,
537-
4 * sizeof(float), // these are always vec4
538-
offset.value()));
528+
meta->index,
529+
meta->name,
530+
4 * sizeof(float), // these are always vec4
531+
offset.value()));
539532
}
540533
}
541534
}
542535

543536
return descriptors;
544537
}
545538

546-
std::vector<compiled::TextureDescriptor> ShaderPassCompiler::make_textures(ShaderPassReflection &p_ref, ShaderSymbols &p_sym) const {
539+
std::vector<compiled::TextureDescriptor> ShaderPassCompiler::make_textures(const ShaderPassReflection &p_ref, ShaderSymbols &p_sym) const {
547540
std::vector<compiled::TextureDescriptor> textures;
548541

549542
for (auto &kv : p_ref.textures) {
@@ -557,11 +550,11 @@ std::vector<compiled::TextureDescriptor> ShaderPassCompiler::make_textures(Shade
557550
auto filter = sem == STS::USER ? shader->luts[meta->index].filter : shader->passes[p_ref.pass_number].filter;
558551
textures.push_back(
559552
compiled::TextureDescriptor(meta->name,
560-
sem,
561-
binding,
562-
wrap,
563-
filter,
564-
meta->index));
553+
sem,
554+
binding,
555+
wrap,
556+
filter,
557+
meta->index));
565558
}
566559
}
567560
}

thirdparty/slang/src/ShaderPassCompiler.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@ class ShaderPassCompiler {
3030
FRAGMENT,
3131
};
3232

33-
result::Result<std::vector<uint32_t>> ir_for_pass(ShaderPass &p_pass, ShaderType type, const ShaderCompilerOptions &p_options);
34-
result::Result<std::tuple<Compiler, Compiler>> make_compilers_for_pass(ShaderPass &p_pass, const ShaderCompilerOptions &p_options);
35-
result::Result<compiled::ShaderPass> compile_pass(ShaderPass &p_pass, const ShaderCompilerOptions &p_options);
33+
static result::Result<std::vector<uint32_t>> ir_for_pass(ShaderPass &p_pass, ShaderType type, const ShaderCompilerOptions &p_options);
34+
static result::Result<std::tuple<Compiler, Compiler>> make_compilers_for_pass(ShaderPass &p_pass, const ShaderCompilerOptions &p_options);
35+
result::Result<compiled::ShaderPass> compile_pass(ShaderPass &p_pass, const ShaderCompilerOptions &p_options) const;
3636
result::Result<ShaderSymbols> make_symbols() const;
37-
result::Result<ShaderPassReflection> reflect(int p_pass_number, ShaderSymbols &p_sym, Compiler p_vert, Compiler p_frag);
38-
bool validate_resources(spirv_cross::ShaderResources &p_vert, spirv_cross::ShaderResources &p_frag);
39-
error::ErrorOpt add_active_buffer_ranges(ShaderPassReflection &p_ref, ShaderSymbols &p_sym, Compiler p_comp, spirv_cross::Resource &p_res, bool p_ubo);
40-
compiled::UBOBufferDescriptor make_ubo_descriptor(ShaderPassReflection &p_ref) const;
41-
compiled::PushBufferDescriptor make_push_descriptor(ShaderPassReflection &p_ref) const;
42-
std::vector<compiled::BufferUniformDescriptor> make_descriptors(slang::ShaderPassReflection &p_ref, ShaderBufferSemanticMeta::OffsetType p_type) const;
43-
std::vector<compiled::TextureDescriptor> make_textures(ShaderPassReflection &p_ref, ShaderSymbols &p_sym) const;
37+
static result::Result<ShaderPassReflection> reflect(int p_pass_number, ShaderSymbols &p_sym, Compiler p_vert, Compiler p_frag);
38+
static bool validate_resources(const spirv_cross::ShaderResources &p_vert, const spirv_cross::ShaderResources &p_frag);
39+
static error::ErrorOpt add_active_buffer_ranges(ShaderPassReflection &p_ref, ShaderSymbols &p_sym, Compiler p_comp, spirv_cross::Resource &p_res, bool p_ubo);
40+
static compiled::UBOBufferDescriptor make_ubo_descriptor(ShaderPassReflection &p_ref);
41+
static compiled::PushBufferDescriptor make_push_descriptor(ShaderPassReflection &p_ref);
42+
static std::vector<compiled::BufferUniformDescriptor> make_descriptors(const slang::ShaderPassReflection &p_ref, ShaderBufferSemanticMeta::OffsetType p_type);
43+
std::vector<compiled::TextureDescriptor> make_textures(const ShaderPassReflection &p_ref, ShaderSymbols &p_sym) const;
4444

4545
public:
46-
ShaderPassCompiler(std::shared_ptr<SlangShader> p_shader) :
46+
ShaderPassCompiler(const std::shared_ptr<SlangShader> &p_shader) :
4747
shader(p_shader) {}
4848

49-
result::Result<compiled::Shader> compile(ShaderCompilerOptions const &p_options);
49+
result::Result<compiled::Shader> compile(ShaderCompilerOptions const &p_options) const;
5050
};
5151

5252
} //namespace slang

thirdparty/slang/src/SlangShader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct ShaderLUT {
2222
compiled::Wrap wrap_mode;
2323
bool is_mipmap;
2424

25-
ShaderLUT() {};
25+
ShaderLUT() : filter(compiled::Filter::UNSPECIFIED), wrap_mode(compiled::Wrap::BORDER), is_mipmap(false) {};
2626
ShaderLUT(fs::path const &p_path, ShaderTextureModel const &p_spec) :
2727
path(p_path) {
2828
name = p_spec.name;

thirdparty/slang/src/SourceParser.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ namespace fs = std::filesystem;
1717
using std::holds_alternative, std::get, std::u32string;
1818

1919
namespace prefixes {
20-
static const u32string version = U"#version ";
21-
static const u32string include = U"#include ";
22-
static const u32string endif = U"#endif";
23-
static const u32string pragma = U"#pragma ";
24-
static const u32string pragma_name = U"#pragma name ";
25-
static const u32string pragma_param = U"#pragma parameter ";
26-
static const u32string pragma_format = U"#pragma format ";
27-
static const u32string pragma_stage = U"#pragma stage ";
20+
static constexpr std::u32string_view version = U"#version ";
21+
static constexpr std::u32string_view include = U"#include ";
22+
static constexpr std::u32string_view endif = U"#endif";
23+
static constexpr std::u32string_view pragma = U"#pragma ";
24+
static constexpr std::u32string_view pragma_name = U"#pragma name ";
25+
static constexpr std::u32string_view pragma_param = U"#pragma parameter ";
26+
static constexpr std::u32string_view pragma_format = U"#pragma format ";
27+
static constexpr std::u32string_view pragma_stage = U"#pragma stage ";
2828
} //namespace prefixes
2929

3030
error::ErrorOpt SourceParser::load(fs::path p_source_path, bool p_is_root) {

thirdparty/slang/src/compiled.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
#include "compiled.h"
66

7+
#include <array>
78
#include <map>
89

9-
namespace slang {
10-
namespace compiled {
10+
namespace slang::compiled {
1111

1212
static std::map<std::u32string, PixelFormat> *str_to_pixel_format = nullptr;
1313

@@ -132,19 +132,21 @@ char const *to_cstr(ShaderTextureSemantic p_val) {
132132
}
133133
}
134134

135-
const std::vector<ShaderTextureSemantic> texture_semantics() {
136-
return {
135+
std::span<const ShaderTextureSemantic> texture_semantics() {
136+
static constexpr std::array semantics{
137137
ShaderTextureSemantic::ORIGINAL,
138138
ShaderTextureSemantic::SOURCE,
139139
ShaderTextureSemantic::ORIGINAL_HISTORY,
140140
ShaderTextureSemantic::PASS_OUTPUT,
141141
ShaderTextureSemantic::PASS_FEEDBACK,
142142
ShaderTextureSemantic::USER,
143143
};
144-
};
145144

146-
const std::vector<ShaderBufferSemantic> buffer_semantics() {
147-
return {
145+
return semantics;
146+
}
147+
148+
std::span<const ShaderBufferSemantic> buffer_semantics() {
149+
static constexpr std::array semantics{
148150
ShaderBufferSemantic::MVP,
149151
ShaderBufferSemantic::OUTPUT_SIZE,
150152
ShaderBufferSemantic::FINAL_VIEWPORT_SIZE,
@@ -158,6 +160,8 @@ const std::vector<ShaderBufferSemantic> buffer_semantics() {
158160
ShaderBufferSemantic::PASS_FEEDBACK_SIZE,
159161
ShaderBufferSemantic::USER_SIZE,
160162
};
163+
164+
return semantics;
161165
}
162166

163167
std::string to_string(ShaderTextureSemantic p_val) {
@@ -199,5 +203,4 @@ std::string to_string(ShaderBufferSemantic p_val) {
199203
return to_cstr(p_val);
200204
}
201205

202-
} //namespace compiled
203-
} //namespace slang
206+
} //namespace slang::compiled

0 commit comments

Comments
 (0)