Skip to content

Commit b34cd93

Browse files
committed
Added JavaScriptTranslator.
1 parent 49b475a commit b34cd93

18 files changed

+430
-111
lines changed

Sources/AgalTranslator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ namespace {
303303
}
304304
}
305305

306-
void AgalTranslator::outputCode(const Target& target, const char* filename, std::map<std::string, int>& attributes) {
306+
void AgalTranslator::outputCode(const Target& target, const char* sourcefilename, const char* filename, std::map<std::string, int>& attributes) {
307307
using namespace spv;
308308

309309
std::map<unsigned, Name> names;

Sources/AgalTranslator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ namespace krafix {
77
class AgalTranslator : public Translator {
88
public:
99
AgalTranslator(std::vector<unsigned>& spirv, EShLanguage stage) : Translator(spirv, stage) {}
10-
void outputCode(const Target& target, const char* filename, std::map<std::string, int>& attributes);
10+
void outputCode(const Target& target, const char* sourcefilename, const char* filename, std::map<std::string, int>& attributes);
1111
};
1212
}

Sources/GlslTranslator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace {
2424
}
2525
}
2626

27-
void GlslTranslator::outputCode(const Target& target, const char* filename, std::map<std::string, int>& attributes) {
27+
void GlslTranslator::outputCode(const Target& target, const char* sourcefilename, const char* filename, std::map<std::string, int>& attributes) {
2828
std::ofstream file;
2929
file.open(filename, std::ios::binary | std::ios::out);
3030
out = &file;

Sources/GlslTranslator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace krafix {
66
class GlslTranslator : public CStyleTranslator {
77
public:
88
GlslTranslator(std::vector<unsigned>& spirv, EShLanguage stage) : CStyleTranslator(spirv, stage) {}
9-
void outputCode(const Target& target, const char* filename, std::map<std::string, int>& attributes);
9+
void outputCode(const Target& target, const char* sourcefilename, const char* filename, std::map<std::string, int>& attributes);
1010
void outputInstruction(const Target& target, std::map<std::string, int>& attributes, Instruction& inst);
1111
};
1212
}

Sources/HlslTranslator.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace {
3131
}
3232
}
3333

34-
void HlslTranslator::outputCode(const Target& target, const char* filename, std::map<std::string, int>& attributes) {
34+
void HlslTranslator::outputCode(const Target& target, const char* sourcefilename, const char* filename, std::map<std::string, int>& attributes) {
3535
std::ofstream file;
3636
file.open(filename, std::ios::binary | std::ios::out);
3737
out = &file;
@@ -427,23 +427,23 @@ void HlslTranslator::outputInstruction(const Target& target, std::map<std::strin
427427
(*out) << "OutputFrag main(InputFrag input)\n";
428428
}
429429
else if (stage == EShLangTessControl) {
430-
(*out) << "[domain(\"tri\")]\n"; indent(out);
431-
(*out) << "[partitioning(\"integer\")]\n"; indent(out);
432-
(*out) << "[outputtopology(\"triangle_cw\")]\n"; indent(out);
433-
(*out) << "[outputcontrolpoints(3)]\n"; indent(out);
434-
(*out) << "[patchconstantfunc(\"patch\")]\n"; indent(out);
430+
(*out) << "[domain(\"tri\")]\n"; indent(out);
431+
(*out) << "[partitioning(\"integer\")]\n"; indent(out);
432+
(*out) << "[outputtopology(\"triangle_cw\")]\n"; indent(out);
433+
(*out) << "[outputcontrolpoints(3)]\n"; indent(out);
434+
(*out) << "[patchconstantfunc(\"patch\")]\n"; indent(out);
435435
(*out) << "OutputTessC main(InputPatch<InputTessC, 3> input, uint pointId : SV_OutputControlPointID, uint patchId : SV_PrimitiveID)\n";
436436
}
437437
else if (stage == EShLangTessEvaluation) {
438-
(*out) << "[domain(\"tri\")]\n"; indent(out);
438+
(*out) << "[domain(\"tri\")]\n"; indent(out);
439439
(*out) << "OutputTessE main(float edges[3] : SV_TessFactor, float inside : SV_InsideTessFactor, float3 gl_TessCoord : SV_DomainLocation, const OutputPatch<InputTessE, 3> input)\n";
440440
}
441441
else if (stage == EShLangGeometry) {
442442
(*out) << "[maxvertexcount(3)]\n"; indent(out);
443443
(*out) << "void main(triangle InputGeom input[3], inout TriangleStream<OutputGeom> _output_stream)\n";
444444
}
445445
else if (stage == EShLangCompute) {
446-
(*out) << "[numthreads(" << localSizeX << ", " << localSizeY << ", " << localSizeZ <<")]\n"; indent(out);
446+
(*out) << "[numthreads(" << localSizeX << ", " << localSizeY << ", " << localSizeZ <<")]\n"; indent(out);
447447
(*out) << "void main(uint3 groupID : SV_GroupID, uint3 groupThreadID : SV_GroupThreadID, uint3 dispatchThreadID : SV_DispatchThreadID)\n";
448448
}
449449
else {
@@ -462,8 +462,8 @@ void HlslTranslator::outputInstruction(const Target& target, std::map<std::strin
462462
indent(out); (*out) << "tc_gl_InvocationID = 0;\n";
463463
}
464464
else if (stage == EShLangCompute) {
465-
indent(out); (*out) << "c_gl_WorkGroupID = groupID;\n";
466-
indent(out); (*out) << "c_gl_LocalInvocationID = groupThreadID;\n";
465+
indent(out); (*out) << "c_gl_WorkGroupID = groupID;\n";
466+
indent(out); (*out) << "c_gl_LocalInvocationID = groupThreadID;\n";
467467
indent(out); (*out) << "c_gl_GlobalInvocationID = dispatchThreadID;\n";
468468
}
469469

@@ -634,19 +634,19 @@ void HlslTranslator::outputInstruction(const Target& target, std::map<std::strin
634634
(*out) << "void tese_main()\n";
635635
}
636636
else if (stage == EShLangTessControl) {
637-
(*out) << "struct PatchOutputTessC {\n"; ++indentation; indent(out);
638-
(*out) << "float gl_TessLevelInner : SV_InsideTessFactor;\n"; indent(out);
639-
(*out) << "float gl_TessLevelOuter[3] : SV_TessFactor;\n"; --indentation; indent(out);
640-
(*out) << "};\n\n"; indent(out);
641-
642-
(*out) << "PatchOutputTessC patch() {\n"; ++indentation; indent(out);
643-
(*out) << "PatchOutputTessC output;\n"; indent(out);
644-
(*out) << "patch_main();\n"; indent(out);
645-
(*out) << "output.gl_TessLevelInner = tc_gl_TessLevelInner[0];\n"; indent(out);
646-
(*out) << "output.gl_TessLevelOuter[0] = tc_gl_TessLevelOuter[0];\n"; indent(out);
647-
(*out) << "output.gl_TessLevelOuter[1] = tc_gl_TessLevelOuter[1];\n"; indent(out);
648-
(*out) << "output.gl_TessLevelOuter[2] = tc_gl_TessLevelOuter[2];\n"; indent(out);
649-
(*out) << "return output;\n"; --indentation; indent(out);
637+
(*out) << "struct PatchOutputTessC {\n"; ++indentation; indent(out);
638+
(*out) << "float gl_TessLevelInner : SV_InsideTessFactor;\n"; indent(out);
639+
(*out) << "float gl_TessLevelOuter[3] : SV_TessFactor;\n"; --indentation; indent(out);
640+
(*out) << "};\n\n"; indent(out);
641+
642+
(*out) << "PatchOutputTessC patch() {\n"; ++indentation; indent(out);
643+
(*out) << "PatchOutputTessC output;\n"; indent(out);
644+
(*out) << "patch_main();\n"; indent(out);
645+
(*out) << "output.gl_TessLevelInner = tc_gl_TessLevelInner[0];\n"; indent(out);
646+
(*out) << "output.gl_TessLevelOuter[0] = tc_gl_TessLevelOuter[0];\n"; indent(out);
647+
(*out) << "output.gl_TessLevelOuter[1] = tc_gl_TessLevelOuter[1];\n"; indent(out);
648+
(*out) << "output.gl_TessLevelOuter[2] = tc_gl_TessLevelOuter[2];\n"; indent(out);
649+
(*out) << "return output;\n"; --indentation; indent(out);
650650
(*out) << "}\n\n"; indent(out);
651651

652652
(*out) << "void tesc_main()\n";

Sources/HlslTranslator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace krafix {
66
class HlslTranslator : public CStyleTranslator {
77
public:
88
HlslTranslator(std::vector<unsigned>& spirv, EShLanguage stage) : CStyleTranslator(spirv, stage) {}
9-
void outputCode(const Target& target, const char* filename, std::map<std::string, int>& attributes);
9+
void outputCode(const Target& target, const char* sourcefilename, const char* filename, std::map<std::string, int>& attributes);
1010
void outputInstruction(const Target& target, std::map<std::string, int>& attributes, Instruction& inst);
1111
void outputLibraryInstruction(const Target& target, std::map<std::string, int>& attributes, Instruction& inst, GLSLstd450 entrypoint);
1212
};

0 commit comments

Comments
 (0)