blob: 1bd18b081e5d367ed7498513f19d25e3265741db [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
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000017/**
18 * Represents the draw target capabilities.
19 */
20class GrDrawTargetCaps : public SkRefCnt {
21public:
bungemand6aeb6d2014-07-25 11:52:47 -070022 SK_DECLARE_INST_COUNT(GrDrawTargetCaps)
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000023
bsalomon17168df2014-12-09 09:00:49 -080024 /** Info about shader variable precision within a given shader stage. That is, this info
bsalomonc0bd6482014-12-09 10:04:14 -080025 is relevant to a float (or vecNf) variable declared with a GrSLPrecision
bsalomon17168df2014-12-09 09:00:49 -080026 in a given GrShaderType. The info here is hoisted from the OpenGL spec. */
27 struct PrecisionInfo {
28 PrecisionInfo() {
29 fLogRangeLow = 0;
30 fLogRangeHigh = 0;
31 fBits = 0;
32 }
33
34 /** Is this precision level allowed in the shader stage? */
35 bool supported() const { return 0 != fBits; }
36
37 bool operator==(const PrecisionInfo& that) const {
38 return fLogRangeLow == that.fLogRangeLow && fLogRangeHigh == that.fLogRangeHigh &&
39 fBits == that.fBits;
40 }
41 bool operator!=(const PrecisionInfo& that) const { return !(*this == that); }
42
43 /** floor(log2(|min_value|)) */
44 int fLogRangeLow;
45 /** floor(log2(|max_value|)) */
46 int fLogRangeHigh;
47 /** Number of bits of precision. As defined in OpenGL (with names modified to reflect this
48 struct) :
49 """
50 If the smallest representable value greater than 1 is 1 + e, then fBits will
51 contain floor(log2(e)), and every value in the range [2^fLogRangeLow,
52 2^fLogRangeHigh] can be represented to at least one part in 2^fBits.
53 """
54 */
55 int fBits;
56 };
57
58
egdanielbc127a32014-09-19 12:07:43 -070059 GrDrawTargetCaps() : fUniqueID(CreateUniqueID()) {
60 this->reset();
61 }
62 GrDrawTargetCaps(const GrDrawTargetCaps& other) : INHERITED(), fUniqueID(CreateUniqueID()) {
63 *this = other;
64 }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000065 GrDrawTargetCaps& operator= (const GrDrawTargetCaps&);
66
67 virtual void reset();
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +000068 virtual SkString dump() const;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000069
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000070 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
commit-bot@chromium.org47442312013-12-19 16:18:01 +000071 /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g.
72 only for POT textures) */
73 bool mipMapSupport() const { return fMipMapSupport; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000074 bool twoSidedStencilSupport() const { return fTwoSidedStencilSupport; }
75 bool stencilWrapOpsSupport() const { return fStencilWrapOpsSupport; }
76 bool hwAALineSupport() const { return fHWAALineSupport; }
77 bool shaderDerivativeSupport() const { return fShaderDerivativeSupport; }
78 bool geometryShaderSupport() const { return fGeometryShaderSupport; }
79 bool dualSourceBlendingSupport() const { return fDualSourceBlendingSupport; }
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +000080 bool pathRenderingSupport() const { return fPathRenderingSupport; }
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000081 bool dstReadInShaderSupport() const { return fDstReadInShaderSupport; }
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000082 bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; }
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +000083 bool gpuTracingSupport() const { return fGpuTracingSupport; }
krajcevski786978162014-07-30 11:25:44 -070084 bool compressedTexSubImageSupport() const { return fCompressedTexSubImageSupport; }
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +000085
bsalomon63b21962014-11-05 07:05:34 -080086 bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; }
87
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000088 /**
89 * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and
90 * textures allows partial mappings or full mappings.
91 */
92 enum MapFlags {
93 kNone_MapFlags = 0x0, //<! Cannot map the resource.
94
95 kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of
96 // the other flags to have meaning.k
97 kSubset_MapFlag = 0x2, //<! The resource can be partially mapped.
98 };
99
100 uint32_t mapBufferFlags() const { return fMapBufferFlags; }
101
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000102 // Scratch textures not being reused means that those scratch textures
skia.committer@gmail.com7ed98df2013-10-31 07:01:53 +0000103 // that we upload to (i.e., don't have a render target) will not be
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000104 // recycled in the texture cache. This is to prevent ghosting by drivers
105 // (in particular for deferred architectures).
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000106 bool reuseScratchTextures() const { return fReuseScratchTextures; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000107
108 int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
109 int maxTextureSize() const { return fMaxTextureSize; }
110 // Will be 0 if MSAA is not supported
111 int maxSampleCount() const { return fMaxSampleCount; }
112
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000113 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000114 SkASSERT(kGrPixelConfigCnt > config);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000115 return fConfigRenderSupport[config][withMSAA];
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000116 }
117
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000118 bool isConfigTexturable(GrPixelConfig config) const {
119 SkASSERT(kGrPixelConfigCnt > config);
120 return fConfigTextureSupport[config];
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000121 }
122
egdanielbc127a32014-09-19 12:07:43 -0700123 /**
bsalomon17168df2014-12-09 09:00:49 -0800124 * Get the precision info for a variable of type kFloat_GrSLType, kVec2f_GrSLType, etc in a
125 * given shader type. If the shader type is not supported or the precision level is not
126 * supported in that shader type then the returned struct will report false when supported() is
127 * called.
128 */
129 const PrecisionInfo& getFloatShaderPrecisionInfo(GrShaderType shaderType,
bsalomonc0bd6482014-12-09 10:04:14 -0800130 GrSLPrecision precision) const {
bsalomon17168df2014-12-09 09:00:49 -0800131 return fFloatPrecisions[shaderType][precision];
132 };
133
134 /**
135 * Is there any difference between the float shader variable precision types? If this is true
136 * then unless the shader type is not supported, any call to getFloatShaderPrecisionInfo() would
137 * report the same info for all precisions in all shader types.
138 */
139 bool floatPrecisionVaries() const { return fShaderPrecisionVaries; }
140
141 /**
egdanielbc127a32014-09-19 12:07:43 -0700142 * Gets an id that is unique for this GrDrawTargetCaps object. It is static in that it does
143 * not change when the content of the GrDrawTargetCaps object changes. This will never return
144 * 0.
145 */
146 uint32_t getUniqueID() const { return fUniqueID; }
147
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000148protected:
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000149 bool fNPOTTextureTileSupport : 1;
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000150 bool fMipMapSupport : 1;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000151 bool fTwoSidedStencilSupport : 1;
152 bool fStencilWrapOpsSupport : 1;
153 bool fHWAALineSupport : 1;
154 bool fShaderDerivativeSupport : 1;
155 bool fGeometryShaderSupport : 1;
156 bool fDualSourceBlendingSupport : 1;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000157 bool fPathRenderingSupport : 1;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000158 bool fDstReadInShaderSupport : 1;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000159 bool fDiscardRenderTargetSupport: 1;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000160 bool fReuseScratchTextures : 1;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000161 bool fGpuTracingSupport : 1;
krajcevski786978162014-07-30 11:25:44 -0700162 bool fCompressedTexSubImageSupport : 1;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000163
bsalomon63b21962014-11-05 07:05:34 -0800164 // Driver workaround
165 bool fUseDrawInsteadOfClear : 1;
166
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000167 uint32_t fMapBufferFlags;
168
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000169 int fMaxRenderTargetSize;
170 int fMaxTextureSize;
171 int fMaxSampleCount;
172
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000173 // The first entry for each config is without msaa and the second is with.
174 bool fConfigRenderSupport[kGrPixelConfigCnt][2];
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000175 bool fConfigTextureSupport[kGrPixelConfigCnt];
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000176
bsalomon17168df2014-12-09 09:00:49 -0800177 bool fShaderPrecisionVaries;
bsalomonc0bd6482014-12-09 10:04:14 -0800178 PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount];
bsalomon17168df2014-12-09 09:00:49 -0800179
egdanielbc127a32014-09-19 12:07:43 -0700180private:
181 static uint32_t CreateUniqueID();
182
183 const uint32_t fUniqueID;
184
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000185 typedef SkRefCnt INHERITED;
186};
187
188#endif