mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
[d3d11] Add constant buffer offsets and counts to context state
This commit is contained in:
parent
a8eecfbfe5
commit
3133e4ba35
@ -60,6 +60,14 @@ namespace dxvk {
|
|||||||
return DxvkBufferSlice(m_buffer, offset, m_buffer->info().size - offset);
|
return DxvkBufferSlice(m_buffer, offset, m_buffer->info().size - offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DxvkBufferSlice GetBufferSlice(VkDeviceSize offset, VkDeviceSize length) const {
|
||||||
|
return DxvkBufferSlice(m_buffer, offset, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
VkDeviceSize GetSize() const {
|
||||||
|
return m_buffer->info().size;
|
||||||
|
}
|
||||||
|
|
||||||
D3D11BufferInfo* GetBufferInfo() {
|
D3D11BufferInfo* GetBufferInfo() {
|
||||||
return &m_bufferInfo;
|
return &m_bufferInfo;
|
||||||
}
|
}
|
||||||
|
@ -112,12 +112,12 @@ namespace dxvk {
|
|||||||
|
|
||||||
// Default constant buffers
|
// Default constant buffers
|
||||||
for (uint32_t i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; i++) {
|
for (uint32_t i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; i++) {
|
||||||
m_state.vs.constantBuffers[i] = nullptr;
|
m_state.vs.constantBuffers[i] = { nullptr, 0, 0 };
|
||||||
m_state.hs.constantBuffers[i] = nullptr;
|
m_state.hs.constantBuffers[i] = { nullptr, 0, 0 };
|
||||||
m_state.ds.constantBuffers[i] = nullptr;
|
m_state.ds.constantBuffers[i] = { nullptr, 0, 0 };
|
||||||
m_state.gs.constantBuffers[i] = nullptr;
|
m_state.gs.constantBuffers[i] = { nullptr, 0, 0 };
|
||||||
m_state.ps.constantBuffers[i] = nullptr;
|
m_state.ps.constantBuffers[i] = { nullptr, 0, 0 };
|
||||||
m_state.cs.constantBuffers[i] = nullptr;
|
m_state.cs.constantBuffers[i] = { nullptr, 0, 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default samplers
|
// Default samplers
|
||||||
@ -1144,7 +1144,8 @@ namespace dxvk {
|
|||||||
DxbcProgramType::VertexShader,
|
DxbcProgramType::VertexShader,
|
||||||
m_state.vs.constantBuffers,
|
m_state.vs.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
ppConstantBuffers);
|
ppConstantBuffers,
|
||||||
|
nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1199,7 +1200,7 @@ namespace dxvk {
|
|||||||
UINT NumBuffers,
|
UINT NumBuffers,
|
||||||
ID3D11Buffer** ppConstantBuffers) {
|
ID3D11Buffer** ppConstantBuffers) {
|
||||||
for (uint32_t i = 0; i < NumBuffers; i++)
|
for (uint32_t i = 0; i < NumBuffers; i++)
|
||||||
ppConstantBuffers[i] = m_state.vs.constantBuffers.at(StartSlot + i).ref();
|
ppConstantBuffers[i] = m_state.vs.constantBuffers.at(StartSlot + i).buffer.ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1267,7 +1268,8 @@ namespace dxvk {
|
|||||||
DxbcProgramType::HullShader,
|
DxbcProgramType::HullShader,
|
||||||
m_state.hs.constantBuffers,
|
m_state.hs.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
ppConstantBuffers);
|
ppConstantBuffers,
|
||||||
|
nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1310,7 +1312,7 @@ namespace dxvk {
|
|||||||
UINT NumBuffers,
|
UINT NumBuffers,
|
||||||
ID3D11Buffer** ppConstantBuffers) {
|
ID3D11Buffer** ppConstantBuffers) {
|
||||||
for (uint32_t i = 0; i < NumBuffers; i++)
|
for (uint32_t i = 0; i < NumBuffers; i++)
|
||||||
ppConstantBuffers[i] = m_state.hs.constantBuffers.at(StartSlot + i).ref();
|
ppConstantBuffers[i] = m_state.hs.constantBuffers.at(StartSlot + i).buffer.ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1378,7 +1380,8 @@ namespace dxvk {
|
|||||||
DxbcProgramType::DomainShader,
|
DxbcProgramType::DomainShader,
|
||||||
m_state.ds.constantBuffers,
|
m_state.ds.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
ppConstantBuffers);
|
ppConstantBuffers,
|
||||||
|
nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1421,7 +1424,7 @@ namespace dxvk {
|
|||||||
UINT NumBuffers,
|
UINT NumBuffers,
|
||||||
ID3D11Buffer** ppConstantBuffers) {
|
ID3D11Buffer** ppConstantBuffers) {
|
||||||
for (uint32_t i = 0; i < NumBuffers; i++)
|
for (uint32_t i = 0; i < NumBuffers; i++)
|
||||||
ppConstantBuffers[i] = m_state.ds.constantBuffers.at(StartSlot + i).ref();
|
ppConstantBuffers[i] = m_state.ds.constantBuffers.at(StartSlot + i).buffer.ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1477,7 +1480,8 @@ namespace dxvk {
|
|||||||
DxbcProgramType::GeometryShader,
|
DxbcProgramType::GeometryShader,
|
||||||
m_state.gs.constantBuffers,
|
m_state.gs.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
ppConstantBuffers);
|
ppConstantBuffers,
|
||||||
|
nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1532,7 +1536,7 @@ namespace dxvk {
|
|||||||
UINT NumBuffers,
|
UINT NumBuffers,
|
||||||
ID3D11Buffer** ppConstantBuffers) {
|
ID3D11Buffer** ppConstantBuffers) {
|
||||||
for (uint32_t i = 0; i < NumBuffers; i++)
|
for (uint32_t i = 0; i < NumBuffers; i++)
|
||||||
ppConstantBuffers[i] = m_state.gs.constantBuffers.at(StartSlot + i).ref();
|
ppConstantBuffers[i] = m_state.gs.constantBuffers.at(StartSlot + i).buffer.ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1588,7 +1592,8 @@ namespace dxvk {
|
|||||||
DxbcProgramType::PixelShader,
|
DxbcProgramType::PixelShader,
|
||||||
m_state.ps.constantBuffers,
|
m_state.ps.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
ppConstantBuffers);
|
ppConstantBuffers,
|
||||||
|
nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1643,7 +1648,7 @@ namespace dxvk {
|
|||||||
UINT NumBuffers,
|
UINT NumBuffers,
|
||||||
ID3D11Buffer** ppConstantBuffers) {
|
ID3D11Buffer** ppConstantBuffers) {
|
||||||
for (uint32_t i = 0; i < NumBuffers; i++)
|
for (uint32_t i = 0; i < NumBuffers; i++)
|
||||||
ppConstantBuffers[i] = m_state.ps.constantBuffers.at(StartSlot + i).ref();
|
ppConstantBuffers[i] = m_state.ps.constantBuffers.at(StartSlot + i).buffer.ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1699,7 +1704,8 @@ namespace dxvk {
|
|||||||
DxbcProgramType::ComputeShader,
|
DxbcProgramType::ComputeShader,
|
||||||
m_state.cs.constantBuffers,
|
m_state.cs.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
ppConstantBuffers);
|
ppConstantBuffers,
|
||||||
|
nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1773,7 +1779,7 @@ namespace dxvk {
|
|||||||
UINT NumBuffers,
|
UINT NumBuffers,
|
||||||
ID3D11Buffer** ppConstantBuffers) {
|
ID3D11Buffer** ppConstantBuffers) {
|
||||||
for (uint32_t i = 0; i < NumBuffers; i++)
|
for (uint32_t i = 0; i < NumBuffers; i++)
|
||||||
ppConstantBuffers[i] = m_state.cs.constantBuffers.at(StartSlot + i).ref();
|
ppConstantBuffers[i] = m_state.cs.constantBuffers.at(StartSlot + i).buffer.ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2337,10 +2343,14 @@ namespace dxvk {
|
|||||||
|
|
||||||
void D3D11DeviceContext::BindConstantBuffer(
|
void D3D11DeviceContext::BindConstantBuffer(
|
||||||
UINT Slot,
|
UINT Slot,
|
||||||
D3D11Buffer* pBuffer) {
|
const D3D11ConstantBufferBinding* pBufferBinding) {
|
||||||
EmitCs([
|
EmitCs([
|
||||||
cSlotId = Slot,
|
cSlotId = Slot,
|
||||||
cBufferSlice = pBuffer != nullptr ? pBuffer->GetBufferSlice() : DxvkBufferSlice()
|
cBufferSlice = pBufferBinding->buffer != nullptr
|
||||||
|
? pBufferBinding->buffer->GetBufferSlice(
|
||||||
|
pBufferBinding->constantOffset * 16,
|
||||||
|
pBufferBinding->constantCount * 16)
|
||||||
|
: DxvkBufferSlice()
|
||||||
] (DxvkContext* ctx) {
|
] (DxvkContext* ctx) {
|
||||||
ctx->bindResourceBuffer(cSlotId, cBufferSlice);
|
ctx->bindResourceBuffer(cSlotId, cBufferSlice);
|
||||||
});
|
});
|
||||||
@ -2394,7 +2404,9 @@ namespace dxvk {
|
|||||||
D3D11ConstantBufferBindings& Bindings,
|
D3D11ConstantBufferBindings& Bindings,
|
||||||
UINT StartSlot,
|
UINT StartSlot,
|
||||||
UINT NumBuffers,
|
UINT NumBuffers,
|
||||||
ID3D11Buffer* const* ppConstantBuffers) {
|
ID3D11Buffer* const* ppConstantBuffers,
|
||||||
|
const UINT* pFirstConstant,
|
||||||
|
const UINT* pNumConstants) {
|
||||||
const uint32_t slotId = computeResourceSlotId(
|
const uint32_t slotId = computeResourceSlotId(
|
||||||
ShaderStage, DxbcBindingType::ConstantBuffer,
|
ShaderStage, DxbcBindingType::ConstantBuffer,
|
||||||
StartSlot);
|
StartSlot);
|
||||||
@ -2402,9 +2414,22 @@ namespace dxvk {
|
|||||||
for (uint32_t i = 0; i < NumBuffers; i++) {
|
for (uint32_t i = 0; i < NumBuffers; i++) {
|
||||||
auto newBuffer = static_cast<D3D11Buffer*>(ppConstantBuffers[i]);
|
auto newBuffer = static_cast<D3D11Buffer*>(ppConstantBuffers[i]);
|
||||||
|
|
||||||
if (Bindings[StartSlot + i] != newBuffer) {
|
UINT constantOffset = 0;
|
||||||
Bindings[StartSlot + i] = newBuffer;
|
UINT constantCount = newBuffer != nullptr
|
||||||
BindConstantBuffer(slotId + i, newBuffer);
|
? newBuffer->GetSize() / 16
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
if (newBuffer != nullptr && pFirstConstant != nullptr && pNumConstants != nullptr) {
|
||||||
|
constantOffset = pFirstConstant[i];
|
||||||
|
constantCount = pNumConstants [i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Bindings[StartSlot + i].buffer != newBuffer) {
|
||||||
|
Bindings[StartSlot + i].buffer = newBuffer;
|
||||||
|
Bindings[StartSlot + i].constantOffset = constantOffset;
|
||||||
|
Bindings[StartSlot + i].constantCount = constantCount;
|
||||||
|
|
||||||
|
BindConstantBuffer(slotId + i, &Bindings[StartSlot + i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2567,7 +2592,7 @@ namespace dxvk {
|
|||||||
Stage, DxbcBindingType::ConstantBuffer, 0);
|
Stage, DxbcBindingType::ConstantBuffer, 0);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < Bindings.size(); i++)
|
for (uint32_t i = 0; i < Bindings.size(); i++)
|
||||||
BindConstantBuffer(slotId + i, Bindings[i].ptr());
|
BindConstantBuffer(slotId + i, &Bindings[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -693,7 +693,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
void BindConstantBuffer(
|
void BindConstantBuffer(
|
||||||
UINT Slot,
|
UINT Slot,
|
||||||
D3D11Buffer* pBuffer);
|
const D3D11ConstantBufferBinding* pBufferBinding);
|
||||||
|
|
||||||
void BindSampler(
|
void BindSampler(
|
||||||
UINT Slot,
|
UINT Slot,
|
||||||
@ -713,7 +713,9 @@ namespace dxvk {
|
|||||||
D3D11ConstantBufferBindings& Bindings,
|
D3D11ConstantBufferBindings& Bindings,
|
||||||
UINT StartSlot,
|
UINT StartSlot,
|
||||||
UINT NumBuffers,
|
UINT NumBuffers,
|
||||||
ID3D11Buffer* const* ppConstantBuffers);
|
ID3D11Buffer* const* ppConstantBuffers,
|
||||||
|
const UINT* pFirstConstant,
|
||||||
|
const UINT* pNumConstants);
|
||||||
|
|
||||||
void SetSamplers(
|
void SetSamplers(
|
||||||
DxbcProgramType ShaderStage,
|
DxbcProgramType ShaderStage,
|
||||||
|
@ -15,8 +15,14 @@
|
|||||||
|
|
||||||
namespace dxvk {
|
namespace dxvk {
|
||||||
|
|
||||||
|
struct D3D11ConstantBufferBinding {
|
||||||
|
Com<D3D11Buffer> buffer = nullptr;
|
||||||
|
UINT constantOffset = 0;
|
||||||
|
UINT constantCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
using D3D11ConstantBufferBindings = std::array<
|
using D3D11ConstantBufferBindings = std::array<
|
||||||
Com<D3D11Buffer>, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT>;
|
D3D11ConstantBufferBinding, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT>;
|
||||||
|
|
||||||
|
|
||||||
using D3D11SamplerBindings = std::array<
|
using D3D11SamplerBindings = std::array<
|
||||||
|
Loading…
x
Reference in New Issue
Block a user