1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-02 01:24:11 +01:00

[dxvk] Add spec constants for pixel shader output mapping

This commit is contained in:
Philip Rebohle 2018-09-01 17:53:45 +02:00
parent 37a8743dbc
commit cb274e040d
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
6 changed files with 63 additions and 5 deletions

View File

@ -237,6 +237,11 @@ namespace dxvk {
omBlendAttachments[i].colorWriteMask = util::remapComponentMask(
state.omBlendAttachments[i].colorWriteMask,
state.omComponentMapping[i]);
specData.outputMappings[4 * i + 0] = util::getComponentIndex(state.omComponentMapping[i].r, 0);
specData.outputMappings[4 * i + 1] = util::getComponentIndex(state.omComponentMapping[i].g, 1);
specData.outputMappings[4 * i + 2] = util::getComponentIndex(state.omComponentMapping[i].b, 2);
specData.outputMappings[4 * i + 3] = util::getComponentIndex(state.omComponentMapping[i].a, 3);
}
// Generate per-instance attribute divisors

View File

@ -22,6 +22,11 @@ namespace dxvk {
enum class DxvkSpecConstantId : uint32_t {
RasterizerSampleCount = 0x10000,
/// Special constant ranges that do not count
/// towards the spec constant min/max values
ColorComponentMappings = 0x20000,
/// Lowest and highest known spec constant IDs
SpecConstantIdMin = RasterizerSampleCount,
SpecConstantIdMax = RasterizerSampleCount,
};

View File

@ -14,6 +14,9 @@ namespace dxvk {
for (uint32_t i = 0; i < MaxNumActiveBindings; i++)
this->setBindingEntry(i);
for (uint32_t i = 0; i < MaxNumRenderTargets; i++)
this->setOutputMappingEntry(i);
}
@ -38,4 +41,18 @@ namespace dxvk {
m_mapEntries[MaxNumSpecConstants + binding] = entry;
}
void DxvkSpecConstantMap::setOutputMappingEntry(
uint32_t output) {
for (uint32_t i = 0; i < 4; i++) {
uint32_t constId = 4 * output + i;
VkSpecializationMapEntry entry;
entry.constantID = uint32_t(DxvkSpecConstantId::ColorComponentMappings) + constId;
entry.offset = sizeof(uint32_t) * constId + offsetof(DxvkSpecConstantData, outputMappings);
entry.size = sizeof(uint32_t);
m_mapEntries[MaxNumSpecConstants + MaxNumActiveBindings + constId] = entry;
}
}
}

View File

@ -18,6 +18,7 @@ namespace dxvk {
*/
struct DxvkSpecConstantData {
uint32_t rasterizerSampleCount;
uint32_t outputMappings[MaxNumRenderTargets * 4];
VkBool32 activeBindings[MaxNumActiveBindings];
};
@ -55,7 +56,10 @@ namespace dxvk {
private:
std::array<VkSpecializationMapEntry, MaxNumSpecConstants + MaxNumActiveBindings> m_mapEntries;
std::array<VkSpecializationMapEntry,
MaxNumSpecConstants +
MaxNumActiveBindings +
MaxNumRenderTargets * 4> m_mapEntries;
void setConstantEntry(
DxvkSpecConstantId specId,
@ -65,6 +69,9 @@ namespace dxvk {
void setBindingEntry(
uint32_t binding);
void setOutputMappingEntry(
uint32_t output);
};
extern DxvkSpecConstantMap g_specConstantMap;

View File

@ -136,4 +136,17 @@ namespace dxvk::util {
return result;
}
uint32_t getComponentIndex(
VkComponentSwizzle component,
uint32_t identity) {
switch (component) {
case VK_COMPONENT_SWIZZLE_R: return 0;
case VK_COMPONENT_SWIZZLE_G: return 1;
case VK_COMPONENT_SWIZZLE_B: return 2;
case VK_COMPONENT_SWIZZLE_A: return 3;
default: return identity; /* identity, zero, one */
}
}
}

View File

@ -201,6 +201,17 @@ namespace dxvk::util {
VkComponentMapping invertComponentMapping(
VkComponentMapping mapping);
/**
* \brief Computes component index for a component swizzle
*
* \param [in] component The component swizzle
* \param [in] identity Value for SWIZZLE_IDENTITY
* \returns Component index
*/
uint32_t getComponentIndex(
VkComponentSwizzle component,
uint32_t identity);
}