mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-13 16:08:50 +01:00
[d3d11] Move ClearState and RestoreState to D3D11CommonContext
This commit is contained in:
parent
f664e87749
commit
1ef9d5389b
@ -104,122 +104,6 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
void STDMETHODCALLTYPE D3D11DeviceContext::ClearState() {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
// Default shaders
|
||||
m_state.vs.shader = nullptr;
|
||||
m_state.hs.shader = nullptr;
|
||||
m_state.ds.shader = nullptr;
|
||||
m_state.gs.shader = nullptr;
|
||||
m_state.ps.shader = nullptr;
|
||||
m_state.cs.shader = nullptr;
|
||||
|
||||
// Default constant buffers
|
||||
for (uint32_t i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; i++) {
|
||||
m_state.vs.constantBuffers[i] = { nullptr, 0, 0 };
|
||||
m_state.hs.constantBuffers[i] = { nullptr, 0, 0 };
|
||||
m_state.ds.constantBuffers[i] = { nullptr, 0, 0 };
|
||||
m_state.gs.constantBuffers[i] = { nullptr, 0, 0 };
|
||||
m_state.ps.constantBuffers[i] = { nullptr, 0, 0 };
|
||||
m_state.cs.constantBuffers[i] = { nullptr, 0, 0 };
|
||||
}
|
||||
|
||||
// Default samplers
|
||||
for (uint32_t i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; i++) {
|
||||
m_state.vs.samplers[i] = nullptr;
|
||||
m_state.hs.samplers[i] = nullptr;
|
||||
m_state.ds.samplers[i] = nullptr;
|
||||
m_state.gs.samplers[i] = nullptr;
|
||||
m_state.ps.samplers[i] = nullptr;
|
||||
m_state.cs.samplers[i] = nullptr;
|
||||
}
|
||||
|
||||
// Default shader resources
|
||||
for (uint32_t i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; i++) {
|
||||
m_state.vs.shaderResources.views[i] = nullptr;
|
||||
m_state.hs.shaderResources.views[i] = nullptr;
|
||||
m_state.ds.shaderResources.views[i] = nullptr;
|
||||
m_state.gs.shaderResources.views[i] = nullptr;
|
||||
m_state.ps.shaderResources.views[i] = nullptr;
|
||||
m_state.cs.shaderResources.views[i] = nullptr;
|
||||
}
|
||||
|
||||
m_state.vs.shaderResources.hazardous.clear();
|
||||
m_state.hs.shaderResources.hazardous.clear();
|
||||
m_state.ds.shaderResources.hazardous.clear();
|
||||
m_state.gs.shaderResources.hazardous.clear();
|
||||
m_state.ps.shaderResources.hazardous.clear();
|
||||
m_state.cs.shaderResources.hazardous.clear();
|
||||
|
||||
// Default UAVs
|
||||
for (uint32_t i = 0; i < D3D11_1_UAV_SLOT_COUNT; i++) {
|
||||
m_state.ps.unorderedAccessViews[i] = nullptr;
|
||||
m_state.cs.unorderedAccessViews[i] = nullptr;
|
||||
}
|
||||
|
||||
m_state.cs.uavMask.clear();
|
||||
|
||||
// Default ID state
|
||||
m_state.id.argBuffer = nullptr;
|
||||
|
||||
// Default IA state
|
||||
m_state.ia.inputLayout = nullptr;
|
||||
m_state.ia.primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
|
||||
|
||||
for (uint32_t i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; i++) {
|
||||
m_state.ia.vertexBuffers[i].buffer = nullptr;
|
||||
m_state.ia.vertexBuffers[i].offset = 0;
|
||||
m_state.ia.vertexBuffers[i].stride = 0;
|
||||
}
|
||||
|
||||
m_state.ia.indexBuffer.buffer = nullptr;
|
||||
m_state.ia.indexBuffer.offset = 0;
|
||||
m_state.ia.indexBuffer.format = DXGI_FORMAT_UNKNOWN;
|
||||
|
||||
// Default OM State
|
||||
for (uint32_t i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
|
||||
m_state.om.renderTargetViews[i] = nullptr;
|
||||
m_state.om.depthStencilView = nullptr;
|
||||
|
||||
m_state.om.cbState = nullptr;
|
||||
m_state.om.dsState = nullptr;
|
||||
|
||||
for (uint32_t i = 0; i < 4; i++)
|
||||
m_state.om.blendFactor[i] = 1.0f;
|
||||
|
||||
m_state.om.sampleCount = 0;
|
||||
m_state.om.sampleMask = D3D11_DEFAULT_SAMPLE_MASK;
|
||||
m_state.om.stencilRef = D3D11_DEFAULT_STENCIL_REFERENCE;
|
||||
|
||||
m_state.om.maxRtv = 0;
|
||||
m_state.om.maxUav = 0;
|
||||
|
||||
// Default RS state
|
||||
m_state.rs.state = nullptr;
|
||||
m_state.rs.numViewports = 0;
|
||||
m_state.rs.numScissors = 0;
|
||||
|
||||
for (uint32_t i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; i++) {
|
||||
m_state.rs.viewports[i] = D3D11_VIEWPORT { };
|
||||
m_state.rs.scissors [i] = D3D11_RECT { };
|
||||
}
|
||||
|
||||
// Default SO state
|
||||
for (uint32_t i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; i++) {
|
||||
m_state.so.targets[i].buffer = nullptr;
|
||||
m_state.so.targets[i].offset = 0;
|
||||
}
|
||||
|
||||
// Default predication
|
||||
m_state.pr.predicateObject = nullptr;
|
||||
m_state.pr.predicateValue = FALSE;
|
||||
|
||||
// Make sure to apply all state
|
||||
ResetState();
|
||||
}
|
||||
|
||||
|
||||
void STDMETHODCALLTYPE D3D11DeviceContext::SetPredication(
|
||||
ID3D11Predicate* pPredicate,
|
||||
BOOL PredicateValue) {
|
||||
@ -2580,223 +2464,6 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
void D3D11DeviceContext::ResetState() {
|
||||
EmitCs([] (DxvkContext* ctx) {
|
||||
// Reset render targets
|
||||
ctx->bindRenderTargets(DxvkRenderTargets());
|
||||
|
||||
// Reset vertex input state
|
||||
ctx->setInputLayout(0, nullptr, 0, nullptr);
|
||||
|
||||
// Reset render states
|
||||
DxvkInputAssemblyState iaState;
|
||||
InitDefaultPrimitiveTopology(&iaState);
|
||||
|
||||
DxvkDepthStencilState dsState;
|
||||
InitDefaultDepthStencilState(&dsState);
|
||||
|
||||
DxvkRasterizerState rsState;
|
||||
InitDefaultRasterizerState(&rsState);
|
||||
|
||||
DxvkBlendMode cbState;
|
||||
DxvkLogicOpState loState;
|
||||
DxvkMultisampleState msState;
|
||||
InitDefaultBlendState(&cbState, &loState, &msState, D3D11_DEFAULT_SAMPLE_MASK);
|
||||
|
||||
ctx->setInputAssemblyState(iaState);
|
||||
ctx->setDepthStencilState(dsState);
|
||||
ctx->setRasterizerState(rsState);
|
||||
ctx->setLogicOpState(loState);
|
||||
ctx->setMultisampleState(msState);
|
||||
|
||||
for (uint32_t i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
|
||||
ctx->setBlendMode(i, cbState);
|
||||
|
||||
// Reset dynamic states
|
||||
ctx->setBlendConstants(DxvkBlendConstants { 1.0f, 1.0f, 1.0f, 1.0f });
|
||||
ctx->setStencilReference(D3D11_DEFAULT_STENCIL_REFERENCE);
|
||||
|
||||
// Reset viewports
|
||||
auto viewport = VkViewport();
|
||||
auto scissor = VkRect2D();
|
||||
|
||||
ctx->setViewports(1, &viewport, &scissor);
|
||||
|
||||
// Unbind indirect draw buffer
|
||||
ctx->bindDrawBuffers(DxvkBufferSlice(), DxvkBufferSlice());
|
||||
|
||||
// Unbind index and vertex buffers
|
||||
ctx->bindIndexBuffer(DxvkBufferSlice(), VK_INDEX_TYPE_UINT32);
|
||||
|
||||
for (uint32_t i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; i++)
|
||||
ctx->bindVertexBuffer(i, DxvkBufferSlice(), 0);
|
||||
|
||||
// Unbind transform feedback buffers
|
||||
for (uint32_t i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; i++)
|
||||
ctx->bindXfbBuffer(i, DxvkBufferSlice(), DxvkBufferSlice());
|
||||
|
||||
// Unbind per-shader stage resources
|
||||
for (uint32_t i = 0; i < 6; i++) {
|
||||
auto programType = DxbcProgramType(i);
|
||||
auto stage = GetShaderStage(programType);
|
||||
|
||||
ctx->bindShader(stage, nullptr);
|
||||
|
||||
// Unbind constant buffers, including the shader's ICB
|
||||
auto cbSlotId = computeConstantBufferBinding(programType, 0);
|
||||
|
||||
for (uint32_t j = 0; j <= D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; j++)
|
||||
ctx->bindResourceBuffer(stage, cbSlotId + j, DxvkBufferSlice());
|
||||
|
||||
// Unbind shader resource views
|
||||
auto srvSlotId = computeSrvBinding(programType, 0);
|
||||
|
||||
for (uint32_t j = 0; j < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; j++)
|
||||
ctx->bindResourceView(stage, srvSlotId + j, nullptr, nullptr);
|
||||
|
||||
// Unbind texture samplers
|
||||
auto samplerSlotId = computeSamplerBinding(programType, 0);
|
||||
|
||||
for (uint32_t j = 0; j < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; j++)
|
||||
ctx->bindResourceSampler(stage, samplerSlotId + j, nullptr);
|
||||
|
||||
// Unbind UAVs for supported stages
|
||||
if (programType == DxbcProgramType::PixelShader
|
||||
|| programType == DxbcProgramType::ComputeShader) {
|
||||
VkShaderStageFlags stages = programType == DxbcProgramType::PixelShader
|
||||
? VK_SHADER_STAGE_ALL_GRAPHICS
|
||||
: VK_SHADER_STAGE_COMPUTE_BIT;
|
||||
|
||||
auto uavSlotId = computeUavBinding(programType, 0);
|
||||
auto ctrSlotId = computeUavCounterBinding(programType, 0);
|
||||
|
||||
for (uint32_t j = 0; j < D3D11_1_UAV_SLOT_COUNT; j++) {
|
||||
ctx->bindResourceView (stages, uavSlotId, nullptr, nullptr);
|
||||
ctx->bindResourceBuffer (stages, ctrSlotId, DxvkBufferSlice());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize push constants
|
||||
DxbcPushConstants pc;
|
||||
pc.rasterizerSampleCount = 1;
|
||||
ctx->pushConstants(0, sizeof(pc), &pc);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void D3D11DeviceContext::RestoreState() {
|
||||
BindFramebuffer();
|
||||
|
||||
BindShader<DxbcProgramType::VertexShader> (GetCommonShader(m_state.vs.shader.ptr()));
|
||||
BindShader<DxbcProgramType::HullShader> (GetCommonShader(m_state.hs.shader.ptr()));
|
||||
BindShader<DxbcProgramType::DomainShader> (GetCommonShader(m_state.ds.shader.ptr()));
|
||||
BindShader<DxbcProgramType::GeometryShader> (GetCommonShader(m_state.gs.shader.ptr()));
|
||||
BindShader<DxbcProgramType::PixelShader> (GetCommonShader(m_state.ps.shader.ptr()));
|
||||
BindShader<DxbcProgramType::ComputeShader> (GetCommonShader(m_state.cs.shader.ptr()));
|
||||
|
||||
ApplyInputLayout();
|
||||
ApplyPrimitiveTopology();
|
||||
ApplyBlendState();
|
||||
ApplyBlendFactor();
|
||||
ApplyDepthStencilState();
|
||||
ApplyStencilRef();
|
||||
ApplyRasterizerState();
|
||||
ApplyRasterizerSampleCount();
|
||||
ApplyViewportState();
|
||||
|
||||
BindDrawBuffers(
|
||||
m_state.id.argBuffer.ptr(),
|
||||
m_state.id.cntBuffer.ptr());
|
||||
|
||||
BindIndexBuffer(
|
||||
m_state.ia.indexBuffer.buffer.ptr(),
|
||||
m_state.ia.indexBuffer.offset,
|
||||
m_state.ia.indexBuffer.format);
|
||||
|
||||
for (uint32_t i = 0; i < m_state.ia.vertexBuffers.size(); i++) {
|
||||
BindVertexBuffer(i,
|
||||
m_state.ia.vertexBuffers[i].buffer.ptr(),
|
||||
m_state.ia.vertexBuffers[i].offset,
|
||||
m_state.ia.vertexBuffers[i].stride);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < m_state.so.targets.size(); i++)
|
||||
BindXfbBuffer(i, m_state.so.targets[i].buffer.ptr(), ~0u);
|
||||
|
||||
RestoreConstantBuffers<DxbcProgramType::VertexShader> (m_state.vs.constantBuffers);
|
||||
RestoreConstantBuffers<DxbcProgramType::HullShader> (m_state.hs.constantBuffers);
|
||||
RestoreConstantBuffers<DxbcProgramType::DomainShader> (m_state.ds.constantBuffers);
|
||||
RestoreConstantBuffers<DxbcProgramType::GeometryShader> (m_state.gs.constantBuffers);
|
||||
RestoreConstantBuffers<DxbcProgramType::PixelShader> (m_state.ps.constantBuffers);
|
||||
RestoreConstantBuffers<DxbcProgramType::ComputeShader> (m_state.cs.constantBuffers);
|
||||
|
||||
RestoreSamplers<DxbcProgramType::VertexShader> (m_state.vs.samplers);
|
||||
RestoreSamplers<DxbcProgramType::HullShader> (m_state.hs.samplers);
|
||||
RestoreSamplers<DxbcProgramType::DomainShader> (m_state.ds.samplers);
|
||||
RestoreSamplers<DxbcProgramType::GeometryShader>(m_state.gs.samplers);
|
||||
RestoreSamplers<DxbcProgramType::PixelShader> (m_state.ps.samplers);
|
||||
RestoreSamplers<DxbcProgramType::ComputeShader> (m_state.cs.samplers);
|
||||
|
||||
RestoreShaderResources<DxbcProgramType::VertexShader> (m_state.vs.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::HullShader> (m_state.hs.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::DomainShader> (m_state.ds.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::GeometryShader> (m_state.gs.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::PixelShader> (m_state.ps.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::ComputeShader> (m_state.cs.shaderResources);
|
||||
|
||||
RestoreUnorderedAccessViews<DxbcProgramType::PixelShader> (m_state.ps.unorderedAccessViews);
|
||||
RestoreUnorderedAccessViews<DxbcProgramType::ComputeShader> (m_state.cs.unorderedAccessViews);
|
||||
}
|
||||
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void D3D11DeviceContext::RestoreConstantBuffers(
|
||||
D3D11ConstantBufferBindings& Bindings) {
|
||||
uint32_t slotId = computeConstantBufferBinding(Stage, 0);
|
||||
|
||||
for (uint32_t i = 0; i < Bindings.size(); i++) {
|
||||
BindConstantBuffer<Stage>(slotId + i, Bindings[i].buffer.ptr(),
|
||||
Bindings[i].constantOffset, Bindings[i].constantBound);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void D3D11DeviceContext::RestoreSamplers(
|
||||
D3D11SamplerBindings& Bindings) {
|
||||
uint32_t slotId = computeSamplerBinding(Stage, 0);
|
||||
|
||||
for (uint32_t i = 0; i < Bindings.size(); i++)
|
||||
BindSampler<Stage>(slotId + i, Bindings[i]);
|
||||
}
|
||||
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void D3D11DeviceContext::RestoreShaderResources(
|
||||
D3D11ShaderResourceBindings& Bindings) {
|
||||
uint32_t slotId = computeSrvBinding(Stage, 0);
|
||||
|
||||
for (uint32_t i = 0; i < Bindings.views.size(); i++)
|
||||
BindShaderResource<Stage>(slotId + i, Bindings.views[i].ptr());
|
||||
}
|
||||
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void D3D11DeviceContext::RestoreUnorderedAccessViews(
|
||||
D3D11UnorderedAccessBindings& Bindings) {
|
||||
uint32_t uavSlotId = computeUavBinding (Stage, 0);
|
||||
uint32_t ctrSlotId = computeUavCounterBinding(Stage, 0);
|
||||
|
||||
for (uint32_t i = 0; i < Bindings.size(); i++) {
|
||||
BindUnorderedAccessView<Stage>(
|
||||
uavSlotId + i,
|
||||
Bindings[i].ptr(),
|
||||
ctrSlotId + i, ~0u);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool D3D11DeviceContext::TestRtvUavHazards(
|
||||
UINT NumRTVs,
|
||||
ID3D11RenderTargetView* const* ppRTVs,
|
||||
|
@ -43,8 +43,6 @@ namespace dxvk {
|
||||
const D3D11_RECT* pRects,
|
||||
UINT NumRects);
|
||||
|
||||
void STDMETHODCALLTYPE ClearState();
|
||||
|
||||
void STDMETHODCALLTYPE SetPredication(
|
||||
ID3D11Predicate* pPredicate,
|
||||
BOOL PredicateValue);
|
||||
@ -407,26 +405,6 @@ namespace dxvk {
|
||||
ID3D11Buffer* pBufferForArgs,
|
||||
ID3D11Buffer* pBufferForCount);
|
||||
|
||||
void ResetState();
|
||||
|
||||
void RestoreState();
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void RestoreConstantBuffers(
|
||||
D3D11ConstantBufferBindings& Bindings);
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void RestoreSamplers(
|
||||
D3D11SamplerBindings& Bindings);
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void RestoreShaderResources(
|
||||
D3D11ShaderResourceBindings& Bindings);
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void RestoreUnorderedAccessViews(
|
||||
D3D11UnorderedAccessBindings& Bindings);
|
||||
|
||||
bool TestRtvUavHazards(
|
||||
UINT NumRTVs,
|
||||
ID3D11RenderTargetView* const* ppRTVs,
|
||||
|
@ -63,6 +63,123 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
void STDMETHODCALLTYPE D3D11CommonContext<ContextType>::ClearState() {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
// Default shaders
|
||||
m_state.vs.shader = nullptr;
|
||||
m_state.hs.shader = nullptr;
|
||||
m_state.ds.shader = nullptr;
|
||||
m_state.gs.shader = nullptr;
|
||||
m_state.ps.shader = nullptr;
|
||||
m_state.cs.shader = nullptr;
|
||||
|
||||
// Default constant buffers
|
||||
for (uint32_t i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; i++) {
|
||||
m_state.vs.constantBuffers[i] = { nullptr, 0, 0 };
|
||||
m_state.hs.constantBuffers[i] = { nullptr, 0, 0 };
|
||||
m_state.ds.constantBuffers[i] = { nullptr, 0, 0 };
|
||||
m_state.gs.constantBuffers[i] = { nullptr, 0, 0 };
|
||||
m_state.ps.constantBuffers[i] = { nullptr, 0, 0 };
|
||||
m_state.cs.constantBuffers[i] = { nullptr, 0, 0 };
|
||||
}
|
||||
|
||||
// Default samplers
|
||||
for (uint32_t i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; i++) {
|
||||
m_state.vs.samplers[i] = nullptr;
|
||||
m_state.hs.samplers[i] = nullptr;
|
||||
m_state.ds.samplers[i] = nullptr;
|
||||
m_state.gs.samplers[i] = nullptr;
|
||||
m_state.ps.samplers[i] = nullptr;
|
||||
m_state.cs.samplers[i] = nullptr;
|
||||
}
|
||||
|
||||
// Default shader resources
|
||||
for (uint32_t i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; i++) {
|
||||
m_state.vs.shaderResources.views[i] = nullptr;
|
||||
m_state.hs.shaderResources.views[i] = nullptr;
|
||||
m_state.ds.shaderResources.views[i] = nullptr;
|
||||
m_state.gs.shaderResources.views[i] = nullptr;
|
||||
m_state.ps.shaderResources.views[i] = nullptr;
|
||||
m_state.cs.shaderResources.views[i] = nullptr;
|
||||
}
|
||||
|
||||
m_state.vs.shaderResources.hazardous.clear();
|
||||
m_state.hs.shaderResources.hazardous.clear();
|
||||
m_state.ds.shaderResources.hazardous.clear();
|
||||
m_state.gs.shaderResources.hazardous.clear();
|
||||
m_state.ps.shaderResources.hazardous.clear();
|
||||
m_state.cs.shaderResources.hazardous.clear();
|
||||
|
||||
// Default UAVs
|
||||
for (uint32_t i = 0; i < D3D11_1_UAV_SLOT_COUNT; i++) {
|
||||
m_state.ps.unorderedAccessViews[i] = nullptr;
|
||||
m_state.cs.unorderedAccessViews[i] = nullptr;
|
||||
}
|
||||
|
||||
m_state.cs.uavMask.clear();
|
||||
|
||||
// Default ID state
|
||||
m_state.id.argBuffer = nullptr;
|
||||
|
||||
// Default IA state
|
||||
m_state.ia.inputLayout = nullptr;
|
||||
m_state.ia.primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
|
||||
|
||||
for (uint32_t i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; i++) {
|
||||
m_state.ia.vertexBuffers[i].buffer = nullptr;
|
||||
m_state.ia.vertexBuffers[i].offset = 0;
|
||||
m_state.ia.vertexBuffers[i].stride = 0;
|
||||
}
|
||||
|
||||
m_state.ia.indexBuffer.buffer = nullptr;
|
||||
m_state.ia.indexBuffer.offset = 0;
|
||||
m_state.ia.indexBuffer.format = DXGI_FORMAT_UNKNOWN;
|
||||
|
||||
// Default OM State
|
||||
for (uint32_t i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
|
||||
m_state.om.renderTargetViews[i] = nullptr;
|
||||
m_state.om.depthStencilView = nullptr;
|
||||
|
||||
m_state.om.cbState = nullptr;
|
||||
m_state.om.dsState = nullptr;
|
||||
|
||||
for (uint32_t i = 0; i < 4; i++)
|
||||
m_state.om.blendFactor[i] = 1.0f;
|
||||
|
||||
m_state.om.sampleCount = 0;
|
||||
m_state.om.sampleMask = D3D11_DEFAULT_SAMPLE_MASK;
|
||||
m_state.om.stencilRef = D3D11_DEFAULT_STENCIL_REFERENCE;
|
||||
|
||||
m_state.om.maxRtv = 0;
|
||||
m_state.om.maxUav = 0;
|
||||
|
||||
// Default RS state
|
||||
m_state.rs.state = nullptr;
|
||||
m_state.rs.numViewports = 0;
|
||||
m_state.rs.numScissors = 0;
|
||||
|
||||
for (uint32_t i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; i++) {
|
||||
m_state.rs.viewports[i] = D3D11_VIEWPORT { };
|
||||
m_state.rs.scissors [i] = D3D11_RECT { };
|
||||
}
|
||||
|
||||
// Default SO state
|
||||
for (uint32_t i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; i++) {
|
||||
m_state.so.targets[i].buffer = nullptr;
|
||||
m_state.so.targets[i].offset = 0;
|
||||
}
|
||||
|
||||
// Default predication
|
||||
m_state.pr.predicateObject = nullptr;
|
||||
m_state.pr.predicateValue = FALSE;
|
||||
|
||||
// Make sure to apply all state
|
||||
ResetState();
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
void STDMETHODCALLTYPE D3D11CommonContext<ContextType>::UpdateSubresource(
|
||||
ID3D11Resource* pDstResource,
|
||||
@ -1717,6 +1834,112 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
void D3D11CommonContext<ContextType>::ResetState() {
|
||||
EmitCs([] (DxvkContext* ctx) {
|
||||
// Reset render targets
|
||||
ctx->bindRenderTargets(DxvkRenderTargets());
|
||||
|
||||
// Reset vertex input state
|
||||
ctx->setInputLayout(0, nullptr, 0, nullptr);
|
||||
|
||||
// Reset render states
|
||||
DxvkInputAssemblyState iaState;
|
||||
InitDefaultPrimitiveTopology(&iaState);
|
||||
|
||||
DxvkDepthStencilState dsState;
|
||||
InitDefaultDepthStencilState(&dsState);
|
||||
|
||||
DxvkRasterizerState rsState;
|
||||
InitDefaultRasterizerState(&rsState);
|
||||
|
||||
DxvkBlendMode cbState;
|
||||
DxvkLogicOpState loState;
|
||||
DxvkMultisampleState msState;
|
||||
InitDefaultBlendState(&cbState, &loState, &msState, D3D11_DEFAULT_SAMPLE_MASK);
|
||||
|
||||
ctx->setInputAssemblyState(iaState);
|
||||
ctx->setDepthStencilState(dsState);
|
||||
ctx->setRasterizerState(rsState);
|
||||
ctx->setLogicOpState(loState);
|
||||
ctx->setMultisampleState(msState);
|
||||
|
||||
for (uint32_t i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
|
||||
ctx->setBlendMode(i, cbState);
|
||||
|
||||
// Reset dynamic states
|
||||
ctx->setBlendConstants(DxvkBlendConstants { 1.0f, 1.0f, 1.0f, 1.0f });
|
||||
ctx->setStencilReference(D3D11_DEFAULT_STENCIL_REFERENCE);
|
||||
|
||||
// Reset viewports
|
||||
auto viewport = VkViewport();
|
||||
auto scissor = VkRect2D();
|
||||
|
||||
ctx->setViewports(1, &viewport, &scissor);
|
||||
|
||||
// Unbind indirect draw buffer
|
||||
ctx->bindDrawBuffers(DxvkBufferSlice(), DxvkBufferSlice());
|
||||
|
||||
// Unbind index and vertex buffers
|
||||
ctx->bindIndexBuffer(DxvkBufferSlice(), VK_INDEX_TYPE_UINT32);
|
||||
|
||||
for (uint32_t i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; i++)
|
||||
ctx->bindVertexBuffer(i, DxvkBufferSlice(), 0);
|
||||
|
||||
// Unbind transform feedback buffers
|
||||
for (uint32_t i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; i++)
|
||||
ctx->bindXfbBuffer(i, DxvkBufferSlice(), DxvkBufferSlice());
|
||||
|
||||
// Unbind per-shader stage resources
|
||||
for (uint32_t i = 0; i < 6; i++) {
|
||||
auto programType = DxbcProgramType(i);
|
||||
auto stage = GetShaderStage(programType);
|
||||
|
||||
ctx->bindShader(stage, nullptr);
|
||||
|
||||
// Unbind constant buffers, including the shader's ICB
|
||||
auto cbSlotId = computeConstantBufferBinding(programType, 0);
|
||||
|
||||
for (uint32_t j = 0; j <= D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; j++)
|
||||
ctx->bindResourceBuffer(stage, cbSlotId + j, DxvkBufferSlice());
|
||||
|
||||
// Unbind shader resource views
|
||||
auto srvSlotId = computeSrvBinding(programType, 0);
|
||||
|
||||
for (uint32_t j = 0; j < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; j++)
|
||||
ctx->bindResourceView(stage, srvSlotId + j, nullptr, nullptr);
|
||||
|
||||
// Unbind texture samplers
|
||||
auto samplerSlotId = computeSamplerBinding(programType, 0);
|
||||
|
||||
for (uint32_t j = 0; j < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; j++)
|
||||
ctx->bindResourceSampler(stage, samplerSlotId + j, nullptr);
|
||||
|
||||
// Unbind UAVs for supported stages
|
||||
if (programType == DxbcProgramType::PixelShader
|
||||
|| programType == DxbcProgramType::ComputeShader) {
|
||||
VkShaderStageFlags stages = programType == DxbcProgramType::PixelShader
|
||||
? VK_SHADER_STAGE_ALL_GRAPHICS
|
||||
: VK_SHADER_STAGE_COMPUTE_BIT;
|
||||
|
||||
auto uavSlotId = computeUavBinding(programType, 0);
|
||||
auto ctrSlotId = computeUavCounterBinding(programType, 0);
|
||||
|
||||
for (uint32_t j = 0; j < D3D11_1_UAV_SLOT_COUNT; j++) {
|
||||
ctx->bindResourceView (stages, uavSlotId, nullptr, nullptr);
|
||||
ctx->bindResourceBuffer (stages, ctrSlotId, DxvkBufferSlice());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize push constants
|
||||
DxbcPushConstants pc;
|
||||
pc.rasterizerSampleCount = 1;
|
||||
ctx->pushConstants(0, sizeof(pc), &pc);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
template<DxbcProgramType ShaderStage, typename T>
|
||||
void D3D11CommonContext<ContextType>::ResolveSrvHazards(
|
||||
@ -2049,6 +2272,123 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
void D3D11CommonContext<ContextType>::RestoreState() {
|
||||
BindFramebuffer();
|
||||
|
||||
BindShader<DxbcProgramType::VertexShader> (GetCommonShader(m_state.vs.shader.ptr()));
|
||||
BindShader<DxbcProgramType::HullShader> (GetCommonShader(m_state.hs.shader.ptr()));
|
||||
BindShader<DxbcProgramType::DomainShader> (GetCommonShader(m_state.ds.shader.ptr()));
|
||||
BindShader<DxbcProgramType::GeometryShader> (GetCommonShader(m_state.gs.shader.ptr()));
|
||||
BindShader<DxbcProgramType::PixelShader> (GetCommonShader(m_state.ps.shader.ptr()));
|
||||
BindShader<DxbcProgramType::ComputeShader> (GetCommonShader(m_state.cs.shader.ptr()));
|
||||
|
||||
ApplyInputLayout();
|
||||
ApplyPrimitiveTopology();
|
||||
ApplyBlendState();
|
||||
ApplyBlendFactor();
|
||||
ApplyDepthStencilState();
|
||||
ApplyStencilRef();
|
||||
ApplyRasterizerState();
|
||||
ApplyRasterizerSampleCount();
|
||||
ApplyViewportState();
|
||||
|
||||
BindDrawBuffers(
|
||||
m_state.id.argBuffer.ptr(),
|
||||
m_state.id.cntBuffer.ptr());
|
||||
|
||||
BindIndexBuffer(
|
||||
m_state.ia.indexBuffer.buffer.ptr(),
|
||||
m_state.ia.indexBuffer.offset,
|
||||
m_state.ia.indexBuffer.format);
|
||||
|
||||
for (uint32_t i = 0; i < m_state.ia.vertexBuffers.size(); i++) {
|
||||
BindVertexBuffer(i,
|
||||
m_state.ia.vertexBuffers[i].buffer.ptr(),
|
||||
m_state.ia.vertexBuffers[i].offset,
|
||||
m_state.ia.vertexBuffers[i].stride);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < m_state.so.targets.size(); i++)
|
||||
BindXfbBuffer(i, m_state.so.targets[i].buffer.ptr(), ~0u);
|
||||
|
||||
RestoreConstantBuffers<DxbcProgramType::VertexShader> (m_state.vs.constantBuffers);
|
||||
RestoreConstantBuffers<DxbcProgramType::HullShader> (m_state.hs.constantBuffers);
|
||||
RestoreConstantBuffers<DxbcProgramType::DomainShader> (m_state.ds.constantBuffers);
|
||||
RestoreConstantBuffers<DxbcProgramType::GeometryShader> (m_state.gs.constantBuffers);
|
||||
RestoreConstantBuffers<DxbcProgramType::PixelShader> (m_state.ps.constantBuffers);
|
||||
RestoreConstantBuffers<DxbcProgramType::ComputeShader> (m_state.cs.constantBuffers);
|
||||
|
||||
RestoreSamplers<DxbcProgramType::VertexShader> (m_state.vs.samplers);
|
||||
RestoreSamplers<DxbcProgramType::HullShader> (m_state.hs.samplers);
|
||||
RestoreSamplers<DxbcProgramType::DomainShader> (m_state.ds.samplers);
|
||||
RestoreSamplers<DxbcProgramType::GeometryShader>(m_state.gs.samplers);
|
||||
RestoreSamplers<DxbcProgramType::PixelShader> (m_state.ps.samplers);
|
||||
RestoreSamplers<DxbcProgramType::ComputeShader> (m_state.cs.samplers);
|
||||
|
||||
RestoreShaderResources<DxbcProgramType::VertexShader> (m_state.vs.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::HullShader> (m_state.hs.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::DomainShader> (m_state.ds.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::GeometryShader> (m_state.gs.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::PixelShader> (m_state.ps.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::ComputeShader> (m_state.cs.shaderResources);
|
||||
|
||||
RestoreUnorderedAccessViews<DxbcProgramType::PixelShader> (m_state.ps.unorderedAccessViews);
|
||||
RestoreUnorderedAccessViews<DxbcProgramType::ComputeShader> (m_state.cs.unorderedAccessViews);
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
template<DxbcProgramType Stage>
|
||||
void D3D11CommonContext<ContextType>::RestoreConstantBuffers(
|
||||
D3D11ConstantBufferBindings& Bindings) {
|
||||
uint32_t slotId = computeConstantBufferBinding(Stage, 0);
|
||||
|
||||
for (uint32_t i = 0; i < Bindings.size(); i++) {
|
||||
BindConstantBuffer<Stage>(slotId + i, Bindings[i].buffer.ptr(),
|
||||
Bindings[i].constantOffset, Bindings[i].constantBound);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
template<DxbcProgramType Stage>
|
||||
void D3D11CommonContext<ContextType>::RestoreSamplers(
|
||||
D3D11SamplerBindings& Bindings) {
|
||||
uint32_t slotId = computeSamplerBinding(Stage, 0);
|
||||
|
||||
for (uint32_t i = 0; i < Bindings.size(); i++)
|
||||
BindSampler<Stage>(slotId + i, Bindings[i]);
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
template<DxbcProgramType Stage>
|
||||
void D3D11CommonContext<ContextType>::RestoreShaderResources(
|
||||
D3D11ShaderResourceBindings& Bindings) {
|
||||
uint32_t slotId = computeSrvBinding(Stage, 0);
|
||||
|
||||
for (uint32_t i = 0; i < Bindings.views.size(); i++)
|
||||
BindShaderResource<Stage>(slotId + i, Bindings.views[i].ptr());
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
template<DxbcProgramType Stage>
|
||||
void D3D11CommonContext<ContextType>::RestoreUnorderedAccessViews(
|
||||
D3D11UnorderedAccessBindings& Bindings) {
|
||||
uint32_t uavSlotId = computeUavBinding (Stage, 0);
|
||||
uint32_t ctrSlotId = computeUavCounterBinding(Stage, 0);
|
||||
|
||||
for (uint32_t i = 0; i < Bindings.size(); i++) {
|
||||
BindUnorderedAccessView<Stage>(
|
||||
uavSlotId + i,
|
||||
Bindings[i].ptr(),
|
||||
ctrSlotId + i, ~0u);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
bool D3D11CommonContext<ContextType>::TestRtvUavHazards(
|
||||
UINT NumRTVs,
|
||||
|
@ -68,6 +68,8 @@ namespace dxvk {
|
||||
REFIID riid,
|
||||
void** ppvObject);
|
||||
|
||||
void STDMETHODCALLTYPE ClearState();
|
||||
|
||||
void STDMETHODCALLTYPE UpdateSubresource(
|
||||
ID3D11Resource* pDstResource,
|
||||
UINT DstSubresource,
|
||||
@ -584,6 +586,8 @@ namespace dxvk {
|
||||
UINT NumSamplers,
|
||||
ID3D11SamplerState** ppSamplers);
|
||||
|
||||
void ResetState();
|
||||
|
||||
template<DxbcProgramType ShaderStage, typename T>
|
||||
void ResolveSrvHazards(
|
||||
T* pView,
|
||||
@ -603,6 +607,24 @@ namespace dxvk {
|
||||
void ResolveOmUavHazards(
|
||||
D3D11RenderTargetView* pView);
|
||||
|
||||
void RestoreState();
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void RestoreConstantBuffers(
|
||||
D3D11ConstantBufferBindings& Bindings);
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void RestoreSamplers(
|
||||
D3D11SamplerBindings& Bindings);
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void RestoreShaderResources(
|
||||
D3D11ShaderResourceBindings& Bindings);
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void RestoreUnorderedAccessViews(
|
||||
D3D11UnorderedAccessBindings& Bindings);
|
||||
|
||||
template<DxbcProgramType ShaderStage>
|
||||
void SetConstantBuffers(
|
||||
D3D11ConstantBufferBindings& Bindings,
|
||||
|
Loading…
Reference in New Issue
Block a user