1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-19 05:52:11 +01:00

[d3d9] Refactor constant buffer creation

This commit is contained in:
Joshua Ashton 2020-02-18 17:32:25 +00:00 committed by Philip Rebohle
parent f688889b41
commit 512393e469
2 changed files with 70 additions and 49 deletions

View File

@ -4432,69 +4432,84 @@ namespace dxvk {
} }
void D3D9DeviceEx::CreateConstantBuffers() { Rc<DxvkBuffer> D3D9DeviceEx::CreateConstantBuffer(
DxvkBufferCreateInfo info; bool SSBO,
info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; VkDeviceSize Size,
info.access = VK_ACCESS_UNIFORM_READ_BIT; DxsoProgramType ShaderStage,
DxsoConstantBuffers BufferType) {
DxvkBufferCreateInfo info = { };
info.usage = SSBO ? VK_BUFFER_USAGE_STORAGE_BUFFER_BIT : VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
info.access = SSBO ? VK_ACCESS_SHADER_READ_BIT : VK_ACCESS_UNIFORM_READ_BIT;
info.size = Size;
info.stages = ShaderStage == DxsoProgramType::VertexShader
? VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
: VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
VkMemoryPropertyFlags memoryFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT VkMemoryPropertyFlags memoryFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
| VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
info.stages = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT; Rc<DxvkBuffer> buffer = m_dxvkDevice->createBuffer(info, memoryFlags);
info.size = m_vsLayout.totalSize();
m_consts[DxsoProgramTypes::VertexShader].buffer = m_dxvkDevice->createBuffer(info, memoryFlags);
info.stages = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; const uint32_t slotId = computeResourceSlotId(
info.size = m_psLayout.totalSize(); ShaderStage, DxsoBindingType::ConstantBuffer,
m_consts[DxsoProgramTypes::PixelShader].buffer = m_dxvkDevice->createBuffer(info, memoryFlags); BufferType);
info.stages = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT; EmitCs([
info.size = caps::MaxClipPlanes * sizeof(D3D9ClipPlane); cSlotId = slotId,
m_vsClipPlanes = m_dxvkDevice->createBuffer(info, memoryFlags); cBuffer = buffer
] (DxvkContext* ctx) {
ctx->bindResourceBuffer(cSlotId,
DxvkBufferSlice(cBuffer, 0, cBuffer->info().size));
});
info.stages = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT; return buffer;
info.size = sizeof(D3D9FixedFunctionVS); }
m_vsFixedFunction = m_dxvkDevice->createBuffer(info, memoryFlags);
info.stages = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
info.size = sizeof(D3D9FixedFunctionPS);
m_psFixedFunction = m_dxvkDevice->createBuffer(info, memoryFlags);
info.stages = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; void D3D9DeviceEx::CreateConstantBuffers() {
info.size = sizeof(D3D9SharedPS); m_consts[DxsoProgramTypes::VertexShader].buffer =
m_psShared = m_dxvkDevice->createBuffer(info, memoryFlags); CreateConstantBuffer(false,
m_vsLayout.totalSize(),
DxsoProgramType::VertexShader,
DxsoConstantBuffers::VSConstantBuffer);
info.stages = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT; m_consts[DxsoProgramTypes::PixelShader].buffer =
info.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; CreateConstantBuffer(false,
info.access = VK_ACCESS_SHADER_READ_BIT; m_psLayout.totalSize(),
info.size = CanSWVP() ? sizeof(D3D9FixedFunctionVertexBlendDataSW) : sizeof(D3D9FixedFunctionVertexBlendDataHW); DxsoProgramType::PixelShader,
m_vsVertexBlend = m_dxvkDevice->createBuffer(info, memoryFlags); DxsoConstantBuffers::PSConstantBuffer);
auto BindConstantBuffer = [this]( m_vsClipPlanes =
DxsoProgramType shaderStage, CreateConstantBuffer(false,
Rc<DxvkBuffer> buffer, caps::MaxClipPlanes * sizeof(D3D9ClipPlane),
DxsoConstantBuffers cbuffer) { DxsoProgramType::VertexShader,
const uint32_t slotId = computeResourceSlotId( DxsoConstantBuffers::VSClipPlanes);
shaderStage, DxsoBindingType::ConstantBuffer,
cbuffer);
EmitCs([ m_vsFixedFunction =
cSlotId = slotId, CreateConstantBuffer(false,
cBuffer = buffer sizeof(D3D9FixedFunctionVS),
] (DxvkContext* ctx) { DxsoProgramType::VertexShader,
ctx->bindResourceBuffer(cSlotId, DxsoConstantBuffers::VSFixedFunction);
DxvkBufferSlice(cBuffer, 0, cBuffer->info().size));
});
};
BindConstantBuffer(DxsoProgramTypes::VertexShader, m_consts[DxsoProgramTypes::VertexShader].buffer, DxsoConstantBuffers::VSConstantBuffer); m_psFixedFunction =
BindConstantBuffer(DxsoProgramTypes::VertexShader, m_vsClipPlanes, DxsoConstantBuffers::VSClipPlanes); CreateConstantBuffer(false,
BindConstantBuffer(DxsoProgramTypes::VertexShader, m_vsFixedFunction, DxsoConstantBuffers::VSFixedFunction); sizeof(D3D9FixedFunctionPS),
BindConstantBuffer(DxsoProgramTypes::VertexShader, m_vsVertexBlend, DxsoConstantBuffers::VSVertexBlendData); DxsoProgramType::PixelShader,
DxsoConstantBuffers::PSFixedFunction);
BindConstantBuffer(DxsoProgramTypes::PixelShader, m_consts[DxsoProgramTypes::PixelShader].buffer, DxsoConstantBuffers::PSConstantBuffer); m_psShared =
BindConstantBuffer(DxsoProgramTypes::PixelShader, m_psFixedFunction, DxsoConstantBuffers::PSFixedFunction); CreateConstantBuffer(false,
BindConstantBuffer(DxsoProgramTypes::PixelShader, m_psShared, DxsoConstantBuffers::PSShared); sizeof(D3D9SharedPS),
DxsoProgramType::PixelShader,
DxsoConstantBuffers::PSShared);
m_vsVertexBlend =
CreateConstantBuffer(true,
CanSWVP()
? sizeof(D3D9FixedFunctionVertexBlendDataSW)
: sizeof(D3D9FixedFunctionVertexBlendDataHW),
DxsoProgramType::VertexShader,
DxsoConstantBuffers::VSVertexBlendData);
m_flags.set( m_flags.set(
D3D9DeviceFlag::DirtyClipPlanes); D3D9DeviceFlag::DirtyClipPlanes);

View File

@ -728,6 +728,12 @@ namespace dxvk {
int64_t DetermineInitialTextureMemory(); int64_t DetermineInitialTextureMemory();
Rc<DxvkBuffer> CreateConstantBuffer(
bool SSBO,
VkDeviceSize Size,
DxsoProgramType ShaderStage,
DxsoConstantBuffers BufferType);
void CreateConstantBuffers(); void CreateConstantBuffers();
void SynchronizeCsThread(); void SynchronizeCsThread();