Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 73c5881

Browse files
[Impeller] dont call SPIRV_CROSS_THROW in SkSL backend (#37273)
1 parent c7b2230 commit 73c5881

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

impeller/compiler/spirv_sksl.cc

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ using namespace SPIRV_CROSS_NAMESPACE;
1010
namespace impeller {
1111
namespace compiler {
1212

13+
// This replaces the SPIRV_CROSS_THROW which aborts and drops the
14+
// error message in non-debug modes.
15+
void report_and_exit(const std::string& msg) {
16+
fprintf(stderr, "There was a compiler error: %s\n", msg.c_str());
17+
fflush(stderr);
18+
exit(1);
19+
}
20+
21+
#define FLUTTER_CROSS_THROW(x) report_and_exit(x)
22+
1323
std::string CompilerSkSL::compile() {
1424
ir.fixup_reserved_names();
1525

1626
if (get_execution_model() != ExecutionModelFragment) {
17-
SPIRV_CROSS_THROW("Only fragment shaders are supported.'");
27+
FLUTTER_CROSS_THROW("Only fragment shaders are supported.'");
1828
return "";
1929
}
2030

@@ -111,7 +121,7 @@ void CompilerSkSL::emit_uniform(const SPIRVariable& var) {
111121
add_resource_name(var.self);
112122
statement(variable_decl(var), ";");
113123

114-
// The Flutter FragmentProgram implementation passes additional unifroms along
124+
// The Flutter FragmentProgram implementation passes additional uniforms along
115125
// with shader uniforms that encode the shader width and height.
116126
if (type.basetype == SPIRType::SampledImage) {
117127
std::string name = to_name(var.self);
@@ -179,8 +189,8 @@ void CompilerSkSL::detect_unsupported_resources() {
179189
DecorationBlock) ||
180190
ir.meta[type.self].decoration.decoration_flags.get(
181191
DecorationBufferBlock))) {
182-
SPIRV_CROSS_THROW("SkSL does not support UBOs or SSBOs: '" +
183-
get_name(var.self) + "'");
192+
FLUTTER_CROSS_THROW("SkSL does not support UBOs or SSBOs: '" +
193+
get_name(var.self) + "'");
184194
}
185195
}
186196
}
@@ -192,8 +202,8 @@ void CompilerSkSL::detect_unsupported_resources() {
192202
auto& type = get<SPIRType>(var.basetype);
193203
if (!is_hidden_variable(var) && var.storage != StorageClassFunction &&
194204
type.pointer && type.storage == StorageClassPushConstant) {
195-
SPIRV_CROSS_THROW("SkSL does not support push constant blocks: '" +
196-
get_name(var.self) + "'");
205+
FLUTTER_CROSS_THROW("SkSL does not support push constant blocks: '" +
206+
get_name(var.self) + "'");
197207
}
198208
}
199209
}
@@ -342,8 +352,8 @@ void CompilerSkSL::emit_interface_block(const SPIRVariable& var) {
342352
bool block =
343353
ir.meta[type.self].decoration.decoration_flags.get(DecorationBlock);
344354
if (block) {
345-
SPIRV_CROSS_THROW("Interface blocks are not supported: '" +
346-
to_name(var.self) + "'");
355+
FLUTTER_CROSS_THROW("Interface blocks are not supported: '" +
356+
to_name(var.self) + "'");
347357
}
348358

349359
// The output is emitted as a global variable, which is returned from the
@@ -353,8 +363,8 @@ void CompilerSkSL::emit_interface_block(const SPIRVariable& var) {
353363
if (output_name_.empty()) {
354364
output_name_ = to_name(var.self);
355365
} else if (to_name(var.self) != output_name_) {
356-
SPIRV_CROSS_THROW("Only one output variable is supported: '" +
357-
to_name(var.self) + "'");
366+
FLUTTER_CROSS_THROW("Only one output variable is supported: '" +
367+
to_name(var.self) + "'");
358368
}
359369
}
360370

@@ -369,11 +379,12 @@ void CompilerSkSL::emit_function_prototype(SPIRFunction& func,
369379

370380
auto& type = get<SPIRType>(func.return_type);
371381
if (type.basetype != SPIRType::Void) {
372-
SPIRV_CROSS_THROW("Return type of the entrypoint function must be 'void'");
382+
FLUTTER_CROSS_THROW(
383+
"Return type of the entrypoint function must be 'void'");
373384
}
374385

375386
if (func.arguments.size() != 0) {
376-
SPIRV_CROSS_THROW(
387+
FLUTTER_CROSS_THROW(
377388
"The entry point function should not acept any parameters.");
378389
}
379390

@@ -387,7 +398,7 @@ void CompilerSkSL::emit_function_prototype(SPIRFunction& func,
387398

388399
std::string CompilerSkSL::image_type_glsl(const SPIRType& type, uint32_t id) {
389400
if (type.basetype != SPIRType::SampledImage || type.image.dim != Dim2D) {
390-
SPIRV_CROSS_THROW("Only sampler2D uniform image types are supported.");
401+
FLUTTER_CROSS_THROW("Only sampler2D uniform image types are supported.");
391402
return "???";
392403
}
393404
return "shader";
@@ -400,7 +411,7 @@ std::string CompilerSkSL::builtin_to_glsl(BuiltIn builtin,
400411
case BuiltInFragCoord:
401412
return "flutter_FragCoord";
402413
default:
403-
SPIRV_CROSS_THROW("Builtin '" + gl_builtin + "' is not supported.");
414+
FLUTTER_CROSS_THROW("Builtin '" + gl_builtin + "' is not supported.");
404415
break;
405416
}
406417

@@ -414,7 +425,7 @@ std::string CompilerSkSL::to_texture_op(
414425
SmallVector<uint32_t>& inherited_expressions) {
415426
auto op = static_cast<Op>(i.op);
416427
if (op != OpImageSampleImplicitLod) {
417-
SPIRV_CROSS_THROW("Only simple shader sampling is supported.");
428+
FLUTTER_CROSS_THROW("Only simple shader sampling is supported.");
418429
return "???";
419430
}
420431
return CompilerGLSL::to_texture_op(i, sparse, forward, inherited_expressions);
@@ -442,8 +453,8 @@ std::string CompilerSkSL::to_function_args(const TextureFunctionArguments& args,
442453
}
443454

444455
if (no_shader.empty()) {
445-
SPIRV_CROSS_THROW("Unexpected shader sampling arguments: '(" + glsl_args +
446-
")'");
456+
FLUTTER_CROSS_THROW("Unexpected shader sampling arguments: '(" + glsl_args +
457+
")'");
447458
return "()";
448459
}
449460

0 commit comments

Comments
 (0)