Commit b717952e by Jamie Madill Committed by Commit Bot

Vulkan: Use packed enum map for descriptor set index.

This simplifies a lot of the data structure indexing in the program executable class. Also renames the "DriverUniforms" and "InternalShader" index into a single "Internal" index. Bug: angleproject:5736 Change-Id: I2a51d8b14d5b16b438dbe636f77b11bbc045ba9a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2773321 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent 1b08cfcb
...@@ -3942,7 +3942,7 @@ void ContextVk::invalidateComputePipelineBinding() ...@@ -3942,7 +3942,7 @@ void ContextVk::invalidateComputePipelineBinding()
void ContextVk::invalidateGraphicsDescriptorSet(DescriptorSetIndex usedDescriptorSet) void ContextVk::invalidateGraphicsDescriptorSet(DescriptorSetIndex usedDescriptorSet)
{ {
// UtilsVk currently only uses set 0 // UtilsVk currently only uses set 0
ASSERT(usedDescriptorSet == DescriptorSetIndex::DriverUniforms); ASSERT(usedDescriptorSet == DescriptorSetIndex::Internal);
if (mDriverUniforms[PipelineType::Graphics].descriptorSet != VK_NULL_HANDLE) if (mDriverUniforms[PipelineType::Graphics].descriptorSet != VK_NULL_HANDLE)
{ {
mGraphicsDirtyBits.set(DIRTY_BIT_DRIVER_UNIFORMS_BINDING); mGraphicsDirtyBits.set(DIRTY_BIT_DRIVER_UNIFORMS_BINDING);
...@@ -3952,7 +3952,7 @@ void ContextVk::invalidateGraphicsDescriptorSet(DescriptorSetIndex usedDescripto ...@@ -3952,7 +3952,7 @@ void ContextVk::invalidateGraphicsDescriptorSet(DescriptorSetIndex usedDescripto
void ContextVk::invalidateComputeDescriptorSet(DescriptorSetIndex usedDescriptorSet) void ContextVk::invalidateComputeDescriptorSet(DescriptorSetIndex usedDescriptorSet)
{ {
// UtilsVk currently only uses set 0 // UtilsVk currently only uses set 0
ASSERT(usedDescriptorSet == DescriptorSetIndex::DriverUniforms); ASSERT(usedDescriptorSet == DescriptorSetIndex::Internal);
if (mDriverUniforms[PipelineType::Compute].descriptorSet != VK_NULL_HANDLE) if (mDriverUniforms[PipelineType::Compute].descriptorSet != VK_NULL_HANDLE)
{ {
mComputeDirtyBits.set(DIRTY_BIT_DRIVER_UNIFORMS_BINDING); mComputeDirtyBits.set(DIRTY_BIT_DRIVER_UNIFORMS_BINDING);
...@@ -4355,7 +4355,7 @@ void ContextVk::handleDirtyDriverUniformsBindingImpl(vk::CommandBuffer *commandB ...@@ -4355,7 +4355,7 @@ void ContextVk::handleDirtyDriverUniformsBindingImpl(vk::CommandBuffer *commandB
} }
commandBuffer->bindDescriptorSets( commandBuffer->bindDescriptorSets(
mExecutable->getPipelineLayout(), bindPoint, DescriptorSetIndex::DriverUniforms, 1, mExecutable->getPipelineLayout(), bindPoint, DescriptorSetIndex::Internal, 1,
&driverUniforms->descriptorSet, 1, &driverUniforms->dynamicOffset); &driverUniforms->descriptorSet, 1, &driverUniforms->dynamicOffset);
} }
......
...@@ -51,7 +51,7 @@ void GlslangWrapperVk::ResetGlslangProgramInterfaceInfo( ...@@ -51,7 +51,7 @@ void GlslangWrapperVk::ResetGlslangProgramInterfaceInfo(
ToUnderlying(DescriptorSetIndex::ShaderResource); ToUnderlying(DescriptorSetIndex::ShaderResource);
glslangProgramInterfaceInfo->currentShaderResourceBindingIndex = 0; glslangProgramInterfaceInfo->currentShaderResourceBindingIndex = 0;
glslangProgramInterfaceInfo->driverUniformsDescriptorSetIndex = glslangProgramInterfaceInfo->driverUniformsDescriptorSetIndex =
ToUnderlying(DescriptorSetIndex::DriverUniforms); ToUnderlying(DescriptorSetIndex::Internal);
glslangProgramInterfaceInfo->locationsUsedForXfbExtension = 0; glslangProgramInterfaceInfo->locationsUsedForXfbExtension = 0;
} }
......
...@@ -102,7 +102,7 @@ struct DefaultUniformBlock final : private angle::NonCopyable ...@@ -102,7 +102,7 @@ struct DefaultUniformBlock final : private angle::NonCopyable
}; };
// Performance and resource counters. // Performance and resource counters.
using DescriptorSetCountList = std::array<uint32_t, DescriptorSetIndex::EnumCount>; using DescriptorSetCountList = angle::PackedEnumMap<DescriptorSetIndex, uint32_t>;
struct ProgramExecutablePerfCounters struct ProgramExecutablePerfCounters
{ {
......
...@@ -124,12 +124,6 @@ class ProgramVk : public ProgramImpl ...@@ -124,12 +124,6 @@ class ProgramVk : public ProgramImpl
} }
void onProgramBind(); void onProgramBind();
// Used in testing only.
vk::DynamicDescriptorPool *getDynamicDescriptorPool(uint32_t poolIndex)
{
return &mExecutable.mDynamicDescriptorPools[poolIndex];
}
const ProgramExecutableVk &getExecutable() const { return mExecutable; } const ProgramExecutableVk &getExecutable() const { return mExecutable; }
ProgramExecutableVk &getExecutable() { return mExecutable; } ProgramExecutableVk &getExecutable() { return mExecutable; }
......
...@@ -17,12 +17,10 @@ ...@@ -17,12 +17,10 @@
namespace rx namespace rx
{ {
enum class DescriptorSetIndex : uint32_t;
enum DescriptorSetIndex : uint32_t;
namespace vk namespace vk
{ {
namespace priv namespace priv
{ {
......
...@@ -666,7 +666,7 @@ void InsertInputDecorations(spirv::IdRef id, ...@@ -666,7 +666,7 @@ void InsertInputDecorations(spirv::IdRef id,
angle::spirv::Blob *blobOut) angle::spirv::Blob *blobOut)
{ {
spirv::WriteDecorate(blobOut, id, spv::DecorationDescriptorSet, spirv::WriteDecorate(blobOut, id, spv::DecorationDescriptorSet,
{spirv::LiteralInteger(DescriptorSetIndex::InternalShader)}); {spirv::LiteralInteger(ToUnderlying(DescriptorSetIndex::Internal))});
spirv::WriteDecorate(blobOut, id, spv::DecorationBinding, {spirv::LiteralInteger(binding)}); spirv::WriteDecorate(blobOut, id, spv::DecorationBinding, {spirv::LiteralInteger(binding)});
spirv::WriteDecorate(blobOut, id, spv::DecorationInputAttachmentIndex, spirv::WriteDecorate(blobOut, id, spv::DecorationInputAttachmentIndex,
{spirv::LiteralInteger(attachmentIndex)}); {spirv::LiteralInteger(attachmentIndex)});
...@@ -1129,7 +1129,7 @@ angle::Result UtilsVk::ensureResourcesInitialized(ContextVk *contextVk, ...@@ -1129,7 +1129,7 @@ angle::Result UtilsVk::ensureResourcesInitialized(ContextVk *contextVk,
ANGLE_TRY(contextVk->getDescriptorSetLayoutCache().getDescriptorSetLayout( ANGLE_TRY(contextVk->getDescriptorSetLayoutCache().getDescriptorSetLayout(
contextVk, descriptorSetDesc, contextVk, descriptorSetDesc,
&mDescriptorSetLayouts[function][ToUnderlying(DescriptorSetIndex::InternalShader)])); &mDescriptorSetLayouts[function][DescriptorSetIndex::Internal]));
vk::DescriptorSetLayoutBindingVector bindingVector; vk::DescriptorSetLayoutBindingVector bindingVector;
std::vector<VkSampler> immutableSamplers; std::vector<VkSampler> immutableSamplers;
...@@ -1151,9 +1151,7 @@ angle::Result UtilsVk::ensureResourcesInitialized(ContextVk *contextVk, ...@@ -1151,9 +1151,7 @@ angle::Result UtilsVk::ensureResourcesInitialized(ContextVk *contextVk,
{ {
ANGLE_TRY(mDescriptorPools[function].init( ANGLE_TRY(mDescriptorPools[function].init(
contextVk, descriptorPoolSizes.data(), descriptorPoolSizes.size(), contextVk, descriptorPoolSizes.data(), descriptorPoolSizes.size(),
mDescriptorSetLayouts[function][ToUnderlying(DescriptorSetIndex::InternalShader)] mDescriptorSetLayouts[function][DescriptorSetIndex::Internal].get().getHandle()));
.get()
.getHandle()));
} }
gl::ShaderType pushConstantsShaderStage = gl::ShaderType pushConstantsShaderStage =
...@@ -1162,8 +1160,7 @@ angle::Result UtilsVk::ensureResourcesInitialized(ContextVk *contextVk, ...@@ -1162,8 +1160,7 @@ angle::Result UtilsVk::ensureResourcesInitialized(ContextVk *contextVk,
// Corresponding pipeline layouts: // Corresponding pipeline layouts:
vk::PipelineLayoutDesc pipelineLayoutDesc; vk::PipelineLayoutDesc pipelineLayoutDesc;
pipelineLayoutDesc.updateDescriptorSetLayout(DescriptorSetIndex::InternalShader, pipelineLayoutDesc.updateDescriptorSetLayout(DescriptorSetIndex::Internal, descriptorSetDesc);
descriptorSetDesc);
if (pushConstantsSize) if (pushConstantsSize)
{ {
pipelineLayoutDesc.updatePushConstantRange(pushConstantsShaderStage, 0, pipelineLayoutDesc.updatePushConstantRange(pushConstantsShaderStage, 0,
...@@ -1496,15 +1493,15 @@ angle::Result UtilsVk::setupProgram(ContextVk *contextVk, ...@@ -1496,15 +1493,15 @@ angle::Result UtilsVk::setupProgram(ContextVk *contextVk,
if (descriptorSet != VK_NULL_HANDLE) if (descriptorSet != VK_NULL_HANDLE)
{ {
commandBuffer->bindDescriptorSets(pipelineLayout.get(), pipelineBindPoint, commandBuffer->bindDescriptorSets(pipelineLayout.get(), pipelineBindPoint,
DescriptorSetIndex::InternalShader, 1, &descriptorSet, 0, DescriptorSetIndex::Internal, 1, &descriptorSet, 0,
nullptr); nullptr);
if (isCompute) if (isCompute)
{ {
contextVk->invalidateComputeDescriptorSet(DescriptorSetIndex::InternalShader); contextVk->invalidateComputeDescriptorSet(DescriptorSetIndex::Internal);
} }
else else
{ {
contextVk->invalidateGraphicsDescriptorSet(DescriptorSetIndex::InternalShader); contextVk->invalidateGraphicsDescriptorSet(DescriptorSetIndex::Internal);
} }
} }
...@@ -3440,11 +3437,8 @@ angle::Result UtilsVk::allocateDescriptorSet(ContextVk *contextVk, ...@@ -3440,11 +3437,8 @@ angle::Result UtilsVk::allocateDescriptorSet(ContextVk *contextVk,
VkDescriptorSet *descriptorSetOut) VkDescriptorSet *descriptorSetOut)
{ {
ANGLE_TRY(mDescriptorPools[function].allocateSets( ANGLE_TRY(mDescriptorPools[function].allocateSets(
contextVk, contextVk, mDescriptorSetLayouts[function][DescriptorSetIndex::Internal].get().ptr(), 1,
mDescriptorSetLayouts[function][ToUnderlying(DescriptorSetIndex::InternalShader)] bindingOut, descriptorSetOut));
.get()
.ptr(),
1, bindingOut, descriptorSetOut));
mObjectPerfCounters.descriptorSetsAllocated++; mObjectPerfCounters.descriptorSetsAllocated++;
......
...@@ -2879,8 +2879,7 @@ bool PipelineLayoutDesc::operator==(const PipelineLayoutDesc &other) const ...@@ -2879,8 +2879,7 @@ bool PipelineLayoutDesc::operator==(const PipelineLayoutDesc &other) const
void PipelineLayoutDesc::updateDescriptorSetLayout(DescriptorSetIndex setIndex, void PipelineLayoutDesc::updateDescriptorSetLayout(DescriptorSetIndex setIndex,
const DescriptorSetLayoutDesc &desc) const DescriptorSetLayoutDesc &desc)
{ {
ASSERT(ToUnderlying(setIndex) < mDescriptorSetLayouts.size()); mDescriptorSetLayouts[setIndex] = desc;
mDescriptorSetLayouts[ToUnderlying(setIndex)] = desc;
} }
void PipelineLayoutDesc::updatePushConstantRange(gl::ShaderType shaderType, void PipelineLayoutDesc::updatePushConstantRange(gl::ShaderType shaderType,
......
...@@ -35,16 +35,12 @@ namespace rx ...@@ -35,16 +35,12 @@ namespace rx
// - Set 3 contains all other shader resources, such as uniform and storage blocks, atomic counter // - Set 3 contains all other shader resources, such as uniform and storage blocks, atomic counter
// buffers, images and image buffers. // buffers, images and image buffers.
// ANGLE driver uniforms set index (binding is always 0): enum class DescriptorSetIndex : uint32_t
enum DescriptorSetIndex : uint32_t
{ {
// All internal shaders assume there is only one descriptor set, indexed at 0 Internal, // ANGLE driver uniforms or internal shaders
InternalShader = 0, UniformsAndXfb, // Uniforms set index
Texture, // Textures set index
DriverUniforms = 0, // ANGLE driver uniforms set index ShaderResource, // Other shader resources set index
UniformsAndXfb, // Uniforms set index
Texture, // Textures set index
ShaderResource, // Other shader resources set index
InvalidEnum, InvalidEnum,
EnumCount = InvalidEnum, EnumCount = InvalidEnum,
...@@ -839,7 +835,7 @@ struct PackedPushConstantRange ...@@ -839,7 +835,7 @@ struct PackedPushConstantRange
}; };
template <typename T> template <typename T>
using DescriptorSetLayoutArray = std::array<T, static_cast<size_t>(DescriptorSetIndex::EnumCount)>; using DescriptorSetLayoutArray = angle::PackedEnumMap<DescriptorSetIndex, T>;
using DescriptorSetLayoutPointerArray = using DescriptorSetLayoutPointerArray =
DescriptorSetLayoutArray<BindingPointer<DescriptorSetLayout>>; DescriptorSetLayoutArray<BindingPointer<DescriptorSetLayout>>;
template <typename T> template <typename T>
......
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