Commit 6b60dfd8 by Cody Northrop Committed by Commit Bot

Vulkan: Remove image views forced to one mip level

textureSize requires the view to reflect actual mip levels, so we can't artificially limit the view based on filtering mode. This CL removes those views. That unearthed a problem where the VK backend wasn't properly implementing non-mipmapped filter modes. There is a blurb in the Vulkan spec about this: There are no Vulkan filter modes that directly correspond to OpenGL minification filters of GL_LINEAR or GL_NEAREST, but they can be emulated using VK_SAMPLER_MIPMAP_MODE_NEAREST, minLod = 0, and maxLod = 0.25, and using minFilter = VK_FILTER_LINEAR or minFilter = VK_FILTER_NEAREST, respectively. So this CL also adds that emulation. Bug: angleproject:3948 Test: TextureSizeTextureArrayTest.BaseLevelVariesInTextureArray Test: dEQP-GLES3.functional.shaders.texture_functions.texturesize.* Change-Id: I81d5c3417e7d9abd0cdd058b935963706024a28f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1835937Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Commit-Queue: Cody Northrop <cnorthrop@google.com>
parent 74f28333
...@@ -69,6 +69,15 @@ angle::Result SamplerVk::syncState(const gl::Context *context, const bool dirty) ...@@ -69,6 +69,15 @@ angle::Result SamplerVk::syncState(const gl::Context *context, const bool dirty)
samplerInfo.borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK; samplerInfo.borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
samplerInfo.unnormalizedCoordinates = VK_FALSE; samplerInfo.unnormalizedCoordinates = VK_FALSE;
if (!gl::IsMipmapFiltered(mState))
{
// Per the Vulkan spec, GL_NEAREST and GL_LINEAR do not map directly to Vulkan, so
// they must be emulated (See "Mapping of OpenGL to Vulkan filter modes")
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
samplerInfo.minLod = 0.0f;
samplerInfo.maxLod = 0.25f;
}
ANGLE_VK_TRY(contextVk, mSampler.init(contextVk->getDevice(), samplerInfo)); ANGLE_VK_TRY(contextVk, mSampler.init(contextVk->getDevice(), samplerInfo));
// Regenerate the serial on a sampler change. // Regenerate the serial on a sampler change.
mSerial = contextVk->generateTextureSerial(); mSerial = contextVk->generateTextureSerial();
......
...@@ -112,11 +112,9 @@ TextureVk::TextureVkViews::~TextureVkViews() {} ...@@ -112,11 +112,9 @@ TextureVk::TextureVkViews::~TextureVkViews() {}
void TextureVk::TextureVkViews::release(ContextVk *contextVk) void TextureVk::TextureVkViews::release(ContextVk *contextVk)
{ {
contextVk->addGarbage(&mDrawBaseLevelImageView); contextVk->addGarbage(&mDrawImageView);
contextVk->addGarbage(&mReadBaseLevelImageView); contextVk->addGarbage(&mReadImageView);
contextVk->addGarbage(&mReadMipmapImageView); contextVk->addGarbage(&mFetchImageView);
contextVk->addGarbage(&mFetchBaseLevelImageView);
contextVk->addGarbage(&mFetchMipmapImageView);
} }
angle::Result TextureVk::generateMipmapLevelsWithCPU(ContextVk *contextVk, angle::Result TextureVk::generateMipmapLevelsWithCPU(ContextVk *contextVk,
...@@ -955,9 +953,8 @@ void TextureVk::setImageHelper(ContextVk *contextVk, ...@@ -955,9 +953,8 @@ void TextureVk::setImageHelper(ContextVk *contextVk,
mImage->initStagingBuffer(contextVk->getRenderer(), format, vk::kStagingBufferFlags, mImage->initStagingBuffer(contextVk->getRenderer(), format, vk::kStagingBufferFlags,
mStagingBufferInitialSize); mStagingBufferInitialSize);
mRenderTarget.init(mImage, &mDefaultViews.mDrawBaseLevelImageView, mRenderTarget.init(mImage, &mDefaultViews.mDrawImageView, &mDefaultViews.mFetchImageView,
&mDefaultViews.mFetchBaseLevelImageView, getNativeImageLevel(0), getNativeImageLevel(0), getNativeImageLayer(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
mLayerRenderTargets.clear(); mLayerRenderTargets.clear();
...@@ -1487,6 +1484,15 @@ angle::Result TextureVk::syncState(const gl::Context *context, ...@@ -1487,6 +1484,15 @@ angle::Result TextureVk::syncState(const gl::Context *context,
samplerInfo.borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK; samplerInfo.borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
samplerInfo.unnormalizedCoordinates = VK_FALSE; samplerInfo.unnormalizedCoordinates = VK_FALSE;
if (!gl::IsMipmapFiltered(samplerState))
{
// Per the Vulkan spec, GL_NEAREST and GL_LINEAR do not map directly to Vulkan, so
// they must be emulated (See "Mapping of OpenGL to Vulkan filter modes")
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
samplerInfo.minLod = 0.0f;
samplerInfo.maxLod = 0.25f;
}
ANGLE_VK_TRY(contextVk, mSampler.init(contextVk->getDevice(), samplerInfo)); ANGLE_VK_TRY(contextVk, mSampler.init(contextVk->getDevice(), samplerInfo));
// Regenerate the serial on a sampler change. // Regenerate the serial on a sampler change.
...@@ -1543,18 +1549,13 @@ const vk::ImageView &TextureVk::getReadImageView() const ...@@ -1543,18 +1549,13 @@ const vk::ImageView &TextureVk::getReadImageView() const
ASSERT(mImage->valid()); ASSERT(mImage->valid());
const TextureVkViews *activeView = getTextureViews(); const TextureVkViews *activeView = getTextureViews();
if (!gl::IsMipmapFiltered(mState.getSamplerState())) return activeView->mReadImageView;
{
return activeView->mReadBaseLevelImageView;
}
return activeView->mReadMipmapImageView;
} }
const vk::ImageView &TextureVk::getFetchImageView() const const vk::ImageView &TextureVk::getFetchImageView() const
{ {
if (!mDefaultViews.mFetchBaseLevelImageView.valid()) if (!mDefaultViews.mFetchImageView.valid())
{ {
return getReadImageView(); return getReadImageView();
} }
...@@ -1562,12 +1563,7 @@ const vk::ImageView &TextureVk::getFetchImageView() const ...@@ -1562,12 +1563,7 @@ const vk::ImageView &TextureVk::getFetchImageView() const
ASSERT(mImage->valid()); ASSERT(mImage->valid());
const TextureVkViews *activeView = getTextureViews(); const TextureVkViews *activeView = getTextureViews();
if (!gl::IsMipmapFiltered(mState.getSamplerState())) return activeView->mFetchImageView;
{
return activeView->mFetchBaseLevelImageView;
}
return activeView->mFetchMipmapImageView;
} }
vk::ImageView *TextureVk::getLayerLevelImageViewImpl(vk::LayerLevelImageViewVector *imageViews, vk::ImageView *TextureVk::getLayerLevelImageViewImpl(vk::LayerLevelImageViewVector *imageViews,
...@@ -1752,10 +1748,7 @@ angle::Result TextureVk::initImageViewImpl(ContextVk *contextVk, ...@@ -1752,10 +1748,7 @@ angle::Result TextureVk::initImageViewImpl(ContextVk *contextVk,
uint32_t baseLayer = getNativeImageLayer(0); uint32_t baseLayer = getNativeImageLayer(0);
ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags, mappedSwizzle, ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags, mappedSwizzle,
&view->mReadMipmapImageView, baseLevel, levelCount, &view->mReadImageView, baseLevel, levelCount, baseLayer,
baseLayer, layerCount));
ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags, mappedSwizzle,
&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 ||
...@@ -1764,17 +1757,14 @@ angle::Result TextureVk::initImageViewImpl(ContextVk *contextVk, ...@@ -1764,17 +1757,14 @@ angle::Result TextureVk::initImageViewImpl(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,
&view->mFetchMipmapImageView, baseLevel, levelCount, &view->mFetchImageView, baseLevel, levelCount,
baseLayer, layerCount));
ANGLE_TRY(mImage->initLayerImageView(contextVk, arrayType, aspectFlags, mappedSwizzle,
&view->mFetchBaseLevelImageView, baseLevel, 1,
baseLayer, 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(), &view->mDrawBaseLevelImageView, gl::SwizzleState(), &view->mDrawImageView, baseLevel,
baseLevel, 1, baseLayer, layerCount)); 1, baseLayer, layerCount));
} }
return angle::Result::Continue; return angle::Result::Continue;
......
...@@ -186,11 +186,9 @@ class TextureVk : public TextureImpl ...@@ -186,11 +186,9 @@ class TextureVk : public TextureImpl
void release(ContextVk *contextVk); void release(ContextVk *contextVk);
vk::ImageView mDrawBaseLevelImageView; vk::ImageView mDrawImageView;
vk::ImageView mReadBaseLevelImageView; vk::ImageView mReadImageView;
vk::ImageView mReadMipmapImageView; vk::ImageView mFetchImageView;
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
......
...@@ -694,10 +694,10 @@ VkSamplerMipmapMode GetSamplerMipmapMode(const GLenum filter) ...@@ -694,10 +694,10 @@ VkSamplerMipmapMode GetSamplerMipmapMode(const GLenum filter)
{ {
switch (filter) switch (filter)
{ {
case GL_LINEAR:
case GL_LINEAR_MIPMAP_LINEAR: case GL_LINEAR_MIPMAP_LINEAR:
case GL_NEAREST_MIPMAP_LINEAR: case GL_NEAREST_MIPMAP_LINEAR:
return VK_SAMPLER_MIPMAP_MODE_LINEAR; return VK_SAMPLER_MIPMAP_MODE_LINEAR;
case GL_LINEAR:
case GL_NEAREST: case GL_NEAREST:
case GL_NEAREST_MIPMAP_NEAREST: case GL_NEAREST_MIPMAP_NEAREST:
case GL_LINEAR_MIPMAP_NEAREST: case GL_LINEAR_MIPMAP_NEAREST:
......
...@@ -5699,7 +5699,7 @@ ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ...@@ -5699,7 +5699,7 @@ ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3,
ES3_OPENGL(), ES3_OPENGL(),
ES3_OPENGLES(), ES3_OPENGLES(),
ES3_VULKAN()); ES3_VULKAN());
ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL()); ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL(), ES3_VULKAN());
ANGLE_INSTANTIATE_TEST(SamplerInStructTest, ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
ES2_D3D11(), ES2_D3D11(),
ES2_D3D9(), ES2_D3D9(),
......
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