Commit ea71c6b6 by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Emulate R32F images with R32UI

GL requires that imageAtomicExchange be supported for r32f formats. However VK_FORMAT_FEATURE_STORAGE_*_ATOMIC_BIT is nearly unsupported everywhere without some Vulkan extension that brings in unnecessary support. This GL feature is emulated by transforming the shader to use r32ui for all images that originally specified r32f. floatToUintBits and uintBitsToFloat is used to maintain correct usage of the image* builtin functions. Bug: angleproject:5535 Change-Id: Ie607089935d3283b3ffa054f4b4385b81fb8f53d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2635453 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent a4d05638
...@@ -459,6 +459,14 @@ struct FeaturesVk : FeatureSetBase ...@@ -459,6 +459,14 @@ struct FeaturesVk : FeatureSetBase
"exposeNonConformantExtensionsAndVersions", FeatureCategory::VulkanWorkarounds, "exposeNonConformantExtensionsAndVersions", FeatureCategory::VulkanWorkarounds,
"Expose GLES versions and extensions that are not conformant.", &members, "Expose GLES versions and extensions that are not conformant.", &members,
"http://anglebug.com/5375"}; "http://anglebug.com/5375"};
// imageAtomicExchange is expected to work for r32f formats, but support for atomic operations
// for VK_FORMAT_R32_SFLOAT is rare. This support is emulated by using an r32ui format for such
// images instead.
Feature emulateR32fImageAtomicExchange = {
"emulateR32fImageAtomicExchange", FeatureCategory::VulkanWorkarounds,
"Emulate r32f images with r32ui to support imageAtomicExchange.", &members,
"http://anglebug.com/5535"};
}; };
inline FeaturesVk::FeaturesVk() = default; inline FeaturesVk::FeaturesVk() = default;
......
...@@ -333,6 +333,8 @@ angle_translator_lib_vulkan_sources = [ ...@@ -333,6 +333,8 @@ angle_translator_lib_vulkan_sources = [
"src/compiler/translator/tree_ops/vulkan/RewriteDfdy.h", "src/compiler/translator/tree_ops/vulkan/RewriteDfdy.h",
"src/compiler/translator/tree_ops/vulkan/RewriteInterpolateAtOffset.cpp", "src/compiler/translator/tree_ops/vulkan/RewriteInterpolateAtOffset.cpp",
"src/compiler/translator/tree_ops/vulkan/RewriteInterpolateAtOffset.h", "src/compiler/translator/tree_ops/vulkan/RewriteInterpolateAtOffset.h",
"src/compiler/translator/tree_ops/vulkan/RewriteR32fImages.cpp",
"src/compiler/translator/tree_ops/vulkan/RewriteR32fImages.h",
"src/compiler/translator/tree_ops/vulkan/RewriteStructSamplers.cpp", "src/compiler/translator/tree_ops/vulkan/RewriteStructSamplers.cpp",
"src/compiler/translator/tree_ops/vulkan/RewriteStructSamplers.h", "src/compiler/translator/tree_ops/vulkan/RewriteStructSamplers.h",
] ]
......
...@@ -25,6 +25,7 @@ constexpr const ImmutableString kMainName("main"); ...@@ -25,6 +25,7 @@ constexpr const ImmutableString kMainName("main");
constexpr const ImmutableString kImageLoadName("imageLoad"); constexpr const ImmutableString kImageLoadName("imageLoad");
constexpr const ImmutableString kImageStoreName("imageStore"); constexpr const ImmutableString kImageStoreName("imageStore");
constexpr const ImmutableString kImageSizeName("imageSize"); constexpr const ImmutableString kImageSizeName("imageSize");
constexpr const ImmutableString kImageAtomicExchangeName("imageAtomicExchange");
constexpr const ImmutableString kAtomicCounterName("atomicCounter"); constexpr const ImmutableString kAtomicCounterName("atomicCounter");
static const char kFunctionMangledNameSeparator = '('; static const char kFunctionMangledNameSeparator = '(';
...@@ -214,7 +215,8 @@ bool TFunction::isMain() const ...@@ -214,7 +215,8 @@ bool TFunction::isMain() const
bool TFunction::isImageFunction() const bool TFunction::isImageFunction() const
{ {
return symbolType() == SymbolType::BuiltIn && return symbolType() == SymbolType::BuiltIn &&
(name() == kImageSizeName || name() == kImageLoadName || name() == kImageStoreName); (name() == kImageSizeName || name() == kImageLoadName || name() == kImageStoreName ||
name() == kImageAtomicExchangeName);
} }
bool TFunction::isAtomicCounterFunction() const bool TFunction::isAtomicCounterFunction() const
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "compiler/translator/tree_ops/vulkan/RewriteCubeMapSamplersAs2DArray.h" #include "compiler/translator/tree_ops/vulkan/RewriteCubeMapSamplersAs2DArray.h"
#include "compiler/translator/tree_ops/vulkan/RewriteDfdy.h" #include "compiler/translator/tree_ops/vulkan/RewriteDfdy.h"
#include "compiler/translator/tree_ops/vulkan/RewriteInterpolateAtOffset.h" #include "compiler/translator/tree_ops/vulkan/RewriteInterpolateAtOffset.h"
#include "compiler/translator/tree_ops/vulkan/RewriteR32fImages.h"
#include "compiler/translator/tree_ops/vulkan/RewriteStructSamplers.h" #include "compiler/translator/tree_ops/vulkan/RewriteStructSamplers.h"
#include "compiler/translator/tree_util/BuiltIn.h" #include "compiler/translator/tree_util/BuiltIn.h"
#include "compiler/translator/tree_util/DriverUniform.h" #include "compiler/translator/tree_util/DriverUniform.h"
...@@ -731,6 +732,7 @@ bool TranslatorVulkan::translateImpl(TIntermBlock *root, ...@@ -731,6 +732,7 @@ bool TranslatorVulkan::translateImpl(TIntermBlock *root,
// Write out default uniforms into a uniform block assigned to a specific set/binding. // Write out default uniforms into a uniform block assigned to a specific set/binding.
int defaultUniformCount = 0; int defaultUniformCount = 0;
int aggregateTypesUsedForUniforms = 0; int aggregateTypesUsedForUniforms = 0;
int r32fImageCount = 0;
int atomicCounterCount = 0; int atomicCounterCount = 0;
for (const auto &uniform : getUniforms()) for (const auto &uniform : getUniforms())
{ {
...@@ -744,6 +746,11 @@ bool TranslatorVulkan::translateImpl(TIntermBlock *root, ...@@ -744,6 +746,11 @@ bool TranslatorVulkan::translateImpl(TIntermBlock *root,
++aggregateTypesUsedForUniforms; ++aggregateTypesUsedForUniforms;
} }
if (uniform.active && gl::IsImageType(uniform.type) && uniform.imageUnitFormat == GL_R32F)
{
++r32fImageCount;
}
if (uniform.active && gl::IsAtomicCounterType(uniform.type)) if (uniform.active && gl::IsAtomicCounterType(uniform.type))
{ {
++atomicCounterCount; ++atomicCounterCount;
...@@ -853,6 +860,14 @@ bool TranslatorVulkan::translateImpl(TIntermBlock *root, ...@@ -853,6 +860,14 @@ bool TranslatorVulkan::translateImpl(TIntermBlock *root,
driverUniforms->addGraphicsDriverUniformsToShader(root, &getSymbolTable()); driverUniforms->addGraphicsDriverUniformsToShader(root, &getSymbolTable());
} }
if (r32fImageCount > 0)
{
if (!RewriteR32fImages(this, root, &getSymbolTable()))
{
return false;
}
}
if (atomicCounterCount > 0) if (atomicCounterCount > 0)
{ {
// ANGLEUniforms.acbBufferOffsets // ANGLEUniforms.acbBufferOffsets
......
...@@ -317,6 +317,7 @@ class MonomorphizeTraverser final : public TIntermTraverser ...@@ -317,6 +317,7 @@ class MonomorphizeTraverser final : public TIntermTraverser
// subscripted (i.e. the function itself expects an array), or // subscripted (i.e. the function itself expects an array), or
// - The opaque uniform is an atomic counter // - The opaque uniform is an atomic counter
// - The opaque uniform is a samplerCube and ES2's cube sampling emulation is requested. // - The opaque uniform is a samplerCube and ES2's cube sampling emulation is requested.
// - The opaque uniform is an image* with r32f format.
// //
const TType &type = uniform->getType(); const TType &type = uniform->getType();
const bool isArrayOfArrayOfSamplerOrImage = const bool isArrayOfArrayOfSamplerOrImage =
...@@ -326,11 +327,13 @@ class MonomorphizeTraverser final : public TIntermTraverser ...@@ -326,11 +327,13 @@ class MonomorphizeTraverser final : public TIntermTraverser
const bool isSamplerCubeEmulation = const bool isSamplerCubeEmulation =
type.isSamplerCube() && type.isSamplerCube() &&
(mCompileOptions & SH_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING) != 0; (mCompileOptions & SH_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING) != 0;
const bool isR32fImage =
type.isImage() && type.getLayoutQualifier().imageInternalFormat == EiifR32F;
if (!(isStructContainingSamplers || if (!(isStructContainingSamplers ||
(isSamplerInStruct && isParameterArrayOfOpaqueType) || (isSamplerInStruct && isParameterArrayOfOpaqueType) ||
(isArrayOfArrayOfSamplerOrImage && isParameterArrayOfOpaqueType) || (isArrayOfArrayOfSamplerOrImage && isParameterArrayOfOpaqueType) ||
isAtomicCounter || isSamplerCubeEmulation)) isAtomicCounter || isSamplerCubeEmulation || isR32fImage))
{ {
continue; continue;
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
// - Partially subscripted array of array of images // - Partially subscripted array of array of images
// - Atomic counters // - Atomic counters
// - samplerCube variables when emulating ES2's cube map sampling // - samplerCube variables when emulating ES2's cube map sampling
// - image* variables with r32f formats (to emulate imageAtomicExchange)
// //
// This transformation basically duplicates such functions, removes the // This transformation basically duplicates such functions, removes the
// sampler/image/atomic_counter parameters and uses the opaque uniforms used by the caller. // sampler/image/atomic_counter parameters and uses the opaque uniforms used by the caller.
......
...@@ -63,12 +63,6 @@ class RewriteExpressionTraverser final : public TIntermTraverser ...@@ -63,12 +63,6 @@ class RewriteExpressionTraverser final : public TIntermTraverser
bool visitBinary(Visit visit, TIntermBinary *node) override bool visitBinary(Visit visit, TIntermBinary *node) override
{ {
// Only interested in opaque uniforms.
if (!IsOpaqueType(node->getType().getBasicType()))
{
return true;
}
TIntermTyped *rewritten = TIntermTyped *rewritten =
RewriteArrayOfArraySubscriptExpression(mCompiler, node, mUniformMap); RewriteArrayOfArraySubscriptExpression(mCompiler, node, mUniformMap);
if (rewritten == nullptr) if (rewritten == nullptr)
...@@ -130,7 +124,11 @@ TIntermTyped *RewriteArrayOfArraySubscriptExpression(TCompiler *compiler, ...@@ -130,7 +124,11 @@ TIntermTyped *RewriteArrayOfArraySubscriptExpression(TCompiler *compiler,
TIntermBinary *node, TIntermBinary *node,
const UniformMap &uniformMap) const UniformMap &uniformMap)
{ {
ASSERT(IsOpaqueType(node->getType().getBasicType())); // Only interested in opaque uniforms.
if (!IsOpaqueType(node->getType().getBasicType()))
{
return nullptr;
}
TIntermSymbol *opaqueUniform = nullptr; TIntermSymbol *opaqueUniform = nullptr;
...@@ -315,12 +313,6 @@ class RewriteArrayOfArrayOfOpaqueUniformsTraverser : public TIntermTraverser ...@@ -315,12 +313,6 @@ class RewriteArrayOfArrayOfOpaqueUniformsTraverser : public TIntermTraverser
// Same implementation as in RewriteExpressionTraverser. That traverser cannot replace root. // Same implementation as in RewriteExpressionTraverser. That traverser cannot replace root.
bool visitBinary(Visit visit, TIntermBinary *node) override bool visitBinary(Visit visit, TIntermBinary *node) override
{ {
// Only interested in opaque uniforms.
if (!IsOpaqueType(node->getType().getBasicType()))
{
return true;
}
TIntermTyped *rewritten = TIntermTyped *rewritten =
RewriteArrayOfArraySubscriptExpression(mCompiler, node, mUniformMap); RewriteArrayOfArraySubscriptExpression(mCompiler, node, mUniformMap);
if (rewritten == nullptr) if (rewritten == nullptr)
......
...@@ -225,14 +225,14 @@ class RewriteAtomicCountersTraverser : public TIntermTraverser ...@@ -225,14 +225,14 @@ class RewriteAtomicCountersTraverser : public TIntermTraverser
void visitSymbol(TIntermSymbol *symbol) override void visitSymbol(TIntermSymbol *symbol) override
{ {
// Connot encounter the atomic counter symbol directly. It can only be used with functions, // Cannot encounter the atomic counter symbol directly. It can only be used with functions,
// and therefore it's handled by visitAggregate. // and therefore it's handled by visitAggregate.
ASSERT(!symbol->getType().isAtomicCounter()); ASSERT(!symbol->getType().isAtomicCounter());
} }
bool visitBinary(Visit visit, TIntermBinary *node) override bool visitBinary(Visit visit, TIntermBinary *node) override
{ {
// Connot encounter an atomic counter expression directly. It can only be used with // Cannot encounter an atomic counter expression directly. It can only be used with
// functions, and therefore it's handled by visitAggregate. // functions, and therefore it's handled by visitAggregate.
ASSERT(!node->getType().isAtomicCounter()); ASSERT(!node->getType().isAtomicCounter());
return true; return true;
......
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// RewriteR32fImages: Change images qualified with r32f to use r32ui instead. The only supported
// operation on these images is imageAtomicExchange(), which works identically with r32ui. This
// avoids requiring atomic operations support for the R32_FLOAT format in Vulkan.
#ifndef COMPILER_TRANSLATOR_TREEOPS_VULKAN_REWRITER32FIMAGES_H_
#define COMPILER_TRANSLATOR_TREEOPS_VULKAN_REWRITER32FIMAGES_H_
#include "common/angleutils.h"
namespace sh
{
class TCompiler;
class TIntermBlock;
class TSymbolTable;
ANGLE_NO_DISCARD bool RewriteR32fImages(TCompiler *compiler,
TIntermBlock *root,
TSymbolTable *symbolTable);
} // namespace sh
#endif // COMPILER_TRANSLATOR_TREEOPS_VULKAN_REWRITER32FIMAGES_H_
...@@ -1276,7 +1276,7 @@ angle::Result ProgramExecutableVk::updateImagesDescriptorSet( ...@@ -1276,7 +1276,7 @@ angle::Result ProgramExecutableVk::updateImagesDescriptorSet(
TextureVk *textureVk = activeImages[imageUnit]; TextureVk *textureVk = activeImages[imageUnit];
const vk::BufferView *view = nullptr; const vk::BufferView *view = nullptr;
ANGLE_TRY(textureVk->getBufferViewAndRecordUse(contextVk, format, &view)); ANGLE_TRY(textureVk->getBufferViewAndRecordUse(contextVk, format, true, &view));
const ShaderInterfaceVariableInfo &info = const ShaderInterfaceVariableInfo &info =
mVariableInfoMap.get(shaderType, mappedImageName); mVariableInfoMap.get(shaderType, mappedImageName);
...@@ -1510,7 +1510,8 @@ angle::Result ProgramExecutableVk::updateTexturesDescriptorSet(ContextVk *contex ...@@ -1510,7 +1510,8 @@ angle::Result ProgramExecutableVk::updateTexturesDescriptorSet(ContextVk *contex
GLuint textureUnit = samplerBinding.boundTextureUnits[arrayElement]; GLuint textureUnit = samplerBinding.boundTextureUnits[arrayElement];
TextureVk *textureVk = activeTextures[textureUnit].texture; TextureVk *textureVk = activeTextures[textureUnit].texture;
const vk::BufferView *view = nullptr; const vk::BufferView *view = nullptr;
ANGLE_TRY(textureVk->getBufferViewAndRecordUse(contextVk, nullptr, &view)); ANGLE_TRY(
textureVk->getBufferViewAndRecordUse(contextVk, nullptr, false, &view));
const std::string samplerName = const std::string samplerName =
GlslangGetMappedSamplerName(samplerUniform.name); GlslangGetMappedSamplerName(samplerUniform.name);
......
...@@ -2052,6 +2052,10 @@ void RendererVk::initFeatures(DisplayVk *displayVk, ...@@ -2052,6 +2052,10 @@ void RendererVk::initFeatures(DisplayVk *displayVk,
&mFeatures, preferDrawClearOverVkCmdClearAttachments, &mFeatures, preferDrawClearOverVkCmdClearAttachments,
IsPixel2(mPhysicalDeviceProperties.vendorID, mPhysicalDeviceProperties.deviceID)); IsPixel2(mPhysicalDeviceProperties.vendorID, mPhysicalDeviceProperties.deviceID));
// r32f image emulation is done unconditionally so VK_FORMAT_FEATURE_STORAGE_*_ATOMIC_BIT is not
// required.
ANGLE_FEATURE_CONDITION(&mFeatures, emulateR32fImageAtomicExchange, true);
angle::PlatformMethods *platform = ANGLEPlatformCurrent(); angle::PlatformMethods *platform = ANGLEPlatformCurrent();
platform->overrideFeaturesVk(platform, &mFeatures); platform->overrideFeaturesVk(platform, &mFeatures);
......
...@@ -301,6 +301,19 @@ angle::Result CopyAndStageImageSubresource(ContextVk *contextVk, ...@@ -301,6 +301,19 @@ angle::Result CopyAndStageImageSubresource(ContextVk *contextVk,
return angle::Result::Continue; return angle::Result::Continue;
} }
const vk::Format *AdjustStorageViewFormatPerWorkarounds(ContextVk *contextVk,
const vk::Format *intended)
{
// r32f images are emulated with r32ui.
if (contextVk->getFeatures().emulateR32fImageAtomicExchange.enabled &&
intended->actualImageFormatID == angle::FormatID::R32_FLOAT)
{
return &contextVk->getRenderer()->getFormat(angle::FormatID::R32_UINT);
}
return intended;
}
} // anonymous namespace } // anonymous namespace
// TextureVk implementation. // TextureVk implementation.
...@@ -2586,7 +2599,9 @@ angle::Result TextureVk::getStorageImageView(ContextVk *contextVk, ...@@ -2586,7 +2599,9 @@ angle::Result TextureVk::getStorageImageView(ContextVk *contextVk,
const vk::ImageView **imageViewOut) const vk::ImageView **imageViewOut)
{ {
angle::FormatID formatID = angle::Format::InternalFormatToID(binding.format); angle::FormatID formatID = angle::Format::InternalFormatToID(binding.format);
const vk::Format &format = contextVk->getRenderer()->getFormat(formatID); const vk::Format *format = &contextVk->getRenderer()->getFormat(formatID);
format = AdjustStorageViewFormatPerWorkarounds(contextVk, format);
gl::LevelIndex nativeLevelGL = gl::LevelIndex nativeLevelGL =
getNativeImageLevel(gl::LevelIndex(static_cast<uint32_t>(binding.level))); getNativeImageLevel(gl::LevelIndex(static_cast<uint32_t>(binding.level)));
...@@ -2598,7 +2613,7 @@ angle::Result TextureVk::getStorageImageView(ContextVk *contextVk, ...@@ -2598,7 +2613,7 @@ angle::Result TextureVk::getStorageImageView(ContextVk *contextVk,
return getImageViews().getLevelLayerStorageImageView( return getImageViews().getLevelLayerStorageImageView(
contextVk, *mImage, nativeLevelVk, nativeLayer, contextVk, *mImage, nativeLevelVk, nativeLayer,
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, format.actualImageFormatID, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, format->actualImageFormatID,
imageViewOut); imageViewOut);
} }
...@@ -2606,12 +2621,13 @@ angle::Result TextureVk::getStorageImageView(ContextVk *contextVk, ...@@ -2606,12 +2621,13 @@ angle::Result TextureVk::getStorageImageView(ContextVk *contextVk,
return getImageViews().getLevelStorageImageView( return getImageViews().getLevelStorageImageView(
contextVk, mState.getType(), *mImage, nativeLevelVk, nativeLayer, contextVk, mState.getType(), *mImage, nativeLevelVk, nativeLayer,
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, format.actualImageFormatID, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, format->actualImageFormatID,
imageViewOut); imageViewOut);
} }
angle::Result TextureVk::getBufferViewAndRecordUse(ContextVk *contextVk, angle::Result TextureVk::getBufferViewAndRecordUse(ContextVk *contextVk,
const vk::Format *imageUniformFormat, const vk::Format *imageUniformFormat,
bool isImage,
const vk::BufferView **viewOut) const vk::BufferView **viewOut)
{ {
RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
...@@ -2625,6 +2641,11 @@ angle::Result TextureVk::getBufferViewAndRecordUse(ContextVk *contextVk, ...@@ -2625,6 +2641,11 @@ angle::Result TextureVk::getBufferViewAndRecordUse(ContextVk *contextVk,
imageUniformFormat = &renderer->getFormat(baseLevelDesc.format.info->sizedInternalFormat); imageUniformFormat = &renderer->getFormat(baseLevelDesc.format.info->sizedInternalFormat);
} }
if (isImage)
{
imageUniformFormat = AdjustStorageViewFormatPerWorkarounds(contextVk, imageUniformFormat);
}
// Create a view for the required format. // Create a view for the required format.
const vk::BufferHelper &buffer = vk::GetImpl(mState.getBuffer().get())->getBuffer(); const vk::BufferHelper &buffer = vk::GetImpl(mState.getBuffer().get())->getBuffer();
......
...@@ -233,6 +233,7 @@ class TextureVk : public TextureImpl, public angle::ObserverInterface ...@@ -233,6 +233,7 @@ class TextureVk : public TextureImpl, public angle::ObserverInterface
angle::Result getBufferViewAndRecordUse(ContextVk *contextVk, angle::Result getBufferViewAndRecordUse(ContextVk *contextVk,
const vk::Format *imageUniformFormat, const vk::Format *imageUniformFormat,
bool isImage,
const vk::BufferView **viewOut); const vk::BufferView **viewOut);
// Normally, initialize the image with enabled mipmap level counts. // Normally, initialize the image with enabled mipmap level counts.
......
...@@ -32,25 +32,6 @@ namespace vk ...@@ -32,25 +32,6 @@ namespace vk
{ {
namespace namespace
{ {
bool HasShaderImageAtomicsSupport(const RendererVk *rendererVk,
const gl::Extensions &supportedExtensions)
{
// Only VK_FORMAT_R32_SFLOAT doesn't have mandatory support for the STORAGE_IMAGE_ATOMIC and
// STORAGE_TEXEL_BUFFER_ATOMIC features.
const Format &formatVk = rendererVk->getFormat(GL_R32F);
const bool hasImageAtomicSupport = rendererVk->hasImageFormatFeatureBits(
formatVk.actualImageFormatID, VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT);
bool hasBufferAtomicSupport = true;
if (supportedExtensions.textureBufferAny())
{
hasBufferAtomicSupport = rendererVk->hasBufferFormatFeatureBits(
formatVk.actualBufferFormatID, VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT);
}
return hasImageAtomicSupport && hasBufferAtomicSupport;
}
// Checks to see if each format can be reinterpreted to an equivalent format in a different // Checks to see if each format can be reinterpreted to an equivalent format in a different
// colorspace. If all supported formats can be reinterpreted, it returns true. Formats which are not // colorspace. If all supported formats can be reinterpreted, it returns true. Formats which are not
// supported at all are ignored and not counted as failures. // supported at all are ignored and not counted as failures.
...@@ -909,11 +890,9 @@ void RendererVk::ensureCapsInitialized() const ...@@ -909,11 +890,9 @@ void RendererVk::ensureCapsInitialized() const
// GL_OES_shader_image_atomic requires that image atomic functions have support for r32i and // GL_OES_shader_image_atomic requires that image atomic functions have support for r32i and
// r32ui formats. These formats have mandatory support for STORAGE_IMAGE_ATOMIC and // r32ui formats. These formats have mandatory support for STORAGE_IMAGE_ATOMIC and
// STORAGE_TEXEL_BUFFER_ATOMIC features in Vulkan. Additionally, it requires that // STORAGE_TEXEL_BUFFER_ATOMIC features in Vulkan. Additionally, it requires that
// imageAtomicExchange supports r32f. Exposing this extension is thus restricted to this format // imageAtomicExchange supports r32f, which is emulated in ANGLE transforming the shader to
// having support for the aforementioned features. // expect r32ui instead.
mNativeExtensions.shaderImageAtomicOES = mNativeExtensions.shaderImageAtomicOES = true;
vk::HasShaderImageAtomicsSupport(this, mNativeExtensions) ||
getFeatures().exposeNonConformantExtensionsAndVersions.enabled;
// Geometry shaders are required for ES 3.2. // Geometry shaders are required for ES 3.2.
// We don't support GS when we are emulating line raster due to the tricky position varying. // We don't support GS when we are emulating line raster due to the tricky position varying.
......
...@@ -277,9 +277,6 @@ ...@@ -277,9 +277,6 @@
5276 NVIDIA VULKAN : dEQP-GLES31.functional.copy_image.compressed.viewclass_etc* = FAIL 5276 NVIDIA VULKAN : dEQP-GLES31.functional.copy_image.compressed.viewclass_etc* = FAIL
5276 NVIDIA VULKAN : dEQP-GLES31.functional.copy_image.mixed.*eac* = FAIL 5276 NVIDIA VULKAN : dEQP-GLES31.functional.copy_image.mixed.*eac* = FAIL
// imageAtomicExchange failure with r32f format
5353 NVIDIA VULKAN : dEQP-GLES31.functional.image_load_store.*.atomic.exchange_r32f* = FAIL
// Vulkan Android failures with these formats // Vulkan Android failures with these formats
5277 VULKAN ANDROID : dEQP-GLES31.functional.copy_image.non_compressed.viewclass_32_bits.rgba8_snorm_rgb10_a2* = FAIL 5277 VULKAN ANDROID : dEQP-GLES31.functional.copy_image.non_compressed.viewclass_32_bits.rgba8_snorm_rgb10_a2* = FAIL
5277 VULKAN ANDROID : dEQP-GLES31.functional.copy_image.non_compressed.viewclass_32_bits.rgba8_snorm_rgb9_e5* = FAIL 5277 VULKAN ANDROID : dEQP-GLES31.functional.copy_image.non_compressed.viewclass_32_bits.rgba8_snorm_rgb9_e5* = FAIL
......
...@@ -3661,7 +3661,6 @@ TEST_P(GLSLTest_ES31, ArraysOfArraysImage) ...@@ -3661,7 +3661,6 @@ TEST_P(GLSLTest_ES31, ArraysOfArraysImage)
// Test that multiple arrays of arrays of images work as expected. // Test that multiple arrays of arrays of images work as expected.
TEST_P(GLSLTest_ES31, ConsecutiveArraysOfArraysImage) TEST_P(GLSLTest_ES31, ConsecutiveArraysOfArraysImage)
{ {
swapBuffers();
// http://anglebug.com/5072 // http://anglebug.com/5072
ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux() && IsOpenGL()); ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux() && IsOpenGL());
...@@ -3791,6 +3790,174 @@ TEST_P(GLSLTest_ES31, ConsecutiveArraysOfArraysImage) ...@@ -3791,6 +3790,174 @@ TEST_P(GLSLTest_ES31, ConsecutiveArraysOfArraysImage)
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
} }
// Test that arrays of arrays of images of r32f format work when passed to functions.
TEST_P(GLSLTest_ES31, ArraysOfArraysOfR32fImages)
{
// Skip if GL_OES_shader_image_atomic is not enabled.
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_shader_image_atomic"));
// http://anglebug.com/5072
ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux() && IsOpenGL());
// Fails on D3D due to mistranslation.
ANGLE_SKIP_TEST_IF(IsD3D());
// Fails on Android on GLES.
ANGLE_SKIP_TEST_IF(IsAndroid() && IsOpenGLES());
// http://anglebug.com/5353
ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
GLint maxComputeImageUniforms;
glGetIntegerv(GL_MAX_COMPUTE_IMAGE_UNIFORMS, &maxComputeImageUniforms);
ANGLE_SKIP_TEST_IF(maxComputeImageUniforms < 7);
constexpr char kComputeShader[] = R"(#version 310 es
#extension GL_OES_shader_image_atomic : require
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, r32f) uniform highp image2D image1[2][3];
layout(binding = 6, r32f) uniform highp image2D image2;
void testFunction(image2D imageOut[2][3])
{
// image1 is an array of 1x1 images.
// image2 is a 1x4 image with the following data:
//
// (0, 0): 234.5
// (0, 1): 4.0
// (0, 2): 456.0
// (0, 3): 987.0
// Write to [0][0]
imageStore(imageOut[0][0], ivec2(0, 0), vec4(1234.5));
// Write to [0][1]
imageStore(imageOut[0][1], ivec2(0, 0), imageLoad(image2, ivec2(0, 0)));
// Write to [0][2]
imageStore(imageOut[0][2], ivec2(0, 0), vec4(imageSize(image2).y));
// Write to [1][0]
imageStore(imageOut[1][0], ivec2(0,
imageSize(image2).y - int(imageLoad(image2, ivec2(0, 1)).x)
), vec4(678.0));
// Write to [1][1]
imageStore(imageOut[1][1], ivec2(0, 0),
vec4(imageAtomicExchange(image2, ivec2(0, 2), 135.0)));
// Write to [1][2]
imageStore(imageOut[1][2], ivec2(0, 0),
imageLoad(image2, ivec2(imageSize(image2).x - 1, 3)));
}
void main(void)
{
testFunction(image1);
})";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShader);
EXPECT_GL_NO_ERROR();
glUseProgram(program);
constexpr GLsizei kImageRows = 2;
constexpr GLsizei kImageCols = 3;
constexpr GLfloat kImageData = 0;
GLTexture images[kImageRows][kImageCols];
for (size_t row = 0; row < kImageRows; row++)
{
for (size_t col = 0; col < kImageCols; col++)
{
glBindTexture(GL_TEXTURE_2D, images[row][col]);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32F, 1, 1);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RED, GL_FLOAT, &kImageData);
glBindImageTexture(row * kImageCols + col, images[row][col], 0, GL_FALSE, 0,
GL_READ_WRITE, GL_R32F);
EXPECT_GL_NO_ERROR();
}
}
constexpr GLsizei kImage2Size = 4;
constexpr std::array<GLfloat, kImage2Size> kImage2Data = {
234.5f,
4.0f,
456.0f,
987.0f,
};
GLTexture image2;
glBindTexture(GL_TEXTURE_2D, image2);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32F, 1, kImage2Size);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, kImage2Size, GL_RED, GL_FLOAT, kImage2Data.data());
glBindImageTexture(6, image2, 0, GL_FALSE, 0, GL_READ_WRITE, GL_R32F);
EXPECT_GL_NO_ERROR();
glDispatchCompute(1, 1, 1);
EXPECT_GL_NO_ERROR();
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
// Verify the previous dispatch with another dispatch
constexpr char kVerifyShader[] = R"(#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, r32f) uniform highp readonly image2D image1[2][3];
layout(binding = 6, r32f) uniform highp readonly image2D image2;
layout(binding = 0, std430) buffer Output {
float image2Data[4];
float image1Data[6];
} outbuf;
void main(void)
{
for (int i = 0; i < 4; ++i)
{
outbuf.image2Data[i] = imageLoad(image2, ivec2(0, i)).x;
}
outbuf.image1Data[0] = imageLoad(image1[0][0], ivec2(0, 0)).x;
outbuf.image1Data[1] = imageLoad(image1[0][1], ivec2(0, 0)).x;
outbuf.image1Data[2] = imageLoad(image1[0][2], ivec2(0, 0)).x;
outbuf.image1Data[3] = imageLoad(image1[1][0], ivec2(0, 0)).x;
outbuf.image1Data[4] = imageLoad(image1[1][1], ivec2(0, 0)).x;
outbuf.image1Data[5] = imageLoad(image1[1][2], ivec2(0, 0)).x;
})";
ANGLE_GL_COMPUTE_PROGRAM(verifyProgram, kVerifyShader);
EXPECT_GL_NO_ERROR();
glUseProgram(verifyProgram);
constexpr std::array<GLfloat, kImage2Size + kImageRows *kImageCols> kOutputInitData = {};
GLBuffer outputBuffer;
glBindBuffer(GL_SHADER_STORAGE_BUFFER, outputBuffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(kOutputInitData), kOutputInitData.data(),
GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, outputBuffer);
EXPECT_GL_NO_ERROR();
glDispatchCompute(1, 1, 1);
EXPECT_GL_NO_ERROR();
glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
// Verify
const GLfloat *ptr = reinterpret_cast<const GLfloat *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, sizeof(kOutputInitData), GL_MAP_READ_BIT));
EXPECT_EQ(ptr[0], kImage2Data[0]);
EXPECT_EQ(ptr[1], kImage2Data[1]);
EXPECT_NEAR(ptr[2], 135.0f, 0.0001f);
EXPECT_EQ(ptr[3], kImage2Data[3]);
EXPECT_NEAR(ptr[4], 1234.5f, 0.0001f);
EXPECT_NEAR(ptr[5], kImage2Data[0], 0.0001f);
EXPECT_NEAR(ptr[6], kImage2Size, 0.0001f);
EXPECT_NEAR(ptr[7], 678.0f, 0.0001f);
EXPECT_NEAR(ptr[8], kImage2Data[2], 0.0001f);
EXPECT_NEAR(ptr[9], kImage2Data[3], 0.0001f);
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
}
// Test that structs containing arrays of samplers work as expected. // Test that structs containing arrays of samplers work as expected.
TEST_P(GLSLTest_ES31, StructArraySampler) TEST_P(GLSLTest_ES31, StructArraySampler)
{ {
......
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