1
0
mirror of https://github.com/EduApps-CDG/OpenDX synced 2024-12-30 09:45:37 +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,51 +4432,27 @@ 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;
info.size = m_psLayout.totalSize();
m_consts[DxsoProgramTypes::PixelShader].buffer = m_dxvkDevice->createBuffer(info, memoryFlags);
info.stages = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT;
info.size = caps::MaxClipPlanes * sizeof(D3D9ClipPlane);
m_vsClipPlanes = m_dxvkDevice->createBuffer(info, memoryFlags);
info.stages = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT;
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;
info.size = sizeof(D3D9SharedPS);
m_psShared = m_dxvkDevice->createBuffer(info, memoryFlags);
info.stages = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT;
info.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
info.access = VK_ACCESS_SHADER_READ_BIT;
info.size = CanSWVP() ? sizeof(D3D9FixedFunctionVertexBlendDataSW) : sizeof(D3D9FixedFunctionVertexBlendDataHW);
m_vsVertexBlend = m_dxvkDevice->createBuffer(info, memoryFlags);
auto BindConstantBuffer = [this](
DxsoProgramType shaderStage,
Rc<DxvkBuffer> buffer,
DxsoConstantBuffers cbuffer) {
const uint32_t slotId = computeResourceSlotId( const uint32_t slotId = computeResourceSlotId(
shaderStage, DxsoBindingType::ConstantBuffer, ShaderStage, DxsoBindingType::ConstantBuffer,
cbuffer); BufferType);
EmitCs([ EmitCs([
cSlotId = slotId, cSlotId = slotId,
@ -4485,16 +4461,55 @@ namespace dxvk {
ctx->bindResourceBuffer(cSlotId, ctx->bindResourceBuffer(cSlotId,
DxvkBufferSlice(cBuffer, 0, cBuffer->info().size)); DxvkBufferSlice(cBuffer, 0, cBuffer->info().size));
}); });
};
BindConstantBuffer(DxsoProgramTypes::VertexShader, m_consts[DxsoProgramTypes::VertexShader].buffer, DxsoConstantBuffers::VSConstantBuffer); return buffer;
BindConstantBuffer(DxsoProgramTypes::VertexShader, m_vsClipPlanes, DxsoConstantBuffers::VSClipPlanes); }
BindConstantBuffer(DxsoProgramTypes::VertexShader, m_vsFixedFunction, DxsoConstantBuffers::VSFixedFunction);
BindConstantBuffer(DxsoProgramTypes::VertexShader, m_vsVertexBlend, DxsoConstantBuffers::VSVertexBlendData);
BindConstantBuffer(DxsoProgramTypes::PixelShader, m_consts[DxsoProgramTypes::PixelShader].buffer, DxsoConstantBuffers::PSConstantBuffer);
BindConstantBuffer(DxsoProgramTypes::PixelShader, m_psFixedFunction, DxsoConstantBuffers::PSFixedFunction); void D3D9DeviceEx::CreateConstantBuffers() {
BindConstantBuffer(DxsoProgramTypes::PixelShader, m_psShared, DxsoConstantBuffers::PSShared); m_consts[DxsoProgramTypes::VertexShader].buffer =
CreateConstantBuffer(false,
m_vsLayout.totalSize(),
DxsoProgramType::VertexShader,
DxsoConstantBuffers::VSConstantBuffer);
m_consts[DxsoProgramTypes::PixelShader].buffer =
CreateConstantBuffer(false,
m_psLayout.totalSize(),
DxsoProgramType::PixelShader,
DxsoConstantBuffers::PSConstantBuffer);
m_vsClipPlanes =
CreateConstantBuffer(false,
caps::MaxClipPlanes * sizeof(D3D9ClipPlane),
DxsoProgramType::VertexShader,
DxsoConstantBuffers::VSClipPlanes);
m_vsFixedFunction =
CreateConstantBuffer(false,
sizeof(D3D9FixedFunctionVS),
DxsoProgramType::VertexShader,
DxsoConstantBuffers::VSFixedFunction);
m_psFixedFunction =
CreateConstantBuffer(false,
sizeof(D3D9FixedFunctionPS),
DxsoProgramType::PixelShader,
DxsoConstantBuffers::PSFixedFunction);
m_psShared =
CreateConstantBuffer(false,
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();