Added type information to SHShaderBlockInterface variables
This commit is contained in:
parent
bc8b5f8167
commit
76f83068ba
|
@ -14,6 +14,7 @@ namespace SHADE
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
variables.emplace_back(std::move(newVariable));
|
variables.emplace_back(std::move(newVariable));
|
||||||
|
variableNames.emplace_back(name);
|
||||||
variableIndexing.try_emplace(std::move(name), static_cast<uint32_t>(variables.size() - 1));
|
variableIndexing.try_emplace(std::move(name), static_cast<uint32_t>(variables.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +42,19 @@ namespace SHADE
|
||||||
return variableIndexing.at(variableName);
|
return variableIndexing.at(variableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& SHShaderBlockInterface::GetVariableName(uint32_t index) const noexcept
|
||||||
|
{
|
||||||
|
if (index < variableNames.size())
|
||||||
|
return variableNames.at(index);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t SHShaderBlockInterface::GetVariableCount() const noexcept
|
||||||
|
{
|
||||||
|
return variables.size();
|
||||||
|
}
|
||||||
|
|
||||||
SHShaderBlockInterface::SHShaderBlockInterface(void) noexcept
|
SHShaderBlockInterface::SHShaderBlockInterface(void) noexcept
|
||||||
: bytesRequired{ 0 }
|
: bytesRequired{ 0 }
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -12,13 +12,24 @@ namespace SHADE
|
||||||
public:
|
public:
|
||||||
struct Variable
|
struct Variable
|
||||||
{
|
{
|
||||||
|
enum class Type
|
||||||
|
{
|
||||||
|
OTHER,
|
||||||
|
FLOAT,
|
||||||
|
INT,
|
||||||
|
VECTOR2,
|
||||||
|
VECTOR3,
|
||||||
|
VECTOR4
|
||||||
|
};
|
||||||
//! Offset of the variable in the block
|
//! Offset of the variable in the block
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
|
Type type;
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! containers of variable information
|
//! containers of variable information
|
||||||
std::vector<Variable> variables;
|
std::vector<Variable> variables;
|
||||||
|
std::vector<std::string> variableNames;
|
||||||
std::unordered_map<std::string, uint32_t> variableIndexing;
|
std::unordered_map<std::string, uint32_t> variableIndexing;
|
||||||
|
|
||||||
//! bytes required by the block (includes padding). This variable is required
|
//! bytes required by the block (includes padding). This variable is required
|
||||||
|
@ -29,6 +40,8 @@ namespace SHADE
|
||||||
Variable const* const GetVariable (std::string const& variableName) const noexcept;
|
Variable const* const GetVariable (std::string const& variableName) const noexcept;
|
||||||
Variable const* const GetVariable(uint32_t index) const noexcept;
|
Variable const* const GetVariable(uint32_t index) const noexcept;
|
||||||
uint32_t GetVariableIndex(std::string const& variableName) const;
|
uint32_t GetVariableIndex(std::string const& variableName) const;
|
||||||
|
const std::string& GetVariableName(uint32_t index) const noexcept;
|
||||||
|
size_t GetVariableCount() const noexcept;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* CTORS AND DTORS */
|
/* CTORS AND DTORS */
|
||||||
|
|
|
@ -97,17 +97,45 @@ namespace SHADE
|
||||||
switch (member.type_description->op)
|
switch (member.type_description->op)
|
||||||
{
|
{
|
||||||
case SpvOp::SpvOpTypeFloat:
|
case SpvOp::SpvOpTypeFloat:
|
||||||
interfaceHdl->AddVariable(parentVarName + std::string(member.name), SHShaderBlockInterface::Variable(parentOffset + member.offset));
|
interfaceHdl->AddVariable
|
||||||
|
(
|
||||||
|
parentVarName + std::string(member.name),
|
||||||
|
SHShaderBlockInterface::Variable
|
||||||
|
(
|
||||||
|
parentOffset + member.offset,
|
||||||
|
SHShaderBlockInterface::Variable::Type::FLOAT
|
||||||
|
)
|
||||||
|
);
|
||||||
biggestAlignment = std::max (biggestAlignment, 4u);
|
biggestAlignment = std::max (biggestAlignment, 4u);
|
||||||
break;
|
break;
|
||||||
case SpvOp::SpvOpTypeVector:
|
case SpvOp::SpvOpTypeVector:
|
||||||
interfaceHdl->AddVariable(parentVarName + std::string(member.name), SHShaderBlockInterface::Variable(parentOffset + member.offset));
|
SHShaderBlockInterface::Variable::Type varType;
|
||||||
|
switch (dim)
|
||||||
|
{
|
||||||
|
case 2: varType = SHShaderBlockInterface::Variable::Type::VECTOR2; break;
|
||||||
|
case 3: varType = SHShaderBlockInterface::Variable::Type::VECTOR3; break;
|
||||||
|
case 4: varType = SHShaderBlockInterface::Variable::Type::VECTOR4; break;
|
||||||
|
default: varType = SHShaderBlockInterface::Variable::Type::OTHER; break;
|
||||||
|
}
|
||||||
|
interfaceHdl->AddVariable
|
||||||
|
(
|
||||||
|
parentVarName + std::string(member.name),
|
||||||
|
SHShaderBlockInterface::Variable(parentOffset + member.offset, varType)
|
||||||
|
);
|
||||||
if (dim == 3)
|
if (dim == 3)
|
||||||
dim = 4;
|
dim = 4;
|
||||||
biggestAlignment = std::max (biggestAlignment, dim * member.type_description->traits.numeric.scalar.width / 8);
|
biggestAlignment = std::max (biggestAlignment, dim * member.type_description->traits.numeric.scalar.width / 8);
|
||||||
break;
|
break;
|
||||||
case SpvOp::SpvOpTypeInt:
|
case SpvOp::SpvOpTypeInt:
|
||||||
interfaceHdl->AddVariable(parentVarName + std::string(member.name), SHShaderBlockInterface::Variable(parentOffset + member.offset));
|
interfaceHdl->AddVariable
|
||||||
|
(
|
||||||
|
parentVarName + std::string(member.name),
|
||||||
|
SHShaderBlockInterface::Variable
|
||||||
|
(
|
||||||
|
parentOffset + member.offset,
|
||||||
|
SHShaderBlockInterface::Variable::Type::INT
|
||||||
|
)
|
||||||
|
);
|
||||||
biggestAlignment = std::max(biggestAlignment, 4u);
|
biggestAlignment = std::max(biggestAlignment, 4u);
|
||||||
break;
|
break;
|
||||||
case SpvOp::SpvOpTypeStruct:
|
case SpvOp::SpvOpTypeStruct:
|
||||||
|
|
Loading…
Reference in New Issue