diff options
Diffstat (limited to 'src/gpu/vk')
-rw-r--r-- | src/gpu/vk/GrVkCaps.cpp | 1 | ||||
-rw-r--r-- | src/gpu/vk/GrVkPipelineState.cpp | 9 | ||||
-rw-r--r-- | src/gpu/vk/GrVkPipelineState.h | 3 | ||||
-rw-r--r-- | src/gpu/vk/GrVkTexture.cpp | 40 | ||||
-rw-r--r-- | src/gpu/vk/GrVkTexture.h | 3 | ||||
-rw-r--r-- | src/gpu/vk/GrVkUtil.cpp | 99 | ||||
-rw-r--r-- | src/gpu/vk/GrVkUtil.h | 6 |
7 files changed, 152 insertions, 9 deletions
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp index 746499f9b0..db21cc2f82 100644 --- a/src/gpu/vk/GrVkCaps.cpp +++ b/src/gpu/vk/GrVkCaps.cpp @@ -21,6 +21,7 @@ GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* * GrDrawTargetCaps fields **************************************************************************/ fMipMapSupport = true; // always available in Vulkan + fSRGBSupport = true; // always available in Vulkan fNPOTTextureTileSupport = false; //TODO: figure this out fTwoSidedStencilSupport = true; // always available in Vulkan fStencilWrapOpsSupport = false; //TODO: figure this out diff --git a/src/gpu/vk/GrVkPipelineState.cpp b/src/gpu/vk/GrVkPipelineState.cpp index 8e52fb46c0..0ebd1dd7fd 100644 --- a/src/gpu/vk/GrVkPipelineState.cpp +++ b/src/gpu/vk/GrVkPipelineState.cpp @@ -203,7 +203,7 @@ void GrVkPipelineState::setData(GrVkGpu* gpu, if (fNumSamplers) { fSamplerPoolManager.getNewDescriptorSet(gpu, &fDescriptorSets[GrVkUniformHandler::kSamplerDescSet]); - this->writeSamplers(gpu, textureBindings); + this->writeSamplers(gpu, textureBindings, pipeline.getAllowSRGBInputs()); } if (fVertexUniformBuffer.get() || fFragmentUniformBuffer.get()) { @@ -286,7 +286,8 @@ void GrVkPipelineState::writeUniformBuffers(const GrVkGpu* gpu) { } void GrVkPipelineState::writeSamplers(GrVkGpu* gpu, - const SkTArray<const GrTextureAccess*>& textureBindings) { + const SkTArray<const GrTextureAccess*>& textureBindings, + bool allowSRGBInputs) { SkASSERT(fNumSamplers == textureBindings.count()); for (int i = 0; i < textureBindings.count(); ++i) { @@ -307,7 +308,7 @@ void GrVkPipelineState::writeSamplers(GrVkGpu* gpu, textureResource->ref(); fTextures.push(textureResource); - const GrVkImageView* textureView = texture->textureView(); + const GrVkImageView* textureView = texture->textureView(allowSRGBInputs); textureView->ref(); fTextureViews.push(textureView); @@ -321,7 +322,7 @@ void GrVkPipelineState::writeSamplers(GrVkGpu* gpu, VkDescriptorImageInfo imageInfo; memset(&imageInfo, 0, sizeof(VkDescriptorImageInfo)); imageInfo.sampler = fSamplers[i]->sampler(); - imageInfo.imageView = texture->textureView()->imageView(); + imageInfo.imageView = textureView->imageView(); imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; VkWriteDescriptorSet writeInfo; diff --git a/src/gpu/vk/GrVkPipelineState.h b/src/gpu/vk/GrVkPipelineState.h index d0b0f564de..ea988861ef 100644 --- a/src/gpu/vk/GrVkPipelineState.h +++ b/src/gpu/vk/GrVkPipelineState.h @@ -200,7 +200,8 @@ private: void writeUniformBuffers(const GrVkGpu* gpu); - void writeSamplers(GrVkGpu* gpu, const SkTArray<const GrTextureAccess*>& textureBindings); + void writeSamplers(GrVkGpu* gpu, const SkTArray<const GrTextureAccess*>& textureBindings, + bool allowSRGBInputs); /** * We use the RT's size and origin to adjust from Skia device space to vulkan normalized device diff --git a/src/gpu/vk/GrVkTexture.cpp b/src/gpu/vk/GrVkTexture.cpp index 8278d27437..c2a30a27f4 100644 --- a/src/gpu/vk/GrVkTexture.cpp +++ b/src/gpu/vk/GrVkTexture.cpp @@ -24,7 +24,8 @@ GrVkTexture::GrVkTexture(GrVkGpu* gpu, : GrSurface(gpu, desc) , GrVkImage(imageResource) , INHERITED(gpu, desc, kSampler2D_GrSLType, desc.fIsMipMapped) - , fTextureView(view) { + , fTextureView(view) + , fLinearTextureView(nullptr) { this->registerWithCache(budgeted); } @@ -36,7 +37,8 @@ GrVkTexture::GrVkTexture(GrVkGpu* gpu, : GrSurface(gpu, desc) , GrVkImage(imageResource) , INHERITED(gpu, desc, kSampler2D_GrSLType, desc.fIsMipMapped) - , fTextureView(view) { + , fTextureView(view) + , fLinearTextureView(nullptr) { this->registerWithCacheWrapped(); } @@ -48,7 +50,8 @@ GrVkTexture::GrVkTexture(GrVkGpu* gpu, : GrSurface(gpu, desc) , GrVkImage(imageResource) , INHERITED(gpu, desc, kSampler2D_GrSLType, desc.fIsMipMapped) - , fTextureView(view) {} + , fTextureView(view) + , fLinearTextureView(nullptr) {} template<typename ResourceType> @@ -126,6 +129,7 @@ GrVkTexture* GrVkTexture::CreateWrappedTexture(GrVkGpu* gpu, GrVkTexture::~GrVkTexture() { // either release or abandon should have been called by the owner of this object. SkASSERT(!fTextureView); + SkASSERT(!fLinearTextureView); } void GrVkTexture::onRelease() { @@ -135,6 +139,11 @@ void GrVkTexture::onRelease() { fTextureView = nullptr; } + if (fLinearTextureView) { + fLinearTextureView->unref(this->getVkGpu()); + fLinearTextureView = nullptr; + } + this->releaseImage(this->getVkGpu()); INHERITED::onRelease(); @@ -146,6 +155,11 @@ void GrVkTexture::onAbandon() { fTextureView = nullptr; } + if (fLinearTextureView) { + fLinearTextureView->unrefAndAbandon(); + fLinearTextureView = nullptr; + } + this->abandonImage(); INHERITED::onAbandon(); } @@ -160,6 +174,22 @@ GrVkGpu* GrVkTexture::getVkGpu() const { return static_cast<GrVkGpu*>(this->getGpu()); } +const GrVkImageView* GrVkTexture::textureView(bool allowSRGB) { + VkFormat linearFormat; + if (allowSRGB || !GrVkFormatIsSRGB(fResource->fFormat, &linearFormat)) { + return fTextureView; + } + + if (!fLinearTextureView) { + fLinearTextureView = GrVkImageView::Create(this->getVkGpu(), fResource->fImage, + linearFormat, GrVkImageView::kColor_Type, + fResource->fLevelCount); + SkASSERT(fLinearTextureView); + } + + return fLinearTextureView; +} + bool GrVkTexture::reallocForMipmap(const GrVkGpu* gpu, uint32_t mipLevels) { if (mipLevels == 1) { // don't need to do anything for a 1x1 texture @@ -210,6 +240,10 @@ bool GrVkTexture::reallocForMipmap(const GrVkGpu* gpu, uint32_t mipLevels) { oldResource->unref(gpu); oldView->unref(gpu); + if (fLinearTextureView) { + fLinearTextureView->unref(gpu); + fLinearTextureView = nullptr; + } fResource = imageResource; fTextureView = textureView; fCurrentLayout = VK_IMAGE_LAYOUT_UNDEFINED; diff --git a/src/gpu/vk/GrVkTexture.h b/src/gpu/vk/GrVkTexture.h index c8fb917347..eae75ea131 100644 --- a/src/gpu/vk/GrVkTexture.h +++ b/src/gpu/vk/GrVkTexture.h @@ -31,7 +31,7 @@ public: void textureParamsModified() override {} - const GrVkImageView* textureView() const { return fTextureView; } + const GrVkImageView* textureView(bool allowSRGB); bool reallocForMipmap(const GrVkGpu* gpu, uint32_t mipLevels); @@ -56,6 +56,7 @@ private: const GrVkImage::Resource*, const GrVkImageView* imageView); const GrVkImageView* fTextureView; + const GrVkImageView* fLinearTextureView; typedef GrTexture INHERITED; }; diff --git a/src/gpu/vk/GrVkUtil.cpp b/src/gpu/vk/GrVkUtil.cpp index a6a9d4c1a1..760b20b458 100644 --- a/src/gpu/vk/GrVkUtil.cpp +++ b/src/gpu/vk/GrVkUtil.cpp @@ -118,6 +118,105 @@ bool GrVkFormatToPixelConfig(VkFormat format, GrPixelConfig* config) { return true; } +bool GrVkFormatIsSRGB(VkFormat format, VkFormat* linearFormat) { + VkFormat linearFmt = format; + switch (format) { + case VK_FORMAT_R8_SRGB: + linearFmt = VK_FORMAT_R8_UNORM; + break; + case VK_FORMAT_R8G8_SRGB: + linearFmt = VK_FORMAT_R8G8_UNORM; + break; + case VK_FORMAT_R8G8B8_SRGB: + linearFmt = VK_FORMAT_R8G8B8_UNORM; + break; + case VK_FORMAT_B8G8R8_SRGB: + linearFmt = VK_FORMAT_B8G8R8_UNORM; + break; + case VK_FORMAT_R8G8B8A8_SRGB: + linearFmt = VK_FORMAT_R8G8B8A8_UNORM; + break; + case VK_FORMAT_B8G8R8A8_SRGB: + linearFmt = VK_FORMAT_B8G8R8A8_UNORM; + break; + case VK_FORMAT_A8B8G8R8_SRGB_PACK32: + linearFmt = VK_FORMAT_A8B8G8R8_UNORM_PACK32; + break; + case VK_FORMAT_BC1_RGB_SRGB_BLOCK: + linearFmt = VK_FORMAT_BC1_RGB_UNORM_BLOCK; + break; + case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: + linearFmt = VK_FORMAT_BC1_RGBA_UNORM_BLOCK; + break; + case VK_FORMAT_BC2_SRGB_BLOCK: + linearFmt = VK_FORMAT_BC2_UNORM_BLOCK; + break; + case VK_FORMAT_BC3_SRGB_BLOCK: + linearFmt = VK_FORMAT_BC3_UNORM_BLOCK; + break; + case VK_FORMAT_BC7_SRGB_BLOCK: + linearFmt = VK_FORMAT_BC7_UNORM_BLOCK; + break; + case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: + linearFmt = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; + break; + case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: + linearFmt = VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK; + break; + case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: + linearFmt = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_4x4_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_5x4_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_5x5_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_6x5_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_6x6_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_8x5_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_8x6_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_8x8_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_10x5_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_10x6_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_10x8_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_10x10_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_12x10_UNORM_BLOCK; + break; + case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: + linearFmt = VK_FORMAT_ASTC_12x12_UNORM_BLOCK; + break; + default: + break; + } + if (linearFormat) { + *linearFormat = linearFmt; + } + return (linearFmt != format); +} + bool GrSampleCountToVkSampleCount(uint32_t samples, VkSampleCountFlagBits* vkSamples) { switch (samples) { case 0: // fall through diff --git a/src/gpu/vk/GrVkUtil.h b/src/gpu/vk/GrVkUtil.h index c2227ec02d..b81aff4ae3 100644 --- a/src/gpu/vk/GrVkUtil.h +++ b/src/gpu/vk/GrVkUtil.h @@ -35,6 +35,12 @@ bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format); */ bool GrVkFormatToPixelConfig(VkFormat format, GrPixelConfig* config); +/** + * Returns true if the given vulkan texture format is sRGB encoded. + * Also provides the non-sRGB version, if there is one. + */ +bool GrVkFormatIsSRGB(VkFormat format, VkFormat* linearFormat); + bool GrSampleCountToVkSampleCount(uint32_t samples, VkSampleCountFlagBits* vkSamples); #endif |