1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-19 05:52:11 +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

@ -2144,6 +2144,16 @@ namespace dxvk {
} }
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( void DxvkContext::setPredicate(
const DxvkBufferSlice& predicate, const DxvkBufferSlice& predicate,
VkConditionalRenderingFlagsEXT flags) { VkConditionalRenderingFlagsEXT flags) {

View File

@ -856,6 +856,19 @@ namespace dxvk {
uint32_t attachment, uint32_t attachment,
const DxvkBlendMode& blendMode); 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 * \brief Sets predicate
* *

View File

@ -206,6 +206,9 @@ namespace dxvk {
} }
} }
for (uint32_t i = 0; i < MaxNumSpecConstants; i++)
specData.set(getSpecId(i), state.scSpecConstants[i], 0u);
VkSpecializationInfo specInfo = specData.getSpecInfo(); VkSpecializationInfo specInfo = specData.getSpecInfo();
DxvkShaderModuleCreateInfo moduleInfo; DxvkShaderModuleCreateInfo moduleInfo;

View File

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

View File

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

View File

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

View File

@ -5,6 +5,18 @@
namespace dxvk { 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 * \brief Specialization constant info
* *
@ -36,6 +48,18 @@ namespace dxvk {
setAsUint32(specId, uint32_t(value)); 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 * \brief Generates specialization info structure
* \returns Specialization info for shader module * \returns Specialization info for shader module
@ -51,4 +75,17 @@ namespace dxvk {
}; };
/**
* \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;
}
} }