Commit 85c076ee by Tim Van Patten Committed by Commit Bot

Vulkan: Make mVariableInfoMap a gl::ShaderMap<>

The ShaderInterfaceVariableInfoMap information is specific to each shader stage, since the locations are determined for each shader stage. This change makes mVariableInfoMap a gl::ShaderMap<> to handle this, which will make it easier to compile separable programs, determine the variable locations, and transform the SPIR-V. Bug: angleproject:3570 Change-Id: I28b71a37efe54bbcfe1dcd445fa03ee71e74f0a6 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2062741 Commit-Queue: Tim Van Patten <timvp@google.com> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com>
parent abaa3573
...@@ -73,8 +73,8 @@ struct ShaderInterfaceVariableInfo ...@@ -73,8 +73,8 @@ struct ShaderInterfaceVariableInfo
// variables that share the same name, such as a vertex attribute and a fragment output. They // variables that share the same name, such as a vertex attribute and a fragment output. They
// will share this object since they have the same name, but will find possibly different // will share this object since they have the same name, but will find possibly different
// locations in their respective slots. // locations in their respective slots.
gl::ShaderMap<uint32_t> location; uint32_t location = kInvalid;
gl::ShaderMap<uint32_t> component; uint32_t component = kInvalid;
// The stages this shader interface variable is active. // The stages this shader interface variable is active.
gl::ShaderBitSet activeStages; gl::ShaderBitSet activeStages;
// Used for transform feedback extension to decorate vertex shader output. // Used for transform feedback extension to decorate vertex shader output.
...@@ -86,6 +86,7 @@ struct ShaderInterfaceVariableInfo ...@@ -86,6 +86,7 @@ struct ShaderInterfaceVariableInfo
// TODO: http://anglebug.com/4524: Need a different hash key than a string, since // TODO: http://anglebug.com/4524: Need a different hash key than a string, since
// that's slow to calculate. // that's slow to calculate.
using ShaderInterfaceVariableInfoMap = std::unordered_map<std::string, ShaderInterfaceVariableInfo>; using ShaderInterfaceVariableInfoMap = std::unordered_map<std::string, ShaderInterfaceVariableInfo>;
using ShaderMapInterfaceVariableInfoMap = gl::ShaderMap<ShaderInterfaceVariableInfoMap>;
void GlslangInitialize(); void GlslangInitialize();
void GlslangRelease(); void GlslangRelease();
...@@ -106,12 +107,12 @@ void GlslangGetShaderSource(GlslangSourceOptions &options, ...@@ -106,12 +107,12 @@ void GlslangGetShaderSource(GlslangSourceOptions &options,
const gl::ProgramLinkedResources &resources, const gl::ProgramLinkedResources &resources,
GlslangProgramInterfaceInfo *programInterfaceInfo, GlslangProgramInterfaceInfo *programInterfaceInfo,
gl::ShaderMap<std::string> *shaderSourcesOut, gl::ShaderMap<std::string> *shaderSourcesOut,
ShaderInterfaceVariableInfoMap *variableInfoMapOut); ShaderMapInterfaceVariableInfoMap *variableInfoMapOut);
angle::Result GlslangGetShaderSpirvCode(const GlslangErrorCallback &callback, angle::Result GlslangGetShaderSpirvCode(const GlslangErrorCallback &callback,
const gl::Caps &glCaps, const gl::Caps &glCaps,
const gl::ShaderMap<std::string> &shaderSources, const gl::ShaderMap<std::string> &shaderSources,
const ShaderInterfaceVariableInfoMap &variableInfoMap, const ShaderMapInterfaceVariableInfoMap &variableInfoMap,
gl::ShaderMap<SpirvBlob> *spirvBlobsOut); gl::ShaderMap<SpirvBlob> *spirvBlobsOut);
} // namespace rx } // namespace rx
......
...@@ -312,7 +312,7 @@ angle::Result ProgramMtl::linkImpl(const gl::Context *glContext, ...@@ -312,7 +312,7 @@ angle::Result ProgramMtl::linkImpl(const gl::Context *glContext,
// Gather variable info and transform sources. // Gather variable info and transform sources.
gl::ShaderMap<std::string> shaderSources; gl::ShaderMap<std::string> shaderSources;
ShaderInterfaceVariableInfoMap variableInfoMap; ShaderMapInterfaceVariableInfoMap variableInfoMap;
mtl::GlslangGetShaderSource(mState, resources, &shaderSources, &variableInfoMap); mtl::GlslangGetShaderSource(mState, resources, &shaderSources, &variableInfoMap);
// Convert GLSL to spirv code // Convert GLSL to spirv code
......
...@@ -22,12 +22,12 @@ namespace mtl ...@@ -22,12 +22,12 @@ namespace mtl
void GlslangGetShaderSource(const gl::ProgramState &programState, void GlslangGetShaderSource(const gl::ProgramState &programState,
const gl::ProgramLinkedResources &resources, const gl::ProgramLinkedResources &resources,
gl::ShaderMap<std::string> *shaderSourcesOut, gl::ShaderMap<std::string> *shaderSourcesOut,
ShaderInterfaceVariableInfoMap *variableInfoMapOut); ShaderMapInterfaceVariableInfoMap *variableInfoMapOut);
angle::Result GlslangGetShaderSpirvCode(ErrorHandler *context, angle::Result GlslangGetShaderSpirvCode(ErrorHandler *context,
const gl::Caps &glCaps, const gl::Caps &glCaps,
const gl::ShaderMap<std::string> &shaderSources, const gl::ShaderMap<std::string> &shaderSources,
const ShaderInterfaceVariableInfoMap &variableInfoMap, const ShaderMapInterfaceVariableInfoMap &variableInfoMap,
gl::ShaderMap<std::vector<uint32_t>> *shaderCodeOut); gl::ShaderMap<std::vector<uint32_t>> *shaderCodeOut);
} // namespace mtl } // namespace mtl
} // namespace rx } // namespace rx
......
...@@ -50,7 +50,7 @@ GlslangSourceOptions CreateSourceOptions() ...@@ -50,7 +50,7 @@ GlslangSourceOptions CreateSourceOptions()
void GlslangGetShaderSource(const gl::ProgramState &programState, void GlslangGetShaderSource(const gl::ProgramState &programState,
const gl::ProgramLinkedResources &resources, const gl::ProgramLinkedResources &resources,
gl::ShaderMap<std::string> *shaderSourcesOut, gl::ShaderMap<std::string> *shaderSourcesOut,
ShaderInterfaceVariableInfoMap *variableInfoMapOut) ShaderMapInterfaceVariableInfoMap *variableInfoMapOut)
{ {
GlslangSourceOptions options = CreateSourceOptions(); GlslangSourceOptions options = CreateSourceOptions();
GlslangProgramInterfaceInfo programInterfaceInfo; GlslangProgramInterfaceInfo programInterfaceInfo;
...@@ -63,7 +63,7 @@ void GlslangGetShaderSource(const gl::ProgramState &programState, ...@@ -63,7 +63,7 @@ void GlslangGetShaderSource(const gl::ProgramState &programState,
angle::Result GlslangGetShaderSpirvCode(ErrorHandler *context, angle::Result GlslangGetShaderSpirvCode(ErrorHandler *context,
const gl::Caps &glCaps, const gl::Caps &glCaps,
const gl::ShaderMap<std::string> &shaderSources, const gl::ShaderMap<std::string> &shaderSources,
const ShaderInterfaceVariableInfoMap &variableInfoMap, const ShaderMapInterfaceVariableInfoMap &variableInfoMap,
gl::ShaderMap<std::vector<uint32_t>> *shaderCodeOut) gl::ShaderMap<std::vector<uint32_t>> *shaderCodeOut)
{ {
return rx::GlslangGetShaderSpirvCode( return rx::GlslangGetShaderSpirvCode(
......
...@@ -61,7 +61,7 @@ void GlslangWrapperVk::GetShaderSource(const angle::FeaturesVk &features, ...@@ -61,7 +61,7 @@ void GlslangWrapperVk::GetShaderSource(const angle::FeaturesVk &features,
const gl::ProgramLinkedResources &resources, const gl::ProgramLinkedResources &resources,
GlslangProgramInterfaceInfo *programInterfaceInfo, GlslangProgramInterfaceInfo *programInterfaceInfo,
gl::ShaderMap<std::string> *shaderSourcesOut, gl::ShaderMap<std::string> *shaderSourcesOut,
ShaderInterfaceVariableInfoMap *variableInfoMapOut) ShaderMapInterfaceVariableInfoMap *variableInfoMapOut)
{ {
GlslangSourceOptions options = CreateSourceOptions(features); GlslangSourceOptions options = CreateSourceOptions(features);
GlslangGetShaderSource(options, programState, resources, programInterfaceInfo, shaderSourcesOut, GlslangGetShaderSource(options, programState, resources, programInterfaceInfo, shaderSourcesOut,
...@@ -69,11 +69,12 @@ void GlslangWrapperVk::GetShaderSource(const angle::FeaturesVk &features, ...@@ -69,11 +69,12 @@ void GlslangWrapperVk::GetShaderSource(const angle::FeaturesVk &features,
} }
// static // static
angle::Result GlslangWrapperVk::GetShaderCode(vk::Context *context, angle::Result GlslangWrapperVk::GetShaderCode(
const gl::Caps &glCaps, vk::Context *context,
const gl::ShaderMap<std::string> &shaderSources, const gl::Caps &glCaps,
const ShaderInterfaceVariableInfoMap &variableInfoMap, const gl::ShaderMap<std::string> &shaderSources,
gl::ShaderMap<std::vector<uint32_t>> *shaderCodeOut) const ShaderMapInterfaceVariableInfoMap &variableInfoMap,
gl::ShaderMap<std::vector<uint32_t>> *shaderCodeOut)
{ {
return GlslangGetShaderSpirvCode( return GlslangGetShaderSpirvCode(
[context](GlslangError error) { return ErrorHandler(context, error); }, glCaps, [context](GlslangError error) { return ErrorHandler(context, error); }, glCaps,
......
...@@ -35,12 +35,12 @@ class GlslangWrapperVk ...@@ -35,12 +35,12 @@ class GlslangWrapperVk
const gl::ProgramLinkedResources &resources, const gl::ProgramLinkedResources &resources,
GlslangProgramInterfaceInfo *programInterfaceInfo, GlslangProgramInterfaceInfo *programInterfaceInfo,
gl::ShaderMap<std::string> *shaderSourcesOut, gl::ShaderMap<std::string> *shaderSourcesOut,
ShaderInterfaceVariableInfoMap *variableInfoMapOut); ShaderMapInterfaceVariableInfoMap *variableInfoMapOut);
static angle::Result GetShaderCode(vk::Context *context, static angle::Result GetShaderCode(vk::Context *context,
const gl::Caps &glCaps, const gl::Caps &glCaps,
const gl::ShaderMap<std::string> &shaderSources, const gl::ShaderMap<std::string> &shaderSources,
const ShaderInterfaceVariableInfoMap &variableInfoMap, const ShaderMapInterfaceVariableInfoMap &variableInfoMap,
gl::ShaderMap<std::vector<uint32_t>> *shaderCodesOut); gl::ShaderMap<std::vector<uint32_t>> *shaderCodesOut);
}; };
} // namespace rx } // namespace rx
......
...@@ -48,7 +48,10 @@ class ProgramExecutableVk ...@@ -48,7 +48,10 @@ class ProgramExecutableVk
std::unique_ptr<rx::LinkEvent> load(gl::BinaryInputStream *stream); std::unique_ptr<rx::LinkEvent> load(gl::BinaryInputStream *stream);
void clearVariableInfoMap(); void clearVariableInfoMap();
ShaderInterfaceVariableInfoMap &getShaderInterfaceVariableInfoMap() { return mVariableInfoMap; } ShaderMapInterfaceVariableInfoMap &getShaderInterfaceVariableInfoMap()
{
return mVariableInfoMap;
}
const vk::PipelineLayout &getPipelineLayout() const { return mPipelineLayout.get(); } const vk::PipelineLayout &getPipelineLayout() const { return mPipelineLayout.get(); }
angle::Result createPipelineLayout(const gl::Context *glContext, angle::Result createPipelineLayout(const gl::Context *glContext,
...@@ -77,10 +80,12 @@ class ProgramExecutableVk ...@@ -77,10 +80,12 @@ class ProgramExecutableVk
uint32_t descriptorSetIndex, uint32_t descriptorSetIndex,
bool *newPoolAllocatedOut); bool *newPoolAllocatedOut);
void addInterfaceBlockDescriptorSetDesc(const std::vector<gl::InterfaceBlock> &blocks, void addInterfaceBlockDescriptorSetDesc(const std::vector<gl::InterfaceBlock> &blocks,
const gl::ShaderType shaderType,
VkDescriptorType descType, VkDescriptorType descType,
vk::DescriptorSetLayoutDesc *descOut); vk::DescriptorSetLayoutDesc *descOut);
void addAtomicCounterBufferDescriptorSetDesc( void addAtomicCounterBufferDescriptorSetDesc(
const std::vector<gl::AtomicCounterBuffer> &atomicCounterBuffers, const std::vector<gl::AtomicCounterBuffer> &atomicCounterBuffers,
const gl::ShaderType shaderType,
vk::DescriptorSetLayoutDesc *descOut); vk::DescriptorSetLayoutDesc *descOut);
void addImageDescriptorSetDesc(const gl::ProgramState &programState, void addImageDescriptorSetDesc(const gl::ProgramState &programState,
vk::DescriptorSetLayoutDesc *descOut); vk::DescriptorSetLayoutDesc *descOut);
...@@ -95,15 +100,18 @@ class ProgramExecutableVk ...@@ -95,15 +100,18 @@ class ProgramExecutableVk
void updateTransformFeedbackDescriptorSetImpl(const gl::ProgramState &programState, void updateTransformFeedbackDescriptorSetImpl(const gl::ProgramState &programState,
ContextVk *contextVk); ContextVk *contextVk);
void updateBuffersDescriptorSet(ContextVk *contextVk, void updateBuffersDescriptorSet(ContextVk *contextVk,
const gl::ShaderType shaderType,
vk::ResourceUseList *resourceUseList, vk::ResourceUseList *resourceUseList,
CommandBufferHelper *commandBufferHelper, CommandBufferHelper *commandBufferHelper,
const std::vector<gl::InterfaceBlock> &blocks, const std::vector<gl::InterfaceBlock> &blocks,
VkDescriptorType descriptorType); VkDescriptorType descriptorType);
void updateAtomicCounterBuffersDescriptorSet(const gl::ProgramState &programState, void updateAtomicCounterBuffersDescriptorSet(const gl::ProgramState &programState,
const gl::ShaderType shaderType,
ContextVk *contextVk, ContextVk *contextVk,
vk::ResourceUseList *resourceUseList, vk::ResourceUseList *resourceUseList,
CommandBufferHelper *commandBufferHelper); CommandBufferHelper *commandBufferHelper);
angle::Result updateImagesDescriptorSet(const gl::ProgramState &programState, angle::Result updateImagesDescriptorSet(const gl::ProgramState &programState,
const gl::ShaderType shaderType,
ContextVk *contextVk); ContextVk *contextVk);
// This is a special "empty" placeholder buffer for when a shader has no uniforms or doesn't // This is a special "empty" placeholder buffer for when a shader has no uniforms or doesn't
...@@ -139,7 +147,7 @@ class ProgramExecutableVk ...@@ -139,7 +147,7 @@ class ProgramExecutableVk
// TODO: http://anglebug.com/4524: Need a different hash key than a string, // TODO: http://anglebug.com/4524: Need a different hash key than a string,
// since that's slow to calculate. // since that's slow to calculate.
ShaderInterfaceVariableInfoMap mVariableInfoMap; ShaderMapInterfaceVariableInfoMap mVariableInfoMap;
}; };
} // namespace rx } // namespace rx
......
...@@ -168,7 +168,7 @@ ProgramVk::ShaderInfo::~ShaderInfo() = default; ...@@ -168,7 +168,7 @@ ProgramVk::ShaderInfo::~ShaderInfo() = default;
angle::Result ProgramVk::ShaderInfo::initShaders( angle::Result ProgramVk::ShaderInfo::initShaders(
ContextVk *contextVk, ContextVk *contextVk,
const gl::ShaderMap<std::string> &shaderSources, const gl::ShaderMap<std::string> &shaderSources,
const ShaderInterfaceVariableInfoMap &variableInfoMap) const ShaderMapInterfaceVariableInfoMap &variableInfoMap)
{ {
ASSERT(!valid()); ASSERT(!valid());
......
...@@ -224,7 +224,7 @@ class ProgramVk : public ProgramImpl ...@@ -224,7 +224,7 @@ class ProgramVk : public ProgramImpl
angle::Result initShaders(ContextVk *contextVk, angle::Result initShaders(ContextVk *contextVk,
const gl::ShaderMap<std::string> &shaderSources, const gl::ShaderMap<std::string> &shaderSources,
const ShaderInterfaceVariableInfoMap &variableInfoMap); const ShaderMapInterfaceVariableInfoMap &variableInfoMap);
void release(ContextVk *contextVk); void release(ContextVk *contextVk);
ANGLE_INLINE bool valid() const { return mIsInitialized; } ANGLE_INLINE bool valid() const { return mIsInitialized; }
......
...@@ -303,10 +303,10 @@ void TransformFeedbackVk::writeDescriptorSet(ContextVk *contextVk, ...@@ -303,10 +303,10 @@ void TransformFeedbackVk::writeDescriptorSet(ContextVk *contextVk,
{ {
VkDevice device = contextVk->getDevice(); VkDevice device = contextVk->getDevice();
ProgramExecutableVk *executableVk = contextVk->getExecutable(); ProgramExecutableVk *executableVk = contextVk->getExecutable();
ShaderInterfaceVariableInfoMap variableInfoMap = ShaderMapInterfaceVariableInfoMap variableInfoMap =
executableVk->getShaderInterfaceVariableInfoMap(); executableVk->getShaderInterfaceVariableInfoMap();
const std::string bufferName = GetXfbBufferName(0); const std::string bufferName = GetXfbBufferName(0);
ShaderInterfaceVariableInfo &info = variableInfoMap[bufferName]; ShaderInterfaceVariableInfo &info = variableInfoMap[gl::ShaderType::Vertex][bufferName];
VkWriteDescriptorSet writeDescriptorInfo = {}; VkWriteDescriptorSet writeDescriptorInfo = {};
writeDescriptorInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; writeDescriptorInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
......
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