1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-18 20:52:10 +01:00

[dxvk] Add new structure to generate specialization constant info

We should avoid passing redundant and unused data to the driver, as
that may interfere with caching. It also adds a lot of unnecessary
data to traces.
This commit is contained in:
Philip Rebohle 2019-05-01 00:32:50 +02:00
parent 0a77ebbeaf
commit 433c707888
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 80 additions and 0 deletions

View File

@ -56,5 +56,39 @@ namespace dxvk {
m_mapEntries[MaxNumSpecConstants + MaxNumActiveBindings + constId] = entry;
}
}
DxvkSpecConstants::DxvkSpecConstants() {
}
DxvkSpecConstants::~DxvkSpecConstants() {
}
VkSpecializationInfo DxvkSpecConstants::getSpecInfo() const {
VkSpecializationInfo specInfo;
specInfo.mapEntryCount = m_map.size();
specInfo.pMapEntries = m_map.data();
specInfo.dataSize = m_data.size() * sizeof(uint32_t);
specInfo.pData = m_data.data();
return specInfo;
}
void DxvkSpecConstants::setAsUint32(uint32_t specId, uint32_t value) {
uint32_t index = m_data.size();
m_data.push_back(value);
VkSpecializationMapEntry mapEntry;
mapEntry.constantID = specId;
mapEntry.offset = sizeof(uint32_t) * index;
mapEntry.size = sizeof(uint32_t);
m_map.push_back(mapEntry);
}
}

View File

@ -77,5 +77,51 @@ namespace dxvk {
};
extern DxvkSpecConstantMap g_specConstantMap;
/**
* \brief Specialization constant info
*
* Accumulates specialization constant data for
* constants that use non-default values.
*/
class DxvkSpecConstants {
public:
DxvkSpecConstants();
~DxvkSpecConstants();
/**
* \brief Sets specialization constant value
*
* If the given value is different from the constant's
* default value, this will store the new value and add
* a map entry so that it gets applied properly. Each
* constant may only be set once.
* \param [in] specId Specialization constant ID
* \param [in] value Specialization constant value
* \param [in] defaultValue Default value
*/
template<typename T>
void set(uint32_t specId, T value, T defaultValue) {
if (value != defaultValue)
setAsUint32(specId, uint32_t(value));
}
/**
* \brief Generates specialization info structure
* \returns Specialization info for shader module
*/
VkSpecializationInfo getSpecInfo() const;
private:
std::vector<uint32_t> m_data = { };
std::vector<VkSpecializationMapEntry> m_map = { };
void setAsUint32(uint32_t specId, uint32_t value);
};
}