OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrVkCaps.h" | 8 #include "GrVkCaps.h" |
9 | 9 |
10 #include "GrVkUtil.h" | 10 #include "GrVkUtil.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 VkPhysicalDevice physDev, uint32_t featureFlags, uint32_t ex
tensionFlags) { | 50 VkPhysicalDevice physDev, uint32_t featureFlags, uint32_t ex
tensionFlags) { |
51 | 51 |
52 VkPhysicalDeviceProperties properties; | 52 VkPhysicalDeviceProperties properties; |
53 GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties)); | 53 GR_VK_CALL(vkInterface, GetPhysicalDeviceProperties(physDev, &properties)); |
54 | 54 |
55 VkPhysicalDeviceMemoryProperties memoryProperties; | 55 VkPhysicalDeviceMemoryProperties memoryProperties; |
56 GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryPr
operties)); | 56 GR_VK_CALL(vkInterface, GetPhysicalDeviceMemoryProperties(physDev, &memoryPr
operties)); |
57 | 57 |
58 this->initGrCaps(properties, memoryProperties, featureFlags); | 58 this->initGrCaps(properties, memoryProperties, featureFlags); |
59 this->initGLSLCaps(properties, featureFlags); | 59 this->initGLSLCaps(properties, featureFlags); |
60 this->initConfigTexturableTable(vkInterface, physDev); | 60 this->initConfigTable(vkInterface, physDev); |
61 this->initConfigRenderableTable(vkInterface, physDev); | 61 this->initStencilFormat(vkInterface, physDev); |
62 this->initStencilFormats(vkInterface, physDev); | |
63 | 62 |
64 if (SkToBool(extensionFlags & kNV_glsl_shader_GrVkExtensionFlag)) { | 63 if (SkToBool(extensionFlags & kNV_glsl_shader_GrVkExtensionFlag)) { |
65 // Currently disabling this feature since it does not play well with val
idation layers which | 64 // Currently disabling this feature since it does not play well with val
idation layers which |
66 // expect a SPIR-V shader | 65 // expect a SPIR-V shader |
67 // fCanUseGLSLForShaderModule = true; | 66 // fCanUseGLSLForShaderModule = true; |
68 } | 67 } |
69 | 68 |
70 this->applyOptionsOverrides(contextOptions); | 69 this->applyOptionsOverrides(contextOptions); |
71 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get()); | 70 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get()); |
72 glslCaps->applyOptionsOverrides(contextOptions); | 71 glslCaps->applyOptionsOverrides(contextOptions); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 glslCaps->fIntegerSupport = true; | 154 glslCaps->fIntegerSupport = true; |
156 | 155 |
157 glslCaps->fMaxVertexSamplers = | 156 glslCaps->fMaxVertexSamplers = |
158 glslCaps->fMaxGeometrySamplers = | 157 glslCaps->fMaxGeometrySamplers = |
159 glslCaps->fMaxFragmentSamplers = SkTMin(properties.limits.maxPerStageDescrip
torSampledImages, | 158 glslCaps->fMaxFragmentSamplers = SkTMin(properties.limits.maxPerStageDescrip
torSampledImages, |
160 properties.limits.maxPerStageDescrip
torSamplers); | 159 properties.limits.maxPerStageDescrip
torSamplers); |
161 glslCaps->fMaxCombinedSamplers = SkTMin(properties.limits.maxDescriptorSetSa
mpledImages, | 160 glslCaps->fMaxCombinedSamplers = SkTMin(properties.limits.maxDescriptorSetSa
mpledImages, |
162 properties.limits.maxDescriptorSetSa
mplers); | 161 properties.limits.maxDescriptorSetSa
mplers); |
163 } | 162 } |
164 | 163 |
165 static void format_supported_for_feature(const GrVkInterface* interface, | 164 bool stencil_format_supported(const GrVkInterface* interface, |
166 VkPhysicalDevice physDev, | 165 VkPhysicalDevice physDev, |
167 VkFormat format, | 166 VkFormat format) { |
168 VkFormatFeatureFlagBits featureBit, | |
169 bool* linearSupport, | |
170 bool* optimalSupport) { | |
171 VkFormatProperties props; | 167 VkFormatProperties props; |
172 memset(&props, 0, sizeof(VkFormatProperties)); | 168 memset(&props, 0, sizeof(VkFormatProperties)); |
173 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &pr
ops)); | 169 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &pr
ops)); |
174 *linearSupport = SkToBool(props.linearTilingFeatures & featureBit); | 170 return SkToBool(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT & props.optim
alTilingFeatures); |
175 *optimalSupport = SkToBool(props.optimalTilingFeatures & featureBit); | |
176 } | 171 } |
177 | 172 |
178 static void config_supported_for_feature(const GrVkInterface* interface, | 173 void GrVkCaps::initStencilFormat(const GrVkInterface* interface, VkPhysicalDevic
e physDev) { |
179 VkPhysicalDevice physDev, | 174 // List of legal stencil formats (though perhaps not supported on |
180 GrPixelConfig config, | 175 // the particular gpu/driver) from most preferred to least. We are guarantee
d to have either |
181 VkFormatFeatureFlagBits featureBit, | 176 // VK_FORMAT_D24_UNORM_S8_UINT or VK_FORMAT_D24_SFLOAT_S8_UINT. VK_FORMAT_D3
2_SFLOAT_S8_UINT |
182 bool* linearSupport, | 177 // can optionally have 24 unused bits at the end so we assume the total bits
is 64. |
183 bool* optimalSupport) { | |
184 VkFormat format; | |
185 if (!GrPixelConfigToVkFormat(config, &format)) { | |
186 *linearSupport = false; | |
187 *optimalSupport = false; | |
188 return; | |
189 } | |
190 format_supported_for_feature(interface, physDev, format, featureBit, | |
191 linearSupport, optimalSupport); | |
192 } | |
193 | |
194 // Currently just assumeing if something can be rendered to without MSAA it also
works for MSAAA | |
195 #define SET_CONFIG_IS_RENDERABLE(config)
\ | |
196 config_supported_for_feature(interface,
\ | |
197 physDev,
\ | |
198 config, \ | |
199 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT,
\ | |
200 &fConfigLinearRenderSupport[config][kNo_MSAA],
\ | |
201 &fConfigRenderSupport[config][kNo_MSAA] );
\ | |
202 fConfigRenderSupport[config][kYes_MSAA] = fConfigRenderSupport[config][kNo_M
SAA]; \ | |
203 fConfigLinearRenderSupport[config][kYes_MSAA] = fConfigLinearRenderSupport[c
onfig][kNo_MSAA]; | |
204 | |
205 | |
206 void GrVkCaps::initConfigRenderableTable(const GrVkInterface* interface, VkPhysi
calDevice physDev) { | |
207 enum { | |
208 kNo_MSAA = 0, | |
209 kYes_MSAA = 1, | |
210 }; | |
211 | |
212 // Base render support | |
213 SET_CONFIG_IS_RENDERABLE(kAlpha_8_GrPixelConfig); | |
214 SET_CONFIG_IS_RENDERABLE(kRGB_565_GrPixelConfig); | |
215 SET_CONFIG_IS_RENDERABLE(kRGBA_4444_GrPixelConfig); | |
216 SET_CONFIG_IS_RENDERABLE(kRGBA_8888_GrPixelConfig); | |
217 SET_CONFIG_IS_RENDERABLE(kBGRA_8888_GrPixelConfig); | |
218 | |
219 SET_CONFIG_IS_RENDERABLE(kSRGBA_8888_GrPixelConfig); | |
220 | |
221 // Float render support | |
222 SET_CONFIG_IS_RENDERABLE(kRGBA_float_GrPixelConfig); | |
223 SET_CONFIG_IS_RENDERABLE(kRGBA_half_GrPixelConfig); | |
224 SET_CONFIG_IS_RENDERABLE(kAlpha_half_GrPixelConfig); | |
225 } | |
226 | |
227 #define SET_CONFIG_IS_TEXTURABLE(config) \ | |
228 config_supported_for_feature(interface, \ | |
229 physDev, \ | |
230 config, \ | |
231 VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT, \ | |
232 &fConfigLinearTextureSupport[config], \ | |
233 &fConfigTextureSupport[config]); | |
234 | |
235 void GrVkCaps::initConfigTexturableTable(const GrVkInterface* interface, VkPhysi
calDevice physDev) { | |
236 // Base texture support | |
237 SET_CONFIG_IS_TEXTURABLE(kAlpha_8_GrPixelConfig); | |
238 SET_CONFIG_IS_TEXTURABLE(kRGB_565_GrPixelConfig); | |
239 SET_CONFIG_IS_TEXTURABLE(kRGBA_4444_GrPixelConfig); | |
240 SET_CONFIG_IS_TEXTURABLE(kRGBA_8888_GrPixelConfig); | |
241 SET_CONFIG_IS_TEXTURABLE(kBGRA_8888_GrPixelConfig); | |
242 | |
243 SET_CONFIG_IS_TEXTURABLE(kIndex_8_GrPixelConfig); | |
244 SET_CONFIG_IS_TEXTURABLE(kSRGBA_8888_GrPixelConfig); | |
245 | |
246 // Compressed texture support | |
247 SET_CONFIG_IS_TEXTURABLE(kETC1_GrPixelConfig); | |
248 SET_CONFIG_IS_TEXTURABLE(kLATC_GrPixelConfig); | |
249 SET_CONFIG_IS_TEXTURABLE(kR11_EAC_GrPixelConfig); | |
250 SET_CONFIG_IS_TEXTURABLE(kASTC_12x12_GrPixelConfig); | |
251 | |
252 // Float texture support | |
253 SET_CONFIG_IS_TEXTURABLE(kRGBA_float_GrPixelConfig); | |
254 SET_CONFIG_IS_TEXTURABLE(kRGBA_half_GrPixelConfig); | |
255 SET_CONFIG_IS_TEXTURABLE(kAlpha_half_GrPixelConfig); | |
256 } | |
257 | |
258 #define SET_CONFIG_CAN_STENCIL(config)
\ | |
259 bool SK_MACRO_APPEND_LINE(linearSupported);
\ | |
260 bool SK_MACRO_APPEND_LINE(optimalSupported);
\ | |
261 format_supported_for_feature(interface,
\ | |
262 physDev,
\ | |
263 config.fInternalFormat,
\ | |
264 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT,
\ | |
265 &SK_MACRO_APPEND_LINE(linearSupported),
\ | |
266 &SK_MACRO_APPEND_LINE(optimalSupported));
\ | |
267 if (SK_MACRO_APPEND_LINE(linearSupported)) fLinearStencilFormats.push_back(c
onfig); \ | |
268 if (SK_MACRO_APPEND_LINE(optimalSupported)) fStencilFormats.push_back(config
); | |
269 | |
270 void GrVkCaps::initStencilFormats(const GrVkInterface* interface, VkPhysicalDevi
ce physDev) { | |
271 // Build up list of legal stencil formats (though perhaps not supported on | |
272 // the particular gpu/driver) from most preferred to least. | |
273 | |
274 static const StencilFormat | 178 static const StencilFormat |
275 // internal Format stencil bits total bits
packed? | 179 // internal Format stencil bits total bits
packed? |
276 gS8 = { VK_FORMAT_S8_UINT, 8, 8,
false }, | 180 gS8 = { VK_FORMAT_S8_UINT, 8, 8,
false }, |
277 gD24S8 = { VK_FORMAT_D24_UNORM_S8_UINT, 8, 32,
true }; | 181 gD24S8 = { VK_FORMAT_D24_UNORM_S8_UINT, 8, 32,
true }, |
| 182 gD32S8 = { VK_FORMAT_D32_SFLOAT_S8_UINT, 8, 64,
true }; |
278 | 183 |
279 // I'm simply assuming that these two will be supported since they are used
in example code. | 184 if (stencil_format_supported(interface, physDev, VK_FORMAT_S8_UINT)) { |
280 // TODO: Actaully figure this out | 185 fPreferedStencilFormat = gS8; |
281 SET_CONFIG_CAN_STENCIL(gS8); | 186 } else if (stencil_format_supported(interface, physDev, VK_FORMAT_D24_UNORM_
S8_UINT)) { |
282 SET_CONFIG_CAN_STENCIL(gD24S8); | 187 fPreferedStencilFormat = gD24S8; |
| 188 } else { |
| 189 SkASSERT(stencil_format_supported(interface, physDev, VK_FORMAT_D32_SFLO
AT_S8_UINT)); |
| 190 fPreferedStencilFormat = gD32S8; |
| 191 } |
283 } | 192 } |
| 193 |
| 194 void GrVkCaps::initConfigTable(const GrVkInterface* interface, VkPhysicalDevice
physDev) { |
| 195 for (int i = 0; i < kGrPixelConfigCnt; ++i) { |
| 196 VkFormat format; |
| 197 if (GrPixelConfigToVkFormat(static_cast<GrPixelConfig>(i), &format)) { |
| 198 fConfigTable[i].init(interface, physDev, format); |
| 199 } |
| 200 } |
| 201 } |
| 202 |
| 203 void GrVkCaps::ConfigInfo::InitConfigFlags(VkFormatFeatureFlags vkFlags, uint16_
t* flags) { |
| 204 if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) && |
| 205 SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) { |
| 206 *flags = *flags | kTextureable_Flag; |
| 207 } |
| 208 |
| 209 if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) { |
| 210 *flags = *flags | kRenderable_Flag; |
| 211 } |
| 212 |
| 213 if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) { |
| 214 *flags = *flags | kBlitSrc_Flag; |
| 215 } |
| 216 |
| 217 if (SkToBool(VK_FORMAT_FEATURE_BLIT_DST_BIT & vkFlags)) { |
| 218 *flags = *flags | kBlitDst_Flag; |
| 219 } |
| 220 } |
| 221 |
| 222 void GrVkCaps::ConfigInfo::init(const GrVkInterface* interface, |
| 223 VkPhysicalDevice physDev, |
| 224 VkFormat format) { |
| 225 VkFormatProperties props; |
| 226 memset(&props, 0, sizeof(VkFormatProperties)); |
| 227 GR_VK_CALL(interface, GetPhysicalDeviceFormatProperties(physDev, format, &pr
ops)); |
| 228 InitConfigFlags(props.linearTilingFeatures, &fLinearFlags); |
| 229 InitConfigFlags(props.optimalTilingFeatures, &fOptimalFlags); |
| 230 } |
OLD | NEW |