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

[dxvk] Add API for specialization constants

This commit is contained in:
Philip Rebohle 2019-05-06 00:04:47 +02:00
parent 7687db0303
commit 37f1087783
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
7 changed files with 68 additions and 1 deletions

View File

@ -2142,6 +2142,16 @@ namespace dxvk {
m_flags.set(DxvkContextFlag::GpDirtyPipelineState);
}
void DxvkContext::setSpecConstant(
uint32_t index,
uint32_t value) {
if (m_state.gp.state.scSpecConstants[index] != value) {
m_state.gp.state.scSpecConstants[index] = value;
m_flags.set(DxvkContextFlag::GpDirtyPipelineState);
}
}
void DxvkContext::setPredicate(

View File

@ -856,6 +856,19 @@ namespace dxvk {
uint32_t attachment,
const DxvkBlendMode& blendMode);
/**
* \brief Sets specialization constants
*
* Replaces current specialization constants with
* the given list of constant entries. The specId
* in the shader can be computed with \c getSpecId.
* \param [in] index Constant index
* \param [in] value Constant value
*/
void setSpecConstant(
uint32_t index,
uint32_t value);
/**
* \brief Sets predicate
*

View File

@ -205,6 +205,9 @@ namespace dxvk {
specData.set(specId + 3, util::getComponentIndex(state.omComponentMapping[i].a, 3), 3u);
}
}
for (uint32_t i = 0; i < MaxNumSpecConstants; i++)
specData.set(getSpecId(i), state.scSpecConstants[i], 0u);
VkSpecializationInfo specInfo = specData.getSpecInfo();

View File

@ -109,6 +109,8 @@ namespace dxvk {
VkLogicOp omLogicOp;
VkPipelineColorBlendAttachmentState omBlendAttachments[MaxNumRenderTargets];
VkComponentMapping omComponentMapping[MaxNumRenderTargets];
uint32_t scSpecConstants[MaxNumSpecConstants];
};

View File

@ -15,6 +15,7 @@ namespace dxvk {
MaxNumActiveBindings = 128,
MaxNumQueuedCommandBuffers = 8,
MaxNumQueryCountPerPool = 128,
MaxNumSpecConstants = 8,
MaxUniformBufferSize = 65536,
MaxVertexBindingStride = 2048,
MaxPushConstantSize = 128,

View File

@ -30,7 +30,8 @@ namespace dxvk {
// Specialization constants for pipeline state
SpecConstantRangeStart = ColorComponentMappings + MaxNumRenderTargets * 4,
RasterizerSampleCount = SpecConstantRangeStart,
RasterizerSampleCount = SpecConstantRangeStart + 0,
FirstPipelineConstant
};

View File

@ -4,6 +4,18 @@
#include "dxvk_shader.h"
namespace dxvk {
/**
* \briefS Specialization constant entry
*
* Used to pass a list of user-defined
* specialization constants to shaders.
*/
struct DxvkSpecConstant {
uint32_t specId;
uint32_t value;
};
/**
* \brief Specialization constant info
@ -36,6 +48,18 @@ namespace dxvk {
setAsUint32(specId, uint32_t(value));
}
/**
* \brief Sets specialization constant value
*
* Always passes the constant value to the driver.
* \param [in] specId Specialization constant ID
* \param [in] value Specialization constant value
*/
template<typename T>
void set(uint32_t specId, T value) {
setAsUint32(specId, uint32_t(value));
}
/**
* \brief Generates specialization info structure
* \returns Specialization info for shader module
@ -50,5 +74,18 @@ namespace dxvk {
void setAsUint32(uint32_t specId, uint32_t value);
};
/**
* \brief Computes specialization constant ID
*
* Computest the specId to use within shaders
* for a given pipeline specialization constant.
* \param [in] index Spec constant index
* \returns Specialization constant ID
*/
inline uint32_t getSpecId(uint32_t index) {
return uint32_t(DxvkSpecConstantId::FirstPipelineConstant) + index;
}
}