Commit bc0a7b58 by Courtney Goeltzenleuchter Committed by Commit Bot

Add support for sampling stencil texture

Suspect a potential driver issue with integer sampling from stencil so skip dEQP-GLES31.functional.stencil_texturing.misc.compare_mode_effect in the expectations file. Will follow-up with more directed tests. Also skip dEQP-GLES31.functional.stencil_texturing.misc.base_level Blocking Bug: angleproject:3148 Test: dEQP-GLES31.functional.stencil_texturing* Bug: angleproject:3575 Change-Id: I9547406b44ec16629631c1bf50907e6a24f1a20e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1736946 Commit-Queue: Courtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 5a2553a7
...@@ -134,6 +134,7 @@ class TextureState final : private angle::NonCopyable ...@@ -134,6 +134,7 @@ class TextureState final : private angle::NonCopyable
const SamplerState &getSamplerState() const { return mSamplerState; } const SamplerState &getSamplerState() const { return mSamplerState; }
GLenum getUsage() const { return mUsage; } GLenum getUsage() const { return mUsage; }
GLenum getDepthStencilTextureMode() const { return mDepthStencilTextureMode; } GLenum getDepthStencilTextureMode() const { return mDepthStencilTextureMode; }
bool isStencilMode() const { return mDepthStencilTextureMode == GL_STENCIL_INDEX; }
// Returns the desc of the base level. Only valid for cube-complete/mip-complete textures. // Returns the desc of the base level. Only valid for cube-complete/mip-complete textures.
const ImageDesc &getBaseLevelDesc() const; const ImageDesc &getBaseLevelDesc() const;
......
...@@ -71,8 +71,27 @@ uint32_t GetRenderTargetLayerCount(vk::ImageHelper *image) ...@@ -71,8 +71,27 @@ uint32_t GetRenderTargetLayerCount(vk::ImageHelper *image)
// Depth > 1 means this is a 3D texture and depth is our layer count // Depth > 1 means this is a 3D texture and depth is our layer count
return image->getExtents().depth > 1 ? image->getExtents().depth : image->getLayerCount(); return image->getExtents().depth > 1 ? image->getExtents().depth : image->getLayerCount();
} }
bool HasBothDepthAndStencilAspects(VkImageAspectFlags aspectFlags)
{
constexpr VkImageAspectFlags kDepthStencilAspects =
VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
return (aspectFlags & kDepthStencilAspects) == kDepthStencilAspects;
}
} // anonymous namespace } // anonymous namespace
TextureVk::TextureVkViews::TextureVkViews() {}
TextureVk::TextureVkViews::~TextureVkViews() {}
void TextureVk::TextureVkViews::release(ContextVk *contextVk, Serial currentSerial)
{
contextVk->releaseObject(currentSerial, &mDrawBaseLevelImageView);
contextVk->releaseObject(currentSerial, &mReadBaseLevelImageView);
contextVk->releaseObject(currentSerial, &mReadMipmapImageView);
contextVk->releaseObject(currentSerial, &mFetchBaseLevelImageView);
contextVk->releaseObject(currentSerial, &mFetchMipmapImageView);
}
angle::Result TextureVk::generateMipmapLevelsWithCPU(ContextVk *contextVk, angle::Result TextureVk::generateMipmapLevelsWithCPU(ContextVk *contextVk,
const angle::Format &sourceFormat, const angle::Format &sourceFormat,
GLuint layer, GLuint layer,
...@@ -907,8 +926,9 @@ void TextureVk::setImageHelper(ContextVk *contextVk, ...@@ -907,8 +926,9 @@ void TextureVk::setImageHelper(ContextVk *contextVk,
mImage->initStagingBuffer(contextVk->getRenderer(), format, vk::kStagingBufferFlags, mImage->initStagingBuffer(contextVk->getRenderer(), format, vk::kStagingBufferFlags,
mStagingBufferInitialSize); mStagingBufferInitialSize);
mRenderTarget.init(mImage, &mDrawBaseLevelImageView, &mFetchBaseLevelImageView, mRenderTarget.init(mImage, &mDefaultViews.mDrawBaseLevelImageView,
getNativeImageLevel(0), getNativeImageLayer(0)); &mDefaultViews.mFetchBaseLevelImageView, getNativeImageLevel(0),
getNativeImageLayer(0));
// Force re-creation of layered render targets next time they are needed // Force re-creation of layered render targets next time they are needed
mCubeMapRenderTargets.clear(); mCubeMapRenderTargets.clear();
...@@ -1290,6 +1310,16 @@ angle::Result TextureVk::syncState(const gl::Context *context, ...@@ -1290,6 +1310,16 @@ angle::Result TextureVk::syncState(const gl::Context *context,
float maxAnisotropy = samplerState.getMaxAnisotropy(); float maxAnisotropy = samplerState.getMaxAnisotropy();
bool anisotropyEnable = extensions.textureFilterAnisotropic && maxAnisotropy > 1.0f; bool anisotropyEnable = extensions.textureFilterAnisotropic && maxAnisotropy > 1.0f;
bool compareEnable = samplerState.getCompareMode() == GL_COMPARE_REF_TO_TEXTURE;
VkCompareOp compareOp = gl_vk::GetCompareOp(samplerState.getCompareFunc());
// When sampling from stencil, deqp tests expect texture compare to have no effect
// dEQP - GLES31.functional.stencil_texturing.misc.compare_mode_effect
// states: NOTE: Texture compare mode has no effect when reading stencil values.
if (mState.isStencilMode())
{
compareEnable = VK_FALSE;
compareOp = VK_COMPARE_OP_ALWAYS;
}
// Create a simple sampler. Force basic parameter settings. // Create a simple sampler. Force basic parameter settings.
VkSamplerCreateInfo samplerInfo = {}; VkSamplerCreateInfo samplerInfo = {};
...@@ -1304,8 +1334,8 @@ angle::Result TextureVk::syncState(const gl::Context *context, ...@@ -1304,8 +1334,8 @@ angle::Result TextureVk::syncState(const gl::Context *context,
samplerInfo.mipLodBias = 0.0f; samplerInfo.mipLodBias = 0.0f;
samplerInfo.anisotropyEnable = anisotropyEnable; samplerInfo.anisotropyEnable = anisotropyEnable;
samplerInfo.maxAnisotropy = maxAnisotropy; samplerInfo.maxAnisotropy = maxAnisotropy;
samplerInfo.compareEnable = samplerState.getCompareMode() == GL_COMPARE_REF_TO_TEXTURE; samplerInfo.compareEnable = compareEnable;
samplerInfo.compareOp = gl_vk::GetCompareOp(samplerState.getCompareFunc()); samplerInfo.compareOp = compareOp;
samplerInfo.minLod = samplerState.getMinLod(); samplerInfo.minLod = samplerState.getMinLod();
samplerInfo.maxLod = samplerState.getMaxLod(); samplerInfo.maxLod = samplerState.getMaxLod();
samplerInfo.borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK; samplerInfo.borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
...@@ -1352,33 +1382,46 @@ void TextureVk::releaseOwnershipOfImage(const gl::Context *context) ...@@ -1352,33 +1382,46 @@ void TextureVk::releaseOwnershipOfImage(const gl::Context *context)
releaseAndDeleteImage(contextVk); releaseAndDeleteImage(contextVk);
} }
const TextureVk::TextureVkViews *TextureVk::getTextureViews() const
{
VkImageAspectFlags aspectFlags = mImage->getAspectFlags();
if (HasBothDepthAndStencilAspects(aspectFlags) && mState.isStencilMode())
{
return &mStencilViews;
}
return &mDefaultViews;
}
const vk::ImageView &TextureVk::getReadImageView() const const vk::ImageView &TextureVk::getReadImageView() const
{ {
ASSERT(mImage->valid()); ASSERT(mImage->valid());
const TextureVkViews *activeView = getTextureViews();
if (!gl::IsMipmapFiltered(mState.getSamplerState())) if (!gl::IsMipmapFiltered(mState.getSamplerState()))
{ {
return mReadBaseLevelImageView; return activeView->mReadBaseLevelImageView;
} }
return mReadMipmapImageView; return activeView->mReadMipmapImageView;
} }
const vk::ImageView &TextureVk::getFetchImageView() const const vk::ImageView &TextureVk::getFetchImageView() const
{ {
if (!mFetchBaseLevelImageView.valid())
if (!mDefaultViews.mFetchBaseLevelImageView.valid())
{ {
return getReadImageView(); return getReadImageView();
} }
ASSERT(mImage->valid()); ASSERT(mImage->valid());
const TextureVkViews *activeView = getTextureViews();
if (!gl::IsMipmapFiltered(mState.getSamplerState())) if (!gl::IsMipmapFiltered(mState.getSamplerState()))
{ {
return mFetchBaseLevelImageView; return activeView->mFetchBaseLevelImageView;
} }
return mFetchMipmapImageView; return activeView->mFetchMipmapImageView;
} }
angle::Result TextureVk::getLayerLevelDrawImageView(vk::Context *context, angle::Result TextureVk::getLayerLevelDrawImageView(vk::Context *context,
...@@ -1481,33 +1524,24 @@ angle::Result TextureVk::initImage(ContextVk *contextVk, ...@@ -1481,33 +1524,24 @@ angle::Result TextureVk::initImage(ContextVk *contextVk,
return angle::Result::Continue; return angle::Result::Continue;
} }
angle::Result TextureVk::initImageViews(ContextVk *contextVk, angle::Result TextureVk::initImageViewImpl(ContextVk *contextVk,
const vk::Format &format, const vk::Format &format,
uint32_t levelCount, uint32_t levelCount,
uint32_t layerCount) uint32_t layerCount,
TextureVkViews *view,
VkImageAspectFlags aspectFlags,
gl::SwizzleState mappedSwizzle)
{ {
ASSERT(mImage != nullptr);
gl::SwizzleState mappedSwizzle;
MapSwizzleState(contextVk, format, mState.getSwizzleState(), &mappedSwizzle);
// TODO: Support non-zero base level for ES 3.0 by passing it to getNativeImageLevel. // TODO: Support non-zero base level for ES 3.0 by passing it to getNativeImageLevel.
// http://anglebug.com/3148 // http://anglebug.com/3148
uint32_t baseLevel = getNativeImageLevel(0); uint32_t baseLevel = getNativeImageLevel(0);
uint32_t baseLayer = getNativeImageLayer(0); uint32_t baseLayer = getNativeImageLayer(0);
VkImageAspectFlags aspectFlags = vk::GetFormatAspectFlags(format.angleFormat());
// If we are reading a depth buffer, select only the depth component/aspect
if (aspectFlags & VK_IMAGE_ASPECT_DEPTH_BIT)
{
aspectFlags = VK_IMAGE_ASPECT_DEPTH_BIT;
}
ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags, mappedSwizzle, ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags, mappedSwizzle,
&mReadMipmapImageView, baseLevel, levelCount, baseLayer, &view->mReadMipmapImageView, baseLevel, levelCount,
layerCount)); baseLayer, layerCount));
ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags, mappedSwizzle, ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags, mappedSwizzle,
&mReadBaseLevelImageView, baseLevel, 1, baseLayer, &view->mReadBaseLevelImageView, baseLevel, 1, baseLayer,
layerCount)); layerCount));
if (mState.getType() == gl::TextureType::CubeMap || if (mState.getType() == gl::TextureType::CubeMap ||
mState.getType() == gl::TextureType::_2DArray || mState.getType() == gl::TextureType::_2DArray ||
...@@ -1516,22 +1550,45 @@ angle::Result TextureVk::initImageViews(ContextVk *contextVk, ...@@ -1516,22 +1550,45 @@ angle::Result TextureVk::initImageViews(ContextVk *contextVk,
gl::TextureType arrayType = vk::Get2DTextureType(layerCount, mImage->getSamples()); gl::TextureType arrayType = vk::Get2DTextureType(layerCount, mImage->getSamples());
ANGLE_TRY(mImage->initLayerImageView(contextVk, arrayType, aspectFlags, mappedSwizzle, ANGLE_TRY(mImage->initLayerImageView(contextVk, arrayType, aspectFlags, mappedSwizzle,
&mFetchMipmapImageView, baseLevel, levelCount, &view->mFetchMipmapImageView, baseLevel, levelCount,
baseLayer, layerCount)); baseLayer, layerCount));
ANGLE_TRY(mImage->initLayerImageView(contextVk, arrayType, aspectFlags, mappedSwizzle, ANGLE_TRY(mImage->initLayerImageView(contextVk, arrayType, aspectFlags, mappedSwizzle,
&mFetchBaseLevelImageView, baseLevel, 1, baseLayer, &view->mFetchBaseLevelImageView, baseLevel, 1,
layerCount)); baseLayer, layerCount));
} }
if (!format.imageFormat().isBlock) if (!format.imageFormat().isBlock)
{ {
ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags, ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags,
gl::SwizzleState(), &mDrawBaseLevelImageView, gl::SwizzleState(), &view->mDrawBaseLevelImageView,
baseLevel, 1, baseLayer, layerCount)); baseLevel, 1, baseLayer, layerCount));
} }
return angle::Result::Continue; return angle::Result::Continue;
} }
angle::Result TextureVk::initImageViews(ContextVk *contextVk,
const vk::Format &format,
uint32_t levelCount,
uint32_t layerCount)
{
ASSERT(mImage != nullptr);
gl::SwizzleState mappedSwizzle;
MapSwizzleState(contextVk, format, mState.getSwizzleState(), &mappedSwizzle);
VkImageAspectFlags aspectFlags = vk::GetFormatAspectFlags(format.angleFormat());
if (HasBothDepthAndStencilAspects(aspectFlags))
{
ANGLE_TRY(initImageViewImpl(contextVk, format, levelCount, layerCount, &mStencilViews,
VK_IMAGE_ASPECT_STENCIL_BIT, mappedSwizzle));
aspectFlags = VK_IMAGE_ASPECT_DEPTH_BIT;
}
ANGLE_TRY(initImageViewImpl(contextVk, format, levelCount, layerCount, &mDefaultViews,
aspectFlags, mappedSwizzle));
return angle::Result::Continue;
}
void TextureVk::releaseImage(ContextVk *contextVk) void TextureVk::releaseImage(ContextVk *contextVk)
{ {
if (mImage) if (mImage)
...@@ -1558,11 +1615,9 @@ void TextureVk::releaseImageViews(ContextVk *contextVk) ...@@ -1558,11 +1615,9 @@ void TextureVk::releaseImageViews(ContextVk *contextVk)
{ {
Serial currentSerial = contextVk->getCurrentQueueSerial(); Serial currentSerial = contextVk->getCurrentQueueSerial();
contextVk->releaseObject(currentSerial, &mDrawBaseLevelImageView); mDefaultViews.release(contextVk, currentSerial);
contextVk->releaseObject(currentSerial, &mReadBaseLevelImageView);
contextVk->releaseObject(currentSerial, &mReadMipmapImageView); mStencilViews.release(contextVk, currentSerial);
contextVk->releaseObject(currentSerial, &mFetchBaseLevelImageView);
contextVk->releaseObject(currentSerial, &mFetchMipmapImageView);
for (auto &layerViews : mLayerLevelDrawImageViews) for (auto &layerViews : mLayerLevelDrawImageViews)
{ {
......
...@@ -173,6 +173,19 @@ class TextureVk : public TextureImpl ...@@ -173,6 +173,19 @@ class TextureVk : public TextureImpl
} }
private: private:
struct TextureVkViews final : angle::NonCopyable
{
TextureVkViews();
~TextureVkViews();
void release(ContextVk *contextVk, Serial currentSerial);
vk::ImageView mDrawBaseLevelImageView;
vk::ImageView mReadBaseLevelImageView;
vk::ImageView mReadMipmapImageView;
vk::ImageView mFetchBaseLevelImageView;
vk::ImageView mFetchMipmapImageView;
};
// Transform an image index from the frontend into one that can be used on the backing // Transform an image index from the frontend into one that can be used on the backing
// ImageHelper, taking into account mipmap or cube face offsets // ImageHelper, taking into account mipmap or cube face offsets
gl::ImageIndex getNativeImageIndex(const gl::ImageIndex &inputImageIndex) const; gl::ImageIndex getNativeImageIndex(const gl::ImageIndex &inputImageIndex) const;
...@@ -283,6 +296,13 @@ class TextureVk : public TextureImpl ...@@ -283,6 +296,13 @@ class TextureVk : public TextureImpl
uint32_t levelCount, uint32_t levelCount,
uint32_t layerCount); uint32_t layerCount);
angle::Result init3DRenderTargets(ContextVk *contextVk); angle::Result init3DRenderTargets(ContextVk *contextVk);
angle::Result initImageViewImpl(ContextVk *contextVk,
const vk::Format &format,
uint32_t levelCount,
uint32_t layerCount,
TextureVkViews *views,
VkImageAspectFlags aspectFlags,
gl::SwizzleState mappedSwizzle);
angle::Result initCubeMapRenderTargets(ContextVk *contextVk); angle::Result initCubeMapRenderTargets(ContextVk *contextVk);
angle::Result ensureImageInitializedImpl(ContextVk *contextVk, angle::Result ensureImageInitializedImpl(ContextVk *contextVk,
...@@ -292,6 +312,8 @@ class TextureVk : public TextureImpl ...@@ -292,6 +312,8 @@ class TextureVk : public TextureImpl
void onStagingBufferChange() { onStateChange(angle::SubjectMessage::SubjectChanged); } void onStagingBufferChange() { onStateChange(angle::SubjectMessage::SubjectChanged); }
const TextureVkViews *getTextureViews() const;
bool mOwnsImage; bool mOwnsImage;
gl::TextureType mImageNativeType; gl::TextureType mImageNativeType;
...@@ -306,11 +328,8 @@ class TextureVk : public TextureImpl ...@@ -306,11 +328,8 @@ class TextureVk : public TextureImpl
vk::ImageHelper *mImage; vk::ImageHelper *mImage;
vk::ImageView mDrawBaseLevelImageView; TextureVkViews mDefaultViews;
vk::ImageView mReadBaseLevelImageView; TextureVkViews mStencilViews;
vk::ImageView mReadMipmapImageView;
vk::ImageView mFetchBaseLevelImageView;
vk::ImageView mFetchMipmapImageView;
std::vector<std::vector<vk::ImageView>> mLayerLevelDrawImageViews; std::vector<std::vector<vk::ImageView>> mLayerLevelDrawImageViews;
vk::Sampler mSampler; vk::Sampler mSampler;
......
...@@ -695,8 +695,10 @@ ...@@ -695,8 +695,10 @@
// Transform feedback: // Transform feedback:
3205 VULKAN : dEQP-GLES31.functional.debug.*transform_feedback = SKIP 3205 VULKAN : dEQP-GLES31.functional.debug.*transform_feedback = SKIP
// Stencil textures (some missing support for 3D and 2D array textures): // Stencil textures (some missing support for base level):
3585 VULKAN : dEQP-GLES31.functional.stencil_texturing.* = SKIP 3683 VULKAN PIXEL2 : dEQP-GLES31.functional.stencil_texturing.format.* = FAIL
3683 VULKAN PIXEL2 : dEQP-GLES31.functional.stencil_texturing.misc.compare_mode_effect = FAIL
3148 VULKAN : dEQP-GLES31.functional.stencil_texturing.misc.base_level = SKIP
// Multisampled textures: // Multisampled textures:
3565 VULKAN : dEQP-GLES31.functional.texture.multisample.* = SKIP 3565 VULKAN : dEQP-GLES31.functional.texture.multisample.* = SKIP
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment