Skip to content

Commit de89276

Browse files
committed
Make things compile again
1 parent d73f936 commit de89276

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

Sources/GlslTranslator2.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using namespace krafix;
66

77
void GlslTranslator2::outputCode(const Target& target, const char* sourcefilename, const char* filename, char* output, std::map<std::string, int>& attributes) {
88
std::vector<unsigned> spirv;
9-
9+
1010
spirv.push_back(magicNumber);
1111
spirv.push_back(version);
1212
spirv.push_back(generator);
@@ -23,8 +23,8 @@ void GlslTranslator2::outputCode(const Target& target, const char* sourcefilenam
2323

2424
spirv_cross::CompilerGLSL* compiler = new spirv_cross::CompilerGLSL(spirv);
2525

26-
compiler->set_entry_point("main");
27-
spirv_cross::CompilerGLSL::Options opts = compiler->get_options();
26+
compiler->set_entry_point("main", executionModel());
27+
spirv_cross::CompilerGLSL::Options opts = compiler->get_common_options();
2828
opts.vertex.fixup_clipspace = false;
2929
opts.version = target.version;
3030
opts.es = target.es;
@@ -42,7 +42,7 @@ void GlslTranslator2::outputCode(const Target& target, const char* sourcefilenam
4242
opts.relax_everything = true;
4343
#endif
4444
}
45-
compiler->set_options(opts);
45+
compiler->set_common_options(opts);
4646

4747
std::string glsl = compiler->compile();
4848
if (output) {

Sources/HlslTranslator2.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using namespace krafix;
77

88
void HlslTranslator2::outputCode(const Target& target, const char* sourcefilename, const char* filename, char* output, std::map<std::string, int>& attributes) {
99
std::vector<unsigned> spirv;
10-
10+
1111
spirv.push_back(magicNumber);
1212
spirv.push_back(version);
1313
spirv.push_back(generator);
@@ -24,20 +24,20 @@ void HlslTranslator2::outputCode(const Target& target, const char* sourcefilenam
2424

2525
spirv_cross::CompilerHLSL* compiler = new spirv_cross::CompilerHLSL(spirv);
2626

27-
compiler->set_entry_point("main");
27+
compiler->set_entry_point("main", executionModel());
2828

29-
spirv_cross::CompilerGLSL::Options glslOpts = compiler->CompilerGLSL::get_options();
29+
spirv_cross::CompilerGLSL::Options glslOpts = compiler->CompilerGLSL::get_common_options();
3030
glslOpts.vertex.fixup_clipspace = true;
31-
compiler->CompilerGLSL::set_options(glslOpts);
32-
33-
spirv_cross::CompilerHLSL::Options opts = compiler->get_options();
31+
compiler->CompilerGLSL::set_common_options(glslOpts);
32+
33+
spirv_cross::CompilerHLSL::Options opts = compiler->get_hlsl_options();
3434
if (target.version > 9) {
3535
opts.shader_model = 40;
3636
}
3737
else {
3838
opts.shader_model = 30;
3939
}
40-
compiler->set_options(opts);
40+
compiler->set_hlsl_options(opts);
4141

4242
std::string hlsl = compiler->compile();
4343
if (output) {

Sources/MetalTranslator2.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace {
1515
}
1616
return path.substr(i, std::string::npos);
1717
}
18-
18+
1919
std::string replace(std::string str, char c1, char c2) {
2020
std::string ret = str;
2121
for (unsigned i = 0; i < str.length(); ++i) {
@@ -40,7 +40,7 @@ namespace {
4040

4141
void MetalTranslator2::outputCode(const Target& target, const char* sourcefilename, const char* filename, char* output, std::map<std::string, int>& attributes) {
4242
std::vector<unsigned> spirv;
43-
43+
4444
spirv.push_back(magicNumber);
4545
spirv.push_back(version);
4646
spirv.push_back(generator);
@@ -56,7 +56,7 @@ void MetalTranslator2::outputCode(const Target& target, const char* sourcefilena
5656
}
5757

5858
spirv_cross::CompilerMSL* compiler = new spirv_cross::CompilerMSL(spirv);
59-
59+
6060
std::string name = extractFilename(sourcefilename);
6161
name = name.substr(0, name.find_last_of("."));
6262
name = replace(name, '-', '_');
@@ -86,8 +86,8 @@ void MetalTranslator2::outputCode(const Target& target, const char* sourcefilena
8686
mslBinding.stage = convert(stage);
8787
mslBinding.msl_buffer = stage == StageVertex ? 1 : 0;
8888
p_res_bindings.push_back(mslBinding);
89-
90-
std::string metal = compiler->compile(nullptr, &p_res_bindings);
89+
90+
std::string metal = compiler->compile(); // nullptr, & p_res_bindings); // TODO?
9191
if (output) {
9292
strcpy(output, metal.c_str());
9393
}

Sources/Translator.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Instruction::Instruction(std::vector<unsigned>& spirv, unsigned& index) {
3838
}
3939

4040
Instruction::Instruction(int opcode, unsigned* operands, unsigned length) : opcode(opcode), operands(operands), length(length), string(NULL) {
41-
41+
4242
}
4343

4444
Translator::Translator(std::vector<unsigned>& spirv, ShaderStage stage) : stage(stage), spirv(spirv) {
@@ -57,3 +57,22 @@ Translator::Translator(std::vector<unsigned>& spirv, ShaderStage stage) : stage(
5757

5858
//printf("Read %i instructions.\n", instructions.size());
5959
}
60+
61+
spv::ExecutionModel Translator::executionModel() {
62+
switch (stage) {
63+
case StageVertex:
64+
return spv::ExecutionModelVertex;
65+
case StageTessControl:
66+
return spv::ExecutionModelTessellationControl;
67+
case StageTessEvaluation:
68+
return spv::ExecutionModelTessellationEvaluation;
69+
case StageGeometry:
70+
return spv::ExecutionModelGeometry;
71+
case StageFragment:
72+
return spv::ExecutionModelFragment;
73+
case StageCompute:
74+
return spv::ExecutionModelKernel;
75+
default:
76+
throw "Unknown shader stage";
77+
}
78+
}

Sources/Translator.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <sstream>
66
#include <vector>
77

8+
#include <SPIRV/spirv.hpp>
9+
810
namespace krafix {
911
enum TargetLanguage {
1012
SpirV,
@@ -61,7 +63,7 @@ namespace krafix {
6163
stream << version;
6264
return stream.str();
6365
}
64-
66+
6567
case Metal:
6668
return "Metal";
6769
case AGAL:
@@ -96,6 +98,7 @@ namespace krafix {
9698
std::vector<unsigned>& spirv;
9799
std::vector<Instruction> instructions;
98100
ShaderStage stage;
101+
spv::ExecutionModel executionModel();
99102

100103
unsigned magicNumber;
101104
unsigned version;

0 commit comments

Comments
 (0)