Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/sksl/SkSLMain.cpp

Issue 2288033003: Turned on SkSL->GLSL compiler (Closed)
Patch Set: changed <iostream> to <ostream> Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/sksl/SkSLIRGenerator.cpp ('k') | src/sksl/SkSLParser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "stdio.h" 8 #include "stdio.h"
9 #include <fstream> 9 #include <fstream>
10 #include "SkSLCompiler.h" 10 #include "SkSLCompiler.h"
11 11
12 bool endsWith(const std::string& s, const std::string& ending) {
13 if (s.length() >= ending.length()) {
14 return (0 == s.compare(s.length() - ending.length(), ending.length(), en ding));
15 }
16 return false;
17 }
18
19 static SkSL::GLCaps default_caps() {
20 return {
21 400,
22 SkSL::GLCaps::kGL_Standard,
23 false, // isCoreProfile
24 false, // usesPrecisionModifiers;
25 false, // mustDeclareFragmentShaderOutput
26 true // canUseMinAndAbsTogether
27 };
28 }
29
12 /** 30 /**
13 * Very simple standalone executable to facilitate testing. 31 * Very simple standalone executable to facilitate testing.
14 */ 32 */
15 int main(int argc, const char** argv) { 33 int main(int argc, const char** argv) {
16 if (argc != 3) { 34 if (argc != 3) {
17 printf("usage: skslc <input> <output>\n"); 35 printf("usage: skslc <input> <output>\n");
18 exit(1); 36 exit(1);
19 } 37 }
20 SkSL::Program::Kind kind; 38 SkSL::Program::Kind kind;
21 size_t len = strlen(argv[1]); 39 size_t len = strlen(argv[1]);
22 if (len > 5 && !strcmp(argv[1] + strlen(argv[1]) - 5, ".vert")) { 40 if (len > 5 && !strcmp(argv[1] + strlen(argv[1]) - 5, ".vert")) {
23 kind = SkSL::Program::kVertex_Kind; 41 kind = SkSL::Program::kVertex_Kind;
24 } else if (len > 5 && !strcmp(argv[1] + strlen(argv[1]) - 5, ".frag")) { 42 } else if (len > 5 && !strcmp(argv[1] + strlen(argv[1]) - 5, ".frag")) {
25 kind = SkSL::Program::kFragment_Kind; 43 kind = SkSL::Program::kFragment_Kind;
26 } else { 44 } else {
27 printf("input filename must end in '.vert' or '.frag'\n"); 45 printf("input filename must end in '.vert' or '.frag'\n");
28 exit(1); 46 exit(1);
29 } 47 }
30 48
31 std::ifstream in(argv[1]); 49 std::ifstream in(argv[1]);
32 std::string text((std::istreambuf_iterator<char>(in)), 50 std::string text((std::istreambuf_iterator<char>(in)),
33 std::istreambuf_iterator<char>()); 51 std::istreambuf_iterator<char>());
34 if (in.rdstate()) { 52 if (in.rdstate()) {
35 printf("error reading '%s'\n", argv[1]); 53 printf("error reading '%s'\n", argv[1]);
36 exit(2); 54 exit(2);
37 } 55 }
38 std::ofstream out(argv[2], std::ofstream::binary); 56 std::string name(argv[2]);
39 SkSL::Compiler compiler; 57 if (endsWith(name, ".spirv")) {
40 if (!compiler.toSPIRV(kind, text, out)) { 58 std::ofstream out(argv[2], std::ofstream::binary);
41 printf("%s", compiler.errorText().c_str()); 59 SkSL::Compiler compiler;
42 exit(3); 60 if (!compiler.toSPIRV(kind, text, out)) {
43 } 61 printf("%s", compiler.errorText().c_str());
44 if (out.rdstate()) { 62 exit(3);
45 printf("error writing '%s'\n", argv[2]); 63 }
46 exit(4); 64 if (out.rdstate()) {
65 printf("error writing '%s'\n", argv[2]);
66 exit(4);
67 }
68 } else if (endsWith(name, ".glsl")) {
69 std::ofstream out(argv[2], std::ofstream::binary);
70 SkSL::Compiler compiler;
71 if (!compiler.toGLSL(kind, text, default_caps(), out)) {
72 printf("%s", compiler.errorText().c_str());
73 exit(3);
74 }
75 if (out.rdstate()) {
76 printf("error writing '%s'\n", argv[2]);
77 exit(4);
78 }
79 } else {
80 printf("expected output filename to end with '.spirv' or '.glsl'");
47 } 81 }
48 } 82 }
OLDNEW
« no previous file with comments | « src/sksl/SkSLIRGenerator.cpp ('k') | src/sksl/SkSLParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698