mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-13 19:29:14 +01:00
[dxvk] Add global specialization constant data structures
Implements a unified way of defining specialization constants for graphics and compute pipelines which can be easily extended in the future.
This commit is contained in:
parent
27816b470a
commit
4ae15f3edf
@ -11,6 +11,22 @@ namespace dxvk {
|
||||
|
||||
class DxvkShader;
|
||||
|
||||
/**
|
||||
* \brief Built-in specialization constants
|
||||
*
|
||||
* These specialization constants allow the SPIR-V
|
||||
* shaders to access some pipeline state like D3D
|
||||
* shaders do. They need to be filled in by the
|
||||
* implementation at pipeline compilation time.
|
||||
*/
|
||||
enum class DxvkSpecConstantId : uint32_t {
|
||||
RasterizerSampleCount = 0x10000,
|
||||
|
||||
SpecConstantIdMin = RasterizerSampleCount,
|
||||
SpecConstantIdMax = RasterizerSampleCount,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Shader interface slots
|
||||
*
|
||||
|
43
src/dxvk/dxvk_spec_const.cpp
Normal file
43
src/dxvk/dxvk_spec_const.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include "dxvk_spec_const.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define SET_CONSTANT_ENTRY(specId, member) \
|
||||
this->setConstantEntry(specId, \
|
||||
offsetof(DxvkSpecConstantData, member), \
|
||||
sizeof(DxvkSpecConstantData::member))
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
DxvkSpecConstantMap g_specConstantMap;
|
||||
|
||||
DxvkSpecConstantMap::DxvkSpecConstantMap() {
|
||||
SET_CONSTANT_ENTRY(DxvkSpecConstantId::RasterizerSampleCount, rasterizerSampleCount);
|
||||
|
||||
for (uint32_t i = 0; i < MaxNumActiveBindings; i++)
|
||||
this->setBindingEntry(i);
|
||||
}
|
||||
|
||||
|
||||
void DxvkSpecConstantMap::setConstantEntry(
|
||||
DxvkSpecConstantId specId,
|
||||
uint32_t offset,
|
||||
uint32_t size) {
|
||||
VkSpecializationMapEntry entry;
|
||||
entry.constantID = uint32_t(specId);
|
||||
entry.offset = offset;
|
||||
entry.size = size;
|
||||
m_mapEntries[uint32_t(specId) - uint32_t(DxvkSpecConstantId::SpecConstantIdMin)] = entry;
|
||||
}
|
||||
|
||||
|
||||
void DxvkSpecConstantMap::setBindingEntry(
|
||||
uint32_t binding) {
|
||||
VkSpecializationMapEntry entry;
|
||||
entry.constantID = binding;
|
||||
entry.offset = sizeof(VkBool32) * binding + offsetof(DxvkSpecConstantData, activeBindings);
|
||||
entry.size = sizeof(VkBool32);
|
||||
m_mapEntries[MaxNumSpecConstants + binding] = entry;
|
||||
}
|
||||
|
||||
}
|
72
src/dxvk/dxvk_spec_const.h
Normal file
72
src/dxvk/dxvk_spec_const.h
Normal file
@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include "dxvk_limits.h"
|
||||
#include "dxvk_shader.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
constexpr uint32_t MaxNumSpecConstants = 1
|
||||
+ uint32_t(DxvkSpecConstantId::SpecConstantIdMax)
|
||||
- uint32_t(DxvkSpecConstantId::SpecConstantIdMin);
|
||||
|
||||
/**
|
||||
* \brief Spec costant data
|
||||
*
|
||||
* The values are derived from the pipeline
|
||||
* state vector so that they can be used by
|
||||
* the shaders.
|
||||
*/
|
||||
struct DxvkSpecConstantData {
|
||||
uint32_t rasterizerSampleCount;
|
||||
VkBool32 activeBindings[MaxNumActiveBindings];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Spec constant map
|
||||
*
|
||||
* Stores the specialization constant map.
|
||||
* This can be passed to Vulkan when compiling
|
||||
* both graphics and compute pipelines.
|
||||
*/
|
||||
class DxvkSpecConstantMap {
|
||||
|
||||
public:
|
||||
|
||||
DxvkSpecConstantMap();
|
||||
|
||||
/**
|
||||
* \brief Map entry count
|
||||
*
|
||||
* \param [in] bindingCount Number of active bindings
|
||||
* \returns The number of map entries to read
|
||||
*/
|
||||
uint32_t mapEntryCount() const {
|
||||
return m_mapEntries.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Map entry data
|
||||
* \returns Map entries
|
||||
*/
|
||||
const VkSpecializationMapEntry* mapEntryData() const {
|
||||
return m_mapEntries.data();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::array<VkSpecializationMapEntry, MaxNumSpecConstants + MaxNumActiveBindings> m_mapEntries;
|
||||
|
||||
void setConstantEntry(
|
||||
DxvkSpecConstantId specId,
|
||||
uint32_t offset,
|
||||
uint32_t size);
|
||||
|
||||
void setBindingEntry(
|
||||
uint32_t binding);
|
||||
|
||||
};
|
||||
|
||||
extern DxvkSpecConstantMap g_specConstantMap;
|
||||
|
||||
}
|
@ -61,6 +61,7 @@ dxvk_src = files([
|
||||
'dxvk_resource.cpp',
|
||||
'dxvk_sampler.cpp',
|
||||
'dxvk_shader.cpp',
|
||||
'dxvk_spec_const.cpp',
|
||||
'dxvk_staging.cpp',
|
||||
'dxvk_stats.cpp',
|
||||
'dxvk_surface.cpp',
|
||||
|
Loading…
x
Reference in New Issue
Block a user