Skip to content

Commit

Permalink
Vulkan: Selectively enable emulateR32fImageAtomicExchange
Browse files Browse the repository at this point in the history
Only emulate R32F imageAtomicExchange if shaderImageFloat32Atomics
feature is not supported

Bug: angleproject:42264071
Change-Id: I305ab88bf3ac918eff5d8c399f0ed02ec8c60c2d
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5860814
Reviewed-by: Shahbaz Youssefi <[email protected]>
Commit-Queue: Shahbaz Youssefi <[email protected]>
  • Loading branch information
Mohan Maiya authored and Angle LUCI CQ committed Sep 17, 2024
1 parent 1503a10 commit f2eb878
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 142 deletions.
5 changes: 4 additions & 1 deletion include/GLSLANG/ShaderLang.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

// Version number for shader translation API.
// It is incremented every time the API changes.
#define ANGLE_SH_VERSION 359
#define ANGLE_SH_VERSION 360

enum ShShaderSpec
{
Expand Down Expand Up @@ -454,6 +454,9 @@ struct ShCompileOptions
//
uint64_t rejectWebglShadersWithUndefinedBehavior : 1;

// Emulate r32f image with an r32ui image
uint64_t emulateR32fImageAtomicExchange : 1;

ShCompileOptionsMetal metal;
ShPixelLocalStorageOptions pls;
};
Expand Down
6 changes: 3 additions & 3 deletions scripts/code_generation_hashes/Static_builtins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"src/compiler/translator/Operator_autogen.h":
"abab7c615d0c5d9405fd1b1660e30f31",
"src/compiler/translator/SymbolTable_ESSL_autogen.cpp":
"42141261ac6c15d767d8058268bf8ae8",
"4c9ec06c7ac26aaa550216e60e7b9e4c",
"src/compiler/translator/SymbolTable_autogen.cpp":
"5641b3bdbfb672e5aee894912153e67c",
"379371d3b1060179b10929b183cbe6ae",
"src/compiler/translator/SymbolTable_autogen.h":
"36d32dd6e9e1111a1a04d3e64fddf8d0",
"src/compiler/translator/builtin_function_declarations.txt":
"a0a7b543ad96c6a2a5254de1c0371428",
"c13a6d729055b3ca43b1c2d4efe14aa1",
"src/compiler/translator/builtin_variables.json":
"1cae0a0367342e78f702e789b63e6f55",
"src/compiler/translator/gen_builtin_symbols.py":
Expand Down
132 changes: 66 additions & 66 deletions src/compiler/translator/SymbolTable_ESSL_autogen.cpp

Large diffs are not rendered by default.

132 changes: 66 additions & 66 deletions src/compiler/translator/SymbolTable_autogen.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/compiler/translator/builtin_function_declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ GROUP BEGIN Image {"queryFunction": true}
uint imageAtomicExchange(IMAGE_PARAMS, uint);
int imageAtomicExchange(IMAGE_PARAMS, int);
DEFAULT METADATA {"essl_level": "ESSL3_2_BUILTINS", "glsl_level": "GLSL4_5_BUILTINS", "hasSideEffects": true}
int imageAtomicExchange(IMAGE_PARAMS, float);
float imageAtomicExchange(IMAGE_PARAMS, float);
DEFAULT METADATA {"essl_level": "ESSL3_2_BUILTINS", "glsl_level": "GLSL4_2_BUILTINS", "hasSideEffects": true}
uint imageAtomicCompSwap(IMAGE_PARAMS, uint, uint);
int imageAtomicCompSwap(IMAGE_PARAMS, int, int);
Expand All @@ -1132,7 +1132,7 @@ GROUP BEGIN Image {"queryFunction": true}
int imageAtomicXor(readonly writeonly IMAGE_PARAMS, int);
uint imageAtomicExchange(readonly writeonly IMAGE_PARAMS, uint);
int imageAtomicExchange(readonly writeonly IMAGE_PARAMS, int);
int imageAtomicExchange(readonly writeonly IMAGE_PARAMS, float);
float imageAtomicExchange(readonly writeonly IMAGE_PARAMS, float);
uint imageAtomicCompSwap(readonly writeonly IMAGE_PARAMS, uint, uint);
int imageAtomicCompSwap(readonly writeonly IMAGE_PARAMS, int, int);
GROUP END Atomic
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/translator/spirv/TranslatorSPIRV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ bool TranslatorSPIRV::translateImpl(TIntermBlock *root,
driverUniforms->getDriverUniformsVariable()->getType().getInterfaceBlock()->uniqueId(),
vk::spirv::kIdDriverUniformsBlock);

if (r32fImageCount > 0)
if (r32fImageCount > 0 && compileOptions.emulateR32fImageAtomicExchange)
{
if (!RewriteR32fImages(this, root, &getSymbolTable()))
{
Expand Down
5 changes: 5 additions & 0 deletions src/libANGLE/renderer/vulkan/ShaderVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ std::shared_ptr<ShaderTranslateTask> ShaderVk::compile(const gl::Context *contex
options->wrapSwitchInIfTrue = true;
}

if (contextVk->getFeatures().emulateR32fImageAtomicExchange.enabled)
{
options->emulateR32fImageAtomicExchange = true;
}

// The Vulkan backend needs no post-processing of the translated shader.
return std::shared_ptr<ShaderTranslateTask>(new ShaderTranslateTask);
}
Expand Down
25 changes: 22 additions & 3 deletions src/libANGLE/renderer/vulkan/vk_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,7 @@ angle::Result Renderer::initializeMemoryAllocator(vk::Context *context)
// - VK_ANDROID_external_format_resolve: externalFormatResolve (feature)
// - VK_EXT_vertex_input_dynamic_state: vertexInputDynamicState (feature)
// - VK_KHR_dynamic_rendering_local_read: dynamicRenderingLocalRead (feature)
// - VK_EXT_shader_atomic_float shaderImageFloat32Atomics (feature)
//
void Renderer::appendDeviceExtensionFeaturesNotPromoted(
const vk::ExtensionNameList &deviceExtensionNames,
Expand Down Expand Up @@ -2407,6 +2408,11 @@ void Renderer::appendDeviceExtensionFeaturesNotPromoted(
vk::AddToPNextChain(deviceFeatures, &mRasterizationOrderAttachmentAccessFeatures);
}

if (ExtensionFound(VK_EXT_SHADER_ATOMIC_FLOAT_EXTENSION_NAME, deviceExtensionNames))
{
vk::AddToPNextChain(deviceFeatures, &mShaderAtomicFloatFeatures);
}

if (ExtensionFound(VK_EXT_SWAPCHAIN_MAINTENANCE_1_EXTENSION_NAME, deviceExtensionNames))
{
vk::AddToPNextChain(deviceFeatures, &mSwapchainMaintenance1Features);
Expand Down Expand Up @@ -2801,6 +2807,10 @@ void Renderer::queryDeviceExtensionFeatures(const vk::ExtensionNameList &deviceE
mMaintenance5Features = {};
mMaintenance5Features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_5_FEATURES_KHR;

mShaderAtomicFloatFeatures = {};
mShaderAtomicFloatFeatures.sType =
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_FEATURES_EXT;

mSwapchainMaintenance1Features = {};
mSwapchainMaintenance1Features.sType =
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SWAPCHAIN_MAINTENANCE_1_FEATURES_EXT;
Expand Down Expand Up @@ -2912,6 +2922,7 @@ void Renderer::queryDeviceExtensionFeatures(const vk::ExtensionNameList &deviceE
mPipelineRobustnessFeatures.pNext = nullptr;
mPipelineProtectedAccessFeatures.pNext = nullptr;
mRasterizationOrderAttachmentAccessFeatures.pNext = nullptr;
mShaderAtomicFloatFeatures.pNext = nullptr;
mMaintenance5Features.pNext = nullptr;
mSwapchainMaintenance1Features.pNext = nullptr;
mDitheringFeatures.pNext = nullptr;
Expand Down Expand Up @@ -3178,6 +3189,13 @@ void Renderer::enableDeviceExtensionsNotPromoted(const vk::ExtensionNameList &de
vk::AddToPNextChain(&mEnabledFeatures, &mRasterizationOrderAttachmentAccessFeatures);
}

if (!mFeatures.emulateR32fImageAtomicExchange.enabled)
{
ASSERT(ExtensionFound(VK_EXT_SHADER_ATOMIC_FLOAT_EXTENSION_NAME, deviceExtensionNames));
mEnabledDeviceExtensions.push_back(VK_EXT_SHADER_ATOMIC_FLOAT_EXTENSION_NAME);
vk::AddToPNextChain(&mEnabledFeatures, &mShaderAtomicFloatFeatures);
}

if (mFeatures.supportsImage2dViewOf3d.enabled)
{
mEnabledDeviceExtensions.push_back(VK_EXT_IMAGE_2D_VIEW_OF_3D_EXTENSION_NAME);
Expand Down Expand Up @@ -4810,9 +4828,10 @@ void Renderer::initFeatures(const vk::ExtensionNameList &deviceExtensionNames,
&mFeatures, preferDrawClearOverVkCmdClearAttachments,
isQualcommProprietary && qualcommDriverVersion < QualcommDriverVersion(512, 762, 12));

// r32f image emulation is done unconditionally so VK_FORMAT_FEATURE_STORAGE_*_ATOMIC_BIT is not
// required.
ANGLE_FEATURE_CONDITION(&mFeatures, emulateR32fImageAtomicExchange, true);
// R32F imageAtomicExchange emulation is done if shaderImageFloat32Atomics feature is not
// supported.
ANGLE_FEATURE_CONDITION(&mFeatures, emulateR32fImageAtomicExchange,
mShaderAtomicFloatFeatures.shaderImageFloat32Atomics != VK_TRUE);

// Whether non-conformant configurations and extensions should be exposed.
ANGLE_FEATURE_CONDITION(&mFeatures, exposeNonConformantExtensionsAndVersions,
Expand Down
1 change: 1 addition & 0 deletions src/libANGLE/renderer/vulkan/vk_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ class Renderer : angle::NonCopyable
VkPhysicalDevicePipelineProtectedAccessFeaturesEXT mPipelineProtectedAccessFeatures;
VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT
mRasterizationOrderAttachmentAccessFeatures;
VkPhysicalDeviceShaderAtomicFloatFeaturesEXT mShaderAtomicFloatFeatures;
VkPhysicalDeviceMaintenance5FeaturesKHR mMaintenance5Features;
VkPhysicalDeviceSwapchainMaintenance1FeaturesEXT mSwapchainMaintenance1Features;
VkPhysicalDeviceLegacyDitheringFeaturesEXT mDitheringFeatures;
Expand Down

0 comments on commit f2eb878

Please sign in to comment.