62#include <initializer_list>
79#define WRITE_PNG_CONTEXT_TYPE kANGLE_D3D11_ES3
146 const std::unique_ptr<skgpu::ganesh::SurfaceDrawContext>&,
151#ifdef WRITE_PNG_CONTEXT_TYPE
153 return type == skgpu::ContextType::WRITE_PNG_CONTEXT_TYPE;
159 auto dContext = ctxInfo.directContext();
188 int rgb[3] = {-(c & 1) & 0xff, -((c >> 1) & 1) & 0xff, -((c >> 2) & 1) & 0xff};
196 std::array<Box, 4>& boxVertices = vertexData.
push_back();
197 for (
int i = 0;
i < 4; ++
i) {
205 paint.setARGB(255, rgb[0], rgb[1], rgb[2]);
212#define VALIDATE(buff) \
215 ERRORF(reporter, #buff " is null."); \
224 for (
int j = 0; j < 6; ++j) {
249 int baseRepetition = 0;
259 pass->drawIndexed(repetitionCount * 6, baseRepetition * 6, baseRepetition * 4,
260 (baseRepetition + repetitionCount) * 4 - 1,
261 (
i - baseRepetition) * 4);
263 baseRepetition = (baseRepetition + 1) % 3;
264 i += repetitionCount;
287 for (
bool indexed : {
false,
true}) {
288 if (!dContext->priv().caps()->drawInstancedSupport()) {
292 run_test(dContext, indexed ?
"drawIndexedInstanced" :
"drawInstanced",
298 for (
int i = 0;
i < 6; ++
i) {
302 baseIndexData.
size());
309 std::vector<float>{-1,-1, -1,-1, 0,0, 0,1, 1,0, 1,1});
320 if (dContext->priv().caps()->shaderCaps()->fVertexIDSupport) {
341 int baseIndex = (
y % 2);
342 pass->bindBuffers(std::move(indexBuffer), helper->
fInstBuffer,
343 std::move(vertexBuffer));
348 std::move(vertexBuffer));
355 for (
bool indexed : {
false,
true}) {
356 if (!dContext->priv().caps()->drawInstancedSupport()) {
360 run_test(dContext, (indexed) ?
"drawIndexedIndirect" :
"drawIndirect",
366 for (
int i = 0;
i < 6; ++
i) {
371 baseIndexData.
size());
376 -1,-1, 0,0, 0,1, 1,0, 1,1, -1,-1, 0,0, 1,0, 0,1, 1,1});
384 size_t ignoredOffset;
387 helper->
target()->makeDrawIndirectSpace(29, &ignoredBuff, &ignoredOffset);
388 indexedIndirectWriter = helper->
target()->makeDrawIndexedIndirectSpace(
394 size_t ignoredOffset;
397 helper->
target()->makeDrawIndexedIndirectSpace(7, &ignoredBuff,
399 indirectWriter = helper->
target()->makeDrawIndirectSpace(
406 int baseVertex = (
y % 2) ? 1 : 6;
408 int baseIndex = 1 +
y * 6;
409 indexedIndirectWriter.writeIndexed(6, baseIndex,
kBoxCountX,
422 for (
int i = 0;
i < 3; ++
i) {
433 for (
int i = 0;
i < 2; ++
i) {
456 return GrOp::Make<MeshTestOp>(rContext, prepareFn, executeFn);
464 :
INHERITED(ClassID()), fPrepareFn(prepareFn), fExecuteFn(executeFn) {
469 const char*
name()
const override {
return "GrMeshTestOp"; }
482 fHelper = std::make_unique<DrawMeshHelper>(
state);
483 fPrepareFn(fHelper.get());
486 fExecuteFn(fHelper.get());
489 std::unique_ptr<DrawMeshHelper> fHelper;
499 return arena->
make([&](
void* ptr) {
500 return new (ptr) MeshTestProcessor(instanced, hasVertexBuffer);
504 const char*
name()
const override {
return "GrMeshTestProcessor"; }
507 b->add32(fInstanceLocation.isInitialized());
508 b->add32(fVertexPosition.isInitialized());
517 return fVertexColor.isInitialized() ? fVertexColor : fInstanceColor;
520 MeshTestProcessor(
bool instanced,
bool hasVertexBuffer)
521 :
INHERITED(kGrMeshTestProcessor_ClassID) {
526 if (hasVertexBuffer) {
547std::unique_ptr<GrGeometryProcessor::ProgramImpl> MeshTestProcessor::makeProgramImpl(
556 void onEmitCode(EmitArgs&
args, GrGPArgs* gpArgs)
final {
557 const MeshTestProcessor& mp =
args.fGeomProc.cast<MeshTestProcessor>();
563 f->codeAppendf(
"half4 %s;",
args.fOutputColor);
566 if (!mp.fInstanceLocation.isInitialized()) {
567 v->codeAppendf(
"float2 vertex = %s;", mp.fVertexPosition.name());
569 if (mp.fVertexPosition.isInitialized()) {
570 v->codeAppendf(
"float2 offset = %s;", mp.fVertexPosition.name());
572 v->codeAppend(
"float2 offset = float2(sk_VertexID / 2, sk_VertexID % 2);");
574 v->codeAppendf(
"float2 vertex = %s + offset * %i;", mp.fInstanceLocation.name(),
579 f->codeAppendf(
"const half4 %s = half4(1);",
args.fOutputCoverage);
583 return std::make_unique<Impl>();
590 count*
sizeof(uint16_t),
610 bool hasVertexBuffer) {
624 std::move(processorSet),
641 const std::unique_ptr<skgpu::ganesh::SurfaceDrawContext>& sdc,
646 const uint32_t* goldPx =
reinterpret_cast<const uint32_t*
>(gold.
getPixels());
647 if (
h != sdc->height() ||
w != sdc->width()) {
660 sdc->readPixels(dContext, resultPM, {0, 0});
662#ifdef WRITE_PNG_CONTEXT_TYPE
663#define STRINGIFY(X) #X
664#define TOSTRING(X) STRINGIFY(X)
666 filename.
printf(
"GrMeshTest_%s_%s.png", TOSTRING(WRITE_PNG_CONTEXT_TYPE),
testName);
671 for (
int y = 0;
y <
h; ++
y) {
672 for (
int x = 0;
x <
w; ++
x) {
675 if (expected != actual) {
static GrColor GrColorPackRGBA(unsigned r, unsigned g, unsigned b, unsigned a)
constexpr uint16_t kIndexPattern[6]
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
static constexpr int kBoxCount
static constexpr int kBoxCountX
static constexpr int kIndexPatternRepeatCount
static constexpr int kImageWidth
static constexpr int kBoxCountY
SKGPU_DECLARE_STATIC_UNIQUE_KEY(gIndexBufferKey)
static void run_test(GrDirectContext *, const char *testName, skiatest::Reporter *, const std::unique_ptr< skgpu::ganesh::SurfaceDrawContext > &, const SkBitmap &gold, std::function< void(DrawMeshHelper *)> prepareFn, std::function< void(DrawMeshHelper *)> executeFn)
static constexpr int kBoxSize
static constexpr int kImageHeight
#define DEFINE_OP_CLASS_ID
@ kDynamic_GrAccessPattern
@ kFloat2_GrVertexAttribType
@ kUByte4_norm_GrVertexAttribType
#define SKGPU_DEFINE_STATIC_UNIQUE_KEY(name)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define INHERITED(method,...)
static constexpr bool SkToBool(const T &x)
#define DEF_GANESH_TEST_FOR_CONTEXTS( name, context_filter, reporter, context_info, options_filter, ctsEnforcement)
sk_sp< const GrBuffer > fInstBuffer
sk_sp< const GrBuffer > fIndexBuffer2
sk_sp< const GrBuffer > fVertBuffer
sk_sp< const GrBuffer > getIndexBuffer()
size_t fDrawIndirectBufferOffset
sk_sp< const GrBuffer > makeVertexBuffer(const std::vector< T > &data)
sk_sp< const GrBuffer > fDrawIndirectBuffer
GrMeshDrawTarget * target()
sk_sp< const GrBuffer > fVertBuffer2
sk_sp< const GrBuffer > fIndexBuffer
DrawMeshHelper(GrOpFlushState *state)
sk_sp< const GrBuffer > makeVertexBuffer(const TArray< T > &data)
sk_sp< const GrBuffer > makeIndexBuffer(const uint16_t[], int count)
GrOpsRenderPass * bindPipeline(GrPrimitiveType, bool isInstanced, bool hasVertexBuffer)
virtual FixedFunctionFlags fixedFunctionFlags() const
virtual GrProcessorSet::Analysis finalize(const GrCaps &, const GrAppliedClip *, GrClampType)=0
GrDrawOp(uint32_t classID)
void setData(const GrGLSLProgramDataManager &pdman, const GrFragmentProcessor &processor)
void emitAttributes(const GrGeometryProcessor &)
void addPassThroughAttribute(const GrShaderVar &vsVar, const char *output, Interpolation=Interpolation::kInterpolated)
GrGeometryProcessor(ClassID)
void setInstanceAttributesWithImplicitOffsets(const Attribute *attrs, int attrCount)
virtual std::unique_ptr< ProgramImpl > makeProgramImpl(const GrShaderCaps &) const =0
virtual void addToKey(const GrShaderCaps &, skgpu::KeyBuilder *) const =0
void setVertexAttributesWithImplicitOffsets(const Attribute *attrs, int attrCount)
GrLoadOp colorLoadOp() const final
GrXferBarrierFlags renderPassBarriers() const final
SkArenaAlloc * allocator() override
const GrAppliedClip * appliedClip() const final
const GrSurfaceProxyView & writeView() const final
GrResourceProvider * resourceProvider() const final
const GrCaps & caps() const final
GrOpsRenderPass * opsRenderPass()
bool usesMSAASurface() const final
virtual void onExecute(GrOpFlushState *, const SkRect &chainBounds)=0
static Owner Make(GrRecordingContext *context, Args &&... args)
std::unique_ptr< GrOp > Owner
virtual void onPrepare(GrOpFlushState *)=0
virtual const char * name() const =0
virtual void onPrePrepare(GrRecordingContext *, const GrSurfaceProxyView &writeView, GrAppliedClip *, const GrDstProxyView &, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp)=0
void setBounds(const SkRect &newBounds, HasAABloat aabloat, IsHairline zeroArea)
void bindPipeline(const GrProgramInfo &, const SkRect &drawBounds)
void bindBuffers(sk_sp< const GrBuffer > indexBuffer, sk_sp< const GrBuffer > instanceBuffer, sk_sp< const GrBuffer > vertexBuffer, GrPrimitiveRestart=GrPrimitiveRestart::kNo)
void drawIndexedIndirect(const GrBuffer *drawIndirectBuffer, size_t bufferOffset, int drawCount)
void drawIndirect(const GrBuffer *drawIndirectBuffer, size_t bufferOffset, int drawCount)
static GrPixmap Allocate(const GrImageInfo &info)
static constexpr Analysis EmptySetAnalysis()
Analysis finalize(const GrProcessorAnalysisColor &, const GrProcessorAnalysisCoverage, const GrAppliedClip *, const GrUserStencilSettings *, const GrCaps &, GrClampType, SkPMColor4f *inputColorOverride)
virtual const char * name() const =0
sk_sp< const GrGpuBuffer > findOrCreatePatternedIndexBuffer(const uint16_t *pattern, int patternSize, int reps, int vertCount, const skgpu::UniqueKey &key)
sk_sp< GrGpuBuffer > createBuffer(size_t size, GrGpuBufferType, GrAccessPattern, ZeroInit)
static const GrPipeline * CreatePipeline(const GrCaps *, SkArenaAlloc *, skgpu::Swizzle writeViewSwizzle, GrAppliedClip &&, const GrDstProxyView &, GrProcessorSet &&, GrPipeline::InputFlags pipelineFlags)
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
const SkImageInfo & info() const
void allocN32Pixels(int width, int height, bool isOpaque=false)
void drawRect(const SkRect &rect, const SkPaint &paint)
void printf(const char format[],...) SK_PRINTF_LIKE(2
const char * c_str() const
static std::unique_ptr< SurfaceDrawContext > Make(GrRecordingContext *, GrColorType, sk_sp< GrSurfaceProxy >, sk_sp< SkColorSpace >, GrSurfaceOrigin, const SkSurfaceProps &)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Dart_NativeFunction function
static float min(float r, float g, float b)
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
static const GrUserStencilSettings & kUnused
static SkRGBA4f FromBytes_RGBA(uint32_t color)
static SkRect MakeIWH(int w, int h)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
std::shared_ptr< const fml::Mapping > data