bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 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 | |
| 8 | // This is a GPU-backend specific test. It relies on static intializers to work |
| 9 | |
| 10 | #include "SkTypes.h" |
| 11 | #include "Test.h" |
| 12 | |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 13 | #include "GrContext.h" |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 14 | #include "GrContextPriv.h" |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 15 | #include "GrGeometryProcessor.h" |
| 16 | #include "GrGpu.h" |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 17 | #include "GrMemoryPool.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 18 | #include "GrOpFlushState.h" |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 19 | #include "GrRenderTargetContext.h" |
| 20 | #include "GrRenderTargetContextPriv.h" |
Cary Clark | 74f623d | 2017-11-06 20:02:02 -0500 | [diff] [blame] | 21 | #include "SkPointPriv.h" |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 22 | #include "SkString.h" |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 23 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 24 | #include "glsl/GrGLSLGeometryProcessor.h" |
| 25 | #include "glsl/GrGLSLVarying.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 26 | #include "ops/GrMeshDrawOp.h" |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 27 | |
| 28 | namespace { |
Brian Salomon | b4b8a46 | 2017-07-13 15:29:47 -0400 | [diff] [blame] | 29 | class Op : public GrMeshDrawOp { |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 30 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 31 | DEFINE_OP_CLASS_ID |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 32 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 33 | const char* name() const override { return "Dummy Op"; } |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 34 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 35 | static std::unique_ptr<GrDrawOp> Make(GrContext* context, int numAttribs) { |
Brian Salomon | b4b8a46 | 2017-07-13 15:29:47 -0400 | [diff] [blame] | 36 | return std::unique_ptr<GrDrawOp>(new Op(numAttribs)); |
| 37 | } |
| 38 | |
| 39 | FixedFunctionFlags fixedFunctionFlags() const override { |
| 40 | return FixedFunctionFlags::kNone; |
| 41 | } |
| 42 | |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 43 | RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*,\ |
| 44 | GrPixelConfigIsClamped) override { |
Brian Salomon | b4b8a46 | 2017-07-13 15:29:47 -0400 | [diff] [blame] | 45 | return RequiresDstTexture::kNo; |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 46 | } |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 47 | |
| 48 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 49 | friend class ::GrOpMemoryPool; |
| 50 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 51 | Op(int numAttribs) : INHERITED(ClassID()), fNumAttribs(numAttribs) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 52 | this->setBounds(SkRect::MakeWH(1.f, 1.f), HasAABloat::kNo, IsZeroArea::kNo); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 55 | bool onCombineIfPossible(GrOp*, const GrCaps&) override { return false; } |
Brian Salomon | b4b8a46 | 2017-07-13 15:29:47 -0400 | [diff] [blame] | 56 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 57 | void onPrepareDraws(Target* target) override { |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 58 | class GP : public GrGeometryProcessor { |
| 59 | public: |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 60 | GP(int numAttribs) |
| 61 | : INHERITED(kGP_ClassID) { |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 62 | SkASSERT(numAttribs > 1); |
| 63 | for (auto i = 0; i < numAttribs; ++i) { |
| 64 | fAttribNames.push_back().printf("attr%d", i); |
| 65 | } |
| 66 | for (auto i = 0; i < numAttribs; ++i) { |
Ethan Nicholas | fa7ee24 | 2017-09-25 09:52:04 -0400 | [diff] [blame] | 67 | this->addVertexAttrib(fAttribNames[i].c_str(), kFloat2_GrVertexAttribType); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 68 | } |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 69 | } |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 70 | const char* name() const override { return "Dummy GP"; } |
| 71 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 72 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override { |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 73 | class GLSLGP : public GrGLSLGeometryProcessor { |
| 74 | public: |
| 75 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
| 76 | const GP& gp = args.fGP.cast<GP>(); |
| 77 | args.fVaryingHandler->emitAttributes(gp); |
Brian Salomon | 70132d0 | 2018-05-29 15:33:06 -0400 | [diff] [blame] | 78 | this->writeOutputPosition(args.fVertBuilder, gpArgs, |
| 79 | gp.getAttrib(0).name()); |
Chris Dalton | 6028361 | 2018-02-14 13:38:14 -0700 | [diff] [blame] | 80 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 81 | fragBuilder->codeAppendf("%s = half4(1);", args.fOutputColor); |
| 82 | fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 83 | } |
| 84 | void setData(const GrGLSLProgramDataManager& pdman, |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 85 | const GrPrimitiveProcessor& primProc, |
| 86 | FPCoordTransformIter&&) override {} |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 87 | }; |
| 88 | return new GLSLGP(); |
| 89 | } |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 90 | void getGLSLProcessorKey(const GrShaderCaps&, |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 91 | GrProcessorKeyBuilder* builder) const override { |
| 92 | builder->add32(this->numAttribs()); |
| 93 | } |
| 94 | |
| 95 | private: |
| 96 | SkTArray<SkString> fAttribNames; |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 97 | |
| 98 | typedef GrGeometryProcessor INHERITED; |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 99 | }; |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 100 | sk_sp<GrGeometryProcessor> gp(new GP(fNumAttribs)); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 101 | QuadHelper helper; |
| 102 | size_t vertexStride = gp->getVertexStride(); |
| 103 | SkPoint* vertices = reinterpret_cast<SkPoint*>(helper.init(target, vertexStride, 1)); |
Cary Clark | 74f623d | 2017-11-06 20:02:02 -0500 | [diff] [blame] | 104 | SkPointPriv::SetRectTriStrip(vertices, 0.f, 0.f, 1.f, 1.f, vertexStride); |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 105 | helper.recordDraw(target, gp.get(), |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 106 | target->makePipeline(0, GrProcessorSet::MakeEmptySet(), |
| 107 | target->detachAppliedClip())); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | int fNumAttribs; |
| 111 | |
Brian Salomon | b4b8a46 | 2017-07-13 15:29:47 -0400 | [diff] [blame] | 112 | typedef GrMeshDrawOp INHERITED; |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 113 | }; |
| 114 | } |
| 115 | |
egdaniel | b05df0f | 2016-06-27 07:15:20 -0700 | [diff] [blame] | 116 | DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 117 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 118 | #if GR_GPU_STATS |
| 119 | GrGpu* gpu = context->contextPriv().getGpu(); |
| 120 | #endif |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 121 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 122 | sk_sp<GrRenderTargetContext> renderTargetContext( |
| 123 | context->contextPriv().makeDeferredRenderTargetContext(SkBackingFit::kApprox, |
| 124 | 1, 1, kRGBA_8888_GrPixelConfig, |
| 125 | nullptr)); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 126 | if (!renderTargetContext) { |
| 127 | ERRORF(reporter, "Could not create render target context."); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 128 | return; |
| 129 | } |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 130 | int attribCnt = context->contextPriv().caps()->maxVertexAttributes(); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 131 | if (!attribCnt) { |
| 132 | ERRORF(reporter, "No attributes allowed?!"); |
| 133 | return; |
| 134 | } |
| 135 | context->flush(); |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 136 | context->contextPriv().resetGpuStats(); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 137 | #if GR_GPU_STATS |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 138 | REPORTER_ASSERT(reporter, gpu->stats()->numDraws() == 0); |
| 139 | REPORTER_ASSERT(reporter, gpu->stats()->numFailedDraws() == 0); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 140 | #endif |
Greg Daniel | f44cb48 | 2018-02-27 14:26:32 -0500 | [diff] [blame] | 141 | // Adding discard to appease vulkan validation warning about loading uninitialized data on draw |
| 142 | renderTargetContext->discard(); |
| 143 | |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 144 | GrPaint grPaint; |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 145 | // This one should succeed. |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 146 | renderTargetContext->priv().testingOnly_addDrawOp(Op::Make(context, attribCnt)); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 147 | context->flush(); |
| 148 | #if GR_GPU_STATS |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 149 | REPORTER_ASSERT(reporter, gpu->stats()->numDraws() == 1); |
| 150 | REPORTER_ASSERT(reporter, gpu->stats()->numFailedDraws() == 0); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 151 | #endif |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 152 | context->contextPriv().resetGpuStats(); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 153 | renderTargetContext->priv().testingOnly_addDrawOp(Op::Make(context, attribCnt + 1)); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 154 | context->flush(); |
| 155 | #if GR_GPU_STATS |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 156 | REPORTER_ASSERT(reporter, gpu->stats()->numDraws() == 0); |
| 157 | REPORTER_ASSERT(reporter, gpu->stats()->numFailedDraws() == 1); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 158 | #endif |
| 159 | } |