d3d12: Use constant buffer content

This commit is contained in:
vlj 2015-05-13 17:20:43 +02:00 committed by Vincent Lejeune
parent d627f9cb83
commit 411265d83a
2 changed files with 17 additions and 6 deletions

View file

@ -345,24 +345,28 @@ void D3D12GSRender::FillVertexShaderConstantsBuffer()
memcpy((char*)constantsBufferMap + m_constantsBufferOffset + currentoffset, scaleOffsetMat, 16 * sizeof(float));
currentoffset += 16 * sizeof(float);
size_t bufferSize = currentoffset;
for (const RSXTransformConstant& c : m_transform_constants)
{
size_t offset = c.id * 4 * sizeof(float) + currentoffset;
float vector[] = { c.x, c.y, c.z, c.w };
memcpy((char*)constantsBufferMap + m_constantsBufferOffset + currentoffset, vector, 4 * sizeof(float));
currentoffset += 4 * sizeof(float);
memcpy((char*)constantsBufferMap + m_constantsBufferOffset + offset, vector, 4 * sizeof(float));
size_t bufferSizeCandidate = offset + 4 * sizeof(float);
bufferSize = bufferSizeCandidate > bufferSize ? bufferSizeCandidate : bufferSize;
}
m_constantsBuffer->Unmap(0, &range);
// Align to 256 byte
currentoffset = (currentoffset + 255) & ~255;
bufferSize = (bufferSize + 255) & ~255;
D3D12_CONSTANT_BUFFER_VIEW_DESC constantBufferViewDesc = {};
constantBufferViewDesc.BufferLocation = m_constantsBuffer->GetGPUVirtualAddress() + m_constantsBufferOffset;
constantBufferViewDesc.SizeInBytes = (UINT)currentoffset;
constantBufferViewDesc.SizeInBytes = (UINT)bufferSize;
D3D12_CPU_DESCRIPTOR_HANDLE Handle = m_constantsBufferDescriptorsHeap->GetCPUDescriptorHandleForHeapStart();
Handle.ptr += m_constantsBufferIndex * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
m_device->CreateConstantBufferView(&constantBufferViewDesc, Handle);
m_constantsBufferOffset += currentoffset;
m_constantsBufferOffset += bufferSize;
}
void D3D12GSRender::FillPixelShaderConstantsBuffer()

View file

@ -256,6 +256,7 @@ void Shader::Compile(SHADER_TYPE st)
cbuffer CONSTANT : register(b0)
{
float4x4 scaleOffsetMat;
float4 vc[468];
};
struct vertex {
@ -271,7 +272,13 @@ void Shader::Compile(SHADER_TYPE st)
pixel main(vertex In)
{
pixel Out;
Out.pos = mul(float4(In.pos.x, In.pos.y, 0., 1.), scaleOffsetMat);
float4 pos = In.pos;
pos.w = dot(pos, vc[259]);
pos.z = dot(pos, vc[258]);
pos.y = dot(pos, vc[257]);
pos.x = dot(pos, vc[256]);
pos.z = 0;
Out.pos = mul(pos, scaleOffsetMat);
Out.color = In.color;
return Out;
});