skia2/tests/DSLFPTest.cpp

88 lines
4.1 KiB
C++
Raw Normal View History

Reland "Reland "Implement statements and expressions in DSL C++ code generator."" This is a reland of c412688798e572ac8ca6414a19a48d007500f751 This CL lands the code changes but not the dm test, which is causing link errors. Tests will be relanded as a separate CL, at http://review.skia.org/400097 Original change's description: > Reland "Implement statements and expressions in DSL C++ code generator." > > This is a reland of 16cbfb41dff107ca3388bacf34201311d3c5f14d > > Tests now rely on `shaderDerivativeSupport` and `integerSupport` as > proxies to indicate ES3 support. The SwitchStatement test has been > adjusted to hopefully confuse fewer compilers. > > Original change's description: > > Implement statements and expressions in DSL C++ code generator. > > > > This CL removes the bulk of the existing C++ code generator, especially > > all the complex format-string assembly code. It has been replaced with > > actual DSL code generation. Simple IR can now be successfully translated > > to a working DSL fragment processor. > > > > This CL also adds a simple test harness which is patterned after the > > existing SkSLTest; it renders a pixel, reads it back, and fails the test > > if the result isn't solid green (RGBA=0101). > > > > This CL doesn't implement every feature. Some obvious gaps include: > > - Sampling from children > > - Uniforms/inputs of any kind > > - Function calls of any kind > > > > Change-Id: Ib80c23fe1ba4453f7c3cb43b65f93c5ea0deb709 > > Bug: skia:11854 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/396757 > > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> > > Reviewed-by: Brian Osman <brianosman@google.com> > > Commit-Queue: John Stiles <johnstiles@google.com> > > Bug: skia:11854, skia:11891 > Change-Id: I91363e31f34611d15ae350b52d6fc459feeace9c > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399076 > Auto-Submit: John Stiles <johnstiles@google.com> > Commit-Queue: Ethan Nicholas <ethannicholas@google.com> > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Bug: skia:11854 Bug: skia:11891 Change-Id: Ib1f08256c84d1da2130e0b61356f72435dc0a5a8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399740 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
2021-04-22 19:05:20 +00:00
/*
* Copyright 2021 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkData.h"
#include "include/core/SkFont.h"
#include "include/core/SkPaint.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "src/gpu/GrDirectContextPriv.h"
#include "src/gpu/GrSurfaceDrawContext.h"
#include "tests/Test.h"
#include "tests/sksl/dslfp/GrDSLFPTest_DoStatement.h"
#include "tests/sksl/dslfp/GrDSLFPTest_ForStatement.h"
#include "tests/sksl/dslfp/GrDSLFPTest_IfStatement.h"
#include "tests/sksl/dslfp/GrDSLFPTest_SwitchStatement.h"
#include "tests/sksl/dslfp/GrDSLFPTest_Swizzle.h"
#include "tests/sksl/dslfp/GrDSLFPTest_Ternary.h"
#include "tests/sksl/dslfp/GrDSLFPTest_WhileStatement.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
template <typename FPClass, typename... Uniforms>
static void test_dsl_fp(skiatest::Reporter* r,
GrDirectContext* ctx,
bool worksInES2,
Uniforms&&... uniforms) {
Reland "Reland "Implement statements and expressions in DSL C++ code generator."" This is a reland of c412688798e572ac8ca6414a19a48d007500f751 This CL lands the code changes but not the dm test, which is causing link errors. Tests will be relanded as a separate CL, at http://review.skia.org/400097 Original change's description: > Reland "Implement statements and expressions in DSL C++ code generator." > > This is a reland of 16cbfb41dff107ca3388bacf34201311d3c5f14d > > Tests now rely on `shaderDerivativeSupport` and `integerSupport` as > proxies to indicate ES3 support. The SwitchStatement test has been > adjusted to hopefully confuse fewer compilers. > > Original change's description: > > Implement statements and expressions in DSL C++ code generator. > > > > This CL removes the bulk of the existing C++ code generator, especially > > all the complex format-string assembly code. It has been replaced with > > actual DSL code generation. Simple IR can now be successfully translated > > to a working DSL fragment processor. > > > > This CL also adds a simple test harness which is patterned after the > > existing SkSLTest; it renders a pixel, reads it back, and fails the test > > if the result isn't solid green (RGBA=0101). > > > > This CL doesn't implement every feature. Some obvious gaps include: > > - Sampling from children > > - Uniforms/inputs of any kind > > - Function calls of any kind > > > > Change-Id: Ib80c23fe1ba4453f7c3cb43b65f93c5ea0deb709 > > Bug: skia:11854 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/396757 > > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> > > Reviewed-by: Brian Osman <brianosman@google.com> > > Commit-Queue: John Stiles <johnstiles@google.com> > > Bug: skia:11854, skia:11891 > Change-Id: I91363e31f34611d15ae350b52d6fc459feeace9c > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399076 > Auto-Submit: John Stiles <johnstiles@google.com> > Commit-Queue: Ethan Nicholas <ethannicholas@google.com> > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Bug: skia:11854 Bug: skia:11891 Change-Id: Ib1f08256c84d1da2130e0b61356f72435dc0a5a8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399740 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
2021-04-22 19:05:20 +00:00
if (!worksInES2) {
// We don't have an ES2 caps bit, so we check for integer support and derivatives support.
// Our ES2 bots should return false for these.
if (!ctx->priv().caps()->shaderCaps()->shaderDerivativeSupport() ||
!ctx->priv().caps()->shaderCaps()->integerSupport()) {
return;
}
}
std::unique_ptr<GrSurfaceDrawContext> rtCtx =
GrSurfaceDrawContext::Make(ctx,
GrColorType::kRGBA_8888,
/*colorSpace=*/nullptr,
SkBackingFit::kApprox,
/*dimensions=*/{1, 1},
SkSurfaceProps{});
rtCtx->fillRectWithFP(SkIRect::MakeWH(1, 1),
FPClass::Make(std::forward<Uniforms>(uniforms)...));
Reland "Reland "Implement statements and expressions in DSL C++ code generator."" This is a reland of c412688798e572ac8ca6414a19a48d007500f751 This CL lands the code changes but not the dm test, which is causing link errors. Tests will be relanded as a separate CL, at http://review.skia.org/400097 Original change's description: > Reland "Implement statements and expressions in DSL C++ code generator." > > This is a reland of 16cbfb41dff107ca3388bacf34201311d3c5f14d > > Tests now rely on `shaderDerivativeSupport` and `integerSupport` as > proxies to indicate ES3 support. The SwitchStatement test has been > adjusted to hopefully confuse fewer compilers. > > Original change's description: > > Implement statements and expressions in DSL C++ code generator. > > > > This CL removes the bulk of the existing C++ code generator, especially > > all the complex format-string assembly code. It has been replaced with > > actual DSL code generation. Simple IR can now be successfully translated > > to a working DSL fragment processor. > > > > This CL also adds a simple test harness which is patterned after the > > existing SkSLTest; it renders a pixel, reads it back, and fails the test > > if the result isn't solid green (RGBA=0101). > > > > This CL doesn't implement every feature. Some obvious gaps include: > > - Sampling from children > > - Uniforms/inputs of any kind > > - Function calls of any kind > > > > Change-Id: Ib80c23fe1ba4453f7c3cb43b65f93c5ea0deb709 > > Bug: skia:11854 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/396757 > > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> > > Reviewed-by: Brian Osman <brianosman@google.com> > > Commit-Queue: John Stiles <johnstiles@google.com> > > Bug: skia:11854, skia:11891 > Change-Id: I91363e31f34611d15ae350b52d6fc459feeace9c > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399076 > Auto-Submit: John Stiles <johnstiles@google.com> > Commit-Queue: Ethan Nicholas <ethannicholas@google.com> > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Bug: skia:11854 Bug: skia:11891 Change-Id: Ib1f08256c84d1da2130e0b61356f72435dc0a5a8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399740 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
2021-04-22 19:05:20 +00:00
SkImageInfo dstInfo = SkImageInfo::Make(/*width=*/1, /*height=*/1, kRGBA_8888_SkColorType,
kPremul_SkAlphaType, /*cs=*/nullptr);
GrPixmap dstPM = GrPixmap::Allocate(dstInfo);
REPORTER_ASSERT(r, rtCtx->readPixels(ctx, dstPM, /*srcPt=*/{0, 0}));
const GrColor* color = static_cast<const GrColor*>(dstPM.addr());
REPORTER_ASSERT(r, *color == GrColorPackRGBA(0x00, 0xFF, 0x00, 0xFF),
"Expected: solid green. Actual: A=%02X R=%02X G=%02X B=%02X.",
GrColorUnpackA(*color), GrColorUnpackR(*color),
GrColorUnpackG(*color), GrColorUnpackB(*color));
}
#define DSL_FP_TEST_ES2(FPClass, ...) \
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FPClass, r, ctxInfo) { \
return test_dsl_fp<Gr##FPClass>(r, ctxInfo.directContext(), /*worksInES2=*/true, \
##__VA_ARGS__); \
Reland "Reland "Implement statements and expressions in DSL C++ code generator."" This is a reland of c412688798e572ac8ca6414a19a48d007500f751 This CL lands the code changes but not the dm test, which is causing link errors. Tests will be relanded as a separate CL, at http://review.skia.org/400097 Original change's description: > Reland "Implement statements and expressions in DSL C++ code generator." > > This is a reland of 16cbfb41dff107ca3388bacf34201311d3c5f14d > > Tests now rely on `shaderDerivativeSupport` and `integerSupport` as > proxies to indicate ES3 support. The SwitchStatement test has been > adjusted to hopefully confuse fewer compilers. > > Original change's description: > > Implement statements and expressions in DSL C++ code generator. > > > > This CL removes the bulk of the existing C++ code generator, especially > > all the complex format-string assembly code. It has been replaced with > > actual DSL code generation. Simple IR can now be successfully translated > > to a working DSL fragment processor. > > > > This CL also adds a simple test harness which is patterned after the > > existing SkSLTest; it renders a pixel, reads it back, and fails the test > > if the result isn't solid green (RGBA=0101). > > > > This CL doesn't implement every feature. Some obvious gaps include: > > - Sampling from children > > - Uniforms/inputs of any kind > > - Function calls of any kind > > > > Change-Id: Ib80c23fe1ba4453f7c3cb43b65f93c5ea0deb709 > > Bug: skia:11854 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/396757 > > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> > > Reviewed-by: Brian Osman <brianosman@google.com> > > Commit-Queue: John Stiles <johnstiles@google.com> > > Bug: skia:11854, skia:11891 > Change-Id: I91363e31f34611d15ae350b52d6fc459feeace9c > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399076 > Auto-Submit: John Stiles <johnstiles@google.com> > Commit-Queue: Ethan Nicholas <ethannicholas@google.com> > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Bug: skia:11854 Bug: skia:11891 Change-Id: Ib1f08256c84d1da2130e0b61356f72435dc0a5a8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399740 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
2021-04-22 19:05:20 +00:00
}
#define DSL_FP_TEST(FPClass, ...) \
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FPClass, r, ctxInfo) { \
return test_dsl_fp<Gr##FPClass>(r, ctxInfo.directContext(), /*worksInES2=*/false, \
##__VA_ARGS__); \
Reland "Reland "Implement statements and expressions in DSL C++ code generator."" This is a reland of c412688798e572ac8ca6414a19a48d007500f751 This CL lands the code changes but not the dm test, which is causing link errors. Tests will be relanded as a separate CL, at http://review.skia.org/400097 Original change's description: > Reland "Implement statements and expressions in DSL C++ code generator." > > This is a reland of 16cbfb41dff107ca3388bacf34201311d3c5f14d > > Tests now rely on `shaderDerivativeSupport` and `integerSupport` as > proxies to indicate ES3 support. The SwitchStatement test has been > adjusted to hopefully confuse fewer compilers. > > Original change's description: > > Implement statements and expressions in DSL C++ code generator. > > > > This CL removes the bulk of the existing C++ code generator, especially > > all the complex format-string assembly code. It has been replaced with > > actual DSL code generation. Simple IR can now be successfully translated > > to a working DSL fragment processor. > > > > This CL also adds a simple test harness which is patterned after the > > existing SkSLTest; it renders a pixel, reads it back, and fails the test > > if the result isn't solid green (RGBA=0101). > > > > This CL doesn't implement every feature. Some obvious gaps include: > > - Sampling from children > > - Uniforms/inputs of any kind > > - Function calls of any kind > > > > Change-Id: Ib80c23fe1ba4453f7c3cb43b65f93c5ea0deb709 > > Bug: skia:11854 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/396757 > > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> > > Reviewed-by: Brian Osman <brianosman@google.com> > > Commit-Queue: John Stiles <johnstiles@google.com> > > Bug: skia:11854, skia:11891 > Change-Id: I91363e31f34611d15ae350b52d6fc459feeace9c > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399076 > Auto-Submit: John Stiles <johnstiles@google.com> > Commit-Queue: Ethan Nicholas <ethannicholas@google.com> > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Bug: skia:11854 Bug: skia:11891 Change-Id: Ib1f08256c84d1da2130e0b61356f72435dc0a5a8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399740 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
2021-04-22 19:05:20 +00:00
}
DSL_FP_TEST_ES2(DSLFPTest_IfStatement, /*one:*/ 1.0f)
Reland "Reland "Implement statements and expressions in DSL C++ code generator."" This is a reland of c412688798e572ac8ca6414a19a48d007500f751 This CL lands the code changes but not the dm test, which is causing link errors. Tests will be relanded as a separate CL, at http://review.skia.org/400097 Original change's description: > Reland "Implement statements and expressions in DSL C++ code generator." > > This is a reland of 16cbfb41dff107ca3388bacf34201311d3c5f14d > > Tests now rely on `shaderDerivativeSupport` and `integerSupport` as > proxies to indicate ES3 support. The SwitchStatement test has been > adjusted to hopefully confuse fewer compilers. > > Original change's description: > > Implement statements and expressions in DSL C++ code generator. > > > > This CL removes the bulk of the existing C++ code generator, especially > > all the complex format-string assembly code. It has been replaced with > > actual DSL code generation. Simple IR can now be successfully translated > > to a working DSL fragment processor. > > > > This CL also adds a simple test harness which is patterned after the > > existing SkSLTest; it renders a pixel, reads it back, and fails the test > > if the result isn't solid green (RGBA=0101). > > > > This CL doesn't implement every feature. Some obvious gaps include: > > - Sampling from children > > - Uniforms/inputs of any kind > > - Function calls of any kind > > > > Change-Id: Ib80c23fe1ba4453f7c3cb43b65f93c5ea0deb709 > > Bug: skia:11854 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/396757 > > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> > > Reviewed-by: Brian Osman <brianosman@google.com> > > Commit-Queue: John Stiles <johnstiles@google.com> > > Bug: skia:11854, skia:11891 > Change-Id: I91363e31f34611d15ae350b52d6fc459feeace9c > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399076 > Auto-Submit: John Stiles <johnstiles@google.com> > Commit-Queue: Ethan Nicholas <ethannicholas@google.com> > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Bug: skia:11854 Bug: skia:11891 Change-Id: Ib1f08256c84d1da2130e0b61356f72435dc0a5a8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399740 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
2021-04-22 19:05:20 +00:00
DSL_FP_TEST_ES2(DSLFPTest_Swizzle)
DSL_FP_TEST_ES2(DSLFPTest_Ternary, /*primaryColors:*/true,
/*colorGreen:*/ SkPMColor4f{0.0, 1.0, 0.0, 1.0},
/*colorRed:*/ SkPMColor4f{1.0, 0.0, 0.0, 1.0},
/*colorOrange:*/ SkPMColor4f{1.0, 0.5, 0.0, 1.0},
/*colorPurple:*/ SkPMColor4f{0.5, 0.0, 0.5, 1.0})
DSL_FP_TEST(DSLFPTest_DoStatement, /*shouldLoop:*/ false)
DSL_FP_TEST(DSLFPTest_ForStatement, /*colorWhite:*/ SkPMColor4f{1, 1, 1, 1})
Reland "Reland "Implement statements and expressions in DSL C++ code generator."" This is a reland of c412688798e572ac8ca6414a19a48d007500f751 This CL lands the code changes but not the dm test, which is causing link errors. Tests will be relanded as a separate CL, at http://review.skia.org/400097 Original change's description: > Reland "Implement statements and expressions in DSL C++ code generator." > > This is a reland of 16cbfb41dff107ca3388bacf34201311d3c5f14d > > Tests now rely on `shaderDerivativeSupport` and `integerSupport` as > proxies to indicate ES3 support. The SwitchStatement test has been > adjusted to hopefully confuse fewer compilers. > > Original change's description: > > Implement statements and expressions in DSL C++ code generator. > > > > This CL removes the bulk of the existing C++ code generator, especially > > all the complex format-string assembly code. It has been replaced with > > actual DSL code generation. Simple IR can now be successfully translated > > to a working DSL fragment processor. > > > > This CL also adds a simple test harness which is patterned after the > > existing SkSLTest; it renders a pixel, reads it back, and fails the test > > if the result isn't solid green (RGBA=0101). > > > > This CL doesn't implement every feature. Some obvious gaps include: > > - Sampling from children > > - Uniforms/inputs of any kind > > - Function calls of any kind > > > > Change-Id: Ib80c23fe1ba4453f7c3cb43b65f93c5ea0deb709 > > Bug: skia:11854 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/396757 > > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> > > Reviewed-by: Brian Osman <brianosman@google.com> > > Commit-Queue: John Stiles <johnstiles@google.com> > > Bug: skia:11854, skia:11891 > Change-Id: I91363e31f34611d15ae350b52d6fc459feeace9c > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399076 > Auto-Submit: John Stiles <johnstiles@google.com> > Commit-Queue: Ethan Nicholas <ethannicholas@google.com> > Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Bug: skia:11854 Bug: skia:11891 Change-Id: Ib1f08256c84d1da2130e0b61356f72435dc0a5a8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399740 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
2021-04-22 19:05:20 +00:00
DSL_FP_TEST(DSLFPTest_SwitchStatement)
DSL_FP_TEST(DSLFPTest_WhileStatement)