blob: 0f7a712dc65ee7b06963f4cb76d74898cb1b6afc [file] [log] [blame]
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001
2/*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00008#ifndef GrDrawTargetCaps_DEFINED
9#define GrDrawTargetCaps_DEFINED
10
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +000011#include "GrTypes.h"
bsalomon17168df2014-12-09 09:00:49 -080012#include "GrTypesPriv.h"
13#include "GrShaderVar.h"
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +000014#include "SkRefCnt.h"
15#include "SkString.h"
16
jvanverthe9c0fc62015-04-29 11:18:05 -070017class GrShaderCaps : public SkRefCnt {
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000018public:
jvanverthe9c0fc62015-04-29 11:18:05 -070019 SK_DECLARE_INST_COUNT(GrShaderCaps)
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000020
bsalomon17168df2014-12-09 09:00:49 -080021 /** Info about shader variable precision within a given shader stage. That is, this info
bsalomonc0bd6482014-12-09 10:04:14 -080022 is relevant to a float (or vecNf) variable declared with a GrSLPrecision
bsalomon17168df2014-12-09 09:00:49 -080023 in a given GrShaderType. The info here is hoisted from the OpenGL spec. */
24 struct PrecisionInfo {
25 PrecisionInfo() {
26 fLogRangeLow = 0;
27 fLogRangeHigh = 0;
28 fBits = 0;
29 }
30
31 /** Is this precision level allowed in the shader stage? */
32 bool supported() const { return 0 != fBits; }
33
34 bool operator==(const PrecisionInfo& that) const {
35 return fLogRangeLow == that.fLogRangeLow && fLogRangeHigh == that.fLogRangeHigh &&
36 fBits == that.fBits;
37 }
38 bool operator!=(const PrecisionInfo& that) const { return !(*this == that); }
39
40 /** floor(log2(|min_value|)) */
41 int fLogRangeLow;
42 /** floor(log2(|max_value|)) */
43 int fLogRangeHigh;
jvanverthe9c0fc62015-04-29 11:18:05 -070044 /** Number of bits of precision. As defined in OpenGL (with names modified to reflect this
bsalomon17168df2014-12-09 09:00:49 -080045 struct) :
46 """
jvanverthe9c0fc62015-04-29 11:18:05 -070047 If the smallest representable value greater than 1 is 1 + e, then fBits will
48 contain floor(log2(e)), and every value in the range [2^fLogRangeLow,
49 2^fLogRangeHigh] can be represented to at least one part in 2^fBits.
50 """
bsalomon17168df2014-12-09 09:00:49 -080051 */
52 int fBits;
53 };
54
jvanverthe9c0fc62015-04-29 11:18:05 -070055 GrShaderCaps() {
56 this->reset();
57 }
58 virtual ~GrShaderCaps() {}
59 GrShaderCaps(const GrShaderCaps& other) : INHERITED() {
60 *this = other;
61 }
62 GrShaderCaps& operator= (const GrShaderCaps&);
63
64 virtual void reset();
65 virtual SkString dump() const;
66
67 bool shaderDerivativeSupport() const { return fShaderDerivativeSupport; }
68 bool geometryShaderSupport() const { return fGeometryShaderSupport; }
69 bool pathRenderingSupport() const { return fPathRenderingSupport; }
70 bool dstReadInShaderSupport() const { return fDstReadInShaderSupport; }
71 bool dualSourceBlendingSupport() const { return fDualSourceBlendingSupport; }
72
73 /**
74 * Get the precision info for a variable of type kFloat_GrSLType, kVec2f_GrSLType, etc in a
75 * given shader type. If the shader type is not supported or the precision level is not
76 * supported in that shader type then the returned struct will report false when supported() is
77 * called.
78 */
79 const PrecisionInfo& getFloatShaderPrecisionInfo(GrShaderType shaderType,
80 GrSLPrecision precision) const {
81 return fFloatPrecisions[shaderType][precision];
82 };
83
84 /**
85 * Is there any difference between the float shader variable precision types? If this is true
86 * then unless the shader type is not supported, any call to getFloatShaderPrecisionInfo() would
87 * report the same info for all precisions in all shader types.
88 */
89 bool floatPrecisionVaries() const { return fShaderPrecisionVaries; }
90
91protected:
92 bool fShaderDerivativeSupport : 1;
93 bool fGeometryShaderSupport : 1;
94 bool fPathRenderingSupport : 1;
95 bool fDstReadInShaderSupport : 1;
96 bool fDualSourceBlendingSupport : 1;
97
98 bool fShaderPrecisionVaries;
99 PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount];
100
101private:
102 typedef SkRefCnt INHERITED;
103};
104
105/**
106 * Represents the draw target capabilities.
107 */
108class GrDrawTargetCaps : public SkRefCnt {
109public:
110 SK_DECLARE_INST_COUNT(GrDrawTargetCaps)
bsalomon17168df2014-12-09 09:00:49 -0800111
egdaniel9665eee2015-03-26 10:13:05 -0700112 GrDrawTargetCaps() {
jvanverthe9c0fc62015-04-29 11:18:05 -0700113 fShaderCaps.reset(NULL);
egdanielbc127a32014-09-19 12:07:43 -0700114 this->reset();
115 }
egdaniel9665eee2015-03-26 10:13:05 -0700116 GrDrawTargetCaps(const GrDrawTargetCaps& other) : INHERITED() {
egdanielbc127a32014-09-19 12:07:43 -0700117 *this = other;
118 }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000119 GrDrawTargetCaps& operator= (const GrDrawTargetCaps&);
120
121 virtual void reset();
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000122 virtual SkString dump() const;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000123
jvanverthe9c0fc62015-04-29 11:18:05 -0700124 GrShaderCaps* shaderCaps() const { return fShaderCaps; }
125
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000126 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000127 /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g.
128 only for POT textures) */
129 bool mipMapSupport() const { return fMipMapSupport; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000130 bool twoSidedStencilSupport() const { return fTwoSidedStencilSupport; }
131 bool stencilWrapOpsSupport() const { return fStencilWrapOpsSupport; }
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000132 bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; }
egdanielbdad9c32015-03-05 12:19:17 -0800133#if GR_FORCE_GPU_TRACE_DEBUGGING
134 bool gpuTracingSupport() const { return true; }
135#else
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000136 bool gpuTracingSupport() const { return fGpuTracingSupport; }
egdanielbdad9c32015-03-05 12:19:17 -0800137#endif
krajcevski786978162014-07-30 11:25:44 -0700138 bool compressedTexSubImageSupport() const { return fCompressedTexSubImageSupport; }
bsalomond08ea5f2015-02-20 06:58:13 -0800139 bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
cdaltonfd4167d2015-04-21 11:45:56 -0700140 bool textureBarrierSupport() const { return fTextureBarrierSupport; }
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000141
bsalomon63b21962014-11-05 07:05:34 -0800142 bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; }
143
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000144 /**
cdalton8917d622015-05-06 13:40:21 -0700145 * Indicates the capabilities of the fixed function blend unit.
146 */
147 enum BlendEquationSupport {
148 kBasic_BlendEquationSupport, //<! Support to select the operator that
149 // combines src and dst terms.
150 kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific
151 // SVG/PDF blend modes. Requires blend barriers.
152 kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not
153 // require blend barriers, and permits overlap.
154
155 kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport
156 };
157
158 BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
159
160 bool advancedBlendEquationSupport() const {
161 return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
162 }
163
164 bool advancedCoherentBlendEquationSupport() const {
165 return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
166 }
167
168 /**
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000169 * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and
170 * textures allows partial mappings or full mappings.
171 */
172 enum MapFlags {
173 kNone_MapFlags = 0x0, //<! Cannot map the resource.
174
175 kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of
176 // the other flags to have meaning.k
177 kSubset_MapFlag = 0x2, //<! The resource can be partially mapped.
178 };
179
180 uint32_t mapBufferFlags() const { return fMapBufferFlags; }
181
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000182 // Scratch textures not being reused means that those scratch textures
skia.committer@gmail.com7ed98df2013-10-31 07:01:53 +0000183 // that we upload to (i.e., don't have a render target) will not be
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000184 // recycled in the texture cache. This is to prevent ghosting by drivers
185 // (in particular for deferred architectures).
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000186 bool reuseScratchTextures() const { return fReuseScratchTextures; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000187
188 int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
189 int maxTextureSize() const { return fMaxTextureSize; }
190 // Will be 0 if MSAA is not supported
191 int maxSampleCount() const { return fMaxSampleCount; }
192
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000193 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000194 SkASSERT(kGrPixelConfigCnt > config);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000195 return fConfigRenderSupport[config][withMSAA];
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000196 }
197
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000198 bool isConfigTexturable(GrPixelConfig config) const {
199 SkASSERT(kGrPixelConfigCnt > config);
200 return fConfigTextureSupport[config];
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000201 }
202
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000203protected:
jvanverthe9c0fc62015-04-29 11:18:05 -0700204 SkAutoTUnref<GrShaderCaps> fShaderCaps;
205
bsalomond08ea5f2015-02-20 06:58:13 -0800206 bool fNPOTTextureTileSupport : 1;
207 bool fMipMapSupport : 1;
208 bool fTwoSidedStencilSupport : 1;
209 bool fStencilWrapOpsSupport : 1;
bsalomond08ea5f2015-02-20 06:58:13 -0800210 bool fDiscardRenderTargetSupport : 1;
211 bool fReuseScratchTextures : 1;
212 bool fGpuTracingSupport : 1;
213 bool fCompressedTexSubImageSupport : 1;
214 bool fOversizedStencilSupport : 1;
cdaltonfd4167d2015-04-21 11:45:56 -0700215 bool fTextureBarrierSupport : 1;
bsalomon63b21962014-11-05 07:05:34 -0800216 // Driver workaround
bsalomond08ea5f2015-02-20 06:58:13 -0800217 bool fUseDrawInsteadOfClear : 1;
bsalomon63b21962014-11-05 07:05:34 -0800218
cdalton8917d622015-05-06 13:40:21 -0700219 BlendEquationSupport fBlendEquationSupport;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000220 uint32_t fMapBufferFlags;
221
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000222 int fMaxRenderTargetSize;
223 int fMaxTextureSize;
224 int fMaxSampleCount;
225
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000226 // The first entry for each config is without msaa and the second is with.
227 bool fConfigRenderSupport[kGrPixelConfigCnt][2];
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000228 bool fConfigTextureSupport[kGrPixelConfigCnt];
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000229
egdanielbc127a32014-09-19 12:07:43 -0700230private:
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000231 typedef SkRefCnt INHERITED;
232};
233
234#endif