SkSLSPIRVTest.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/sksl/SkSLCompiler.h"
  8. #include "tests/Test.h"
  9. static void test_failure(skiatest::Reporter* r, const char* src, const char* error) {
  10. SkSL::Compiler compiler;
  11. SkSL::Program::Settings settings;
  12. sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
  13. settings.fCaps = caps.get();
  14. std::unique_ptr<SkSL::Program> program = compiler.convertProgram(SkSL::Program::kFragment_Kind,
  15. SkSL::String(src), settings);
  16. if (program) {
  17. SkSL::String ignored;
  18. compiler.toSPIRV(*program, &ignored);
  19. }
  20. SkSL::String skError(error);
  21. if (compiler.errorText() != skError) {
  22. SkDebugf("SKSL ERROR:\n source: %s\n expected: %s received: %s", src, error,
  23. compiler.errorText().c_str());
  24. }
  25. REPORTER_ASSERT(r, compiler.errorText() == skError);
  26. }
  27. DEF_TEST(SkSLBadOffset, r) {
  28. test_failure(r,
  29. "struct Bad { layout (offset = 5) int x; } bad; void main() { bad.x = 5; "
  30. "sk_FragColor.r = half(bad.x); }",
  31. "error: 1: offset of field 'x' must be a multiple of 4\n1 error\n");
  32. test_failure(r,
  33. "struct Bad { int x; layout (offset = 0) int y; } bad; void main() { bad.x = 5; "
  34. "sk_FragColor.r = half(bad.x); }",
  35. "error: 1: offset of field 'y' must be at least 4\n1 error\n");
  36. }