Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/d3d11/d3d11_context_def.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,10 @@ class MTLD3D11DeferredContext : public DeferredContextBase {
state_.InputAssembler.VertexBuffers.set_dirty();
}
if (bind_flag & D3D11_BIND_CONSTANT_BUFFER) {
for (auto &stage : state_.ShaderStages) {
stage.ConstantBuffers.set_dirty();
}
dirtyConstantBufferStages(state_.ShaderStages, GetResourceCommon(pResource));
}
if (bind_flag & D3D11_BIND_SHADER_RESOURCE) {
for (auto &stage : state_.ShaderStages) {
stage.SRVs.set_dirty();
}
dirtyShaderResourceStages(state_.ShaderStages, GetResourceCommon(pResource));
}

pMappedResource->pData = MapDynamicBuffer(dynamic);
Expand Down Expand Up @@ -201,9 +197,7 @@ class MTLD3D11DeferredContext : public DeferredContextBase {
case D3D11_MAP_READ_WRITE:
return E_INVALIDARG;
case D3D11_MAP_WRITE_DISCARD: {
for (auto &stage : state_.ShaderStages) {
stage.SRVs.set_dirty();
}
dirtyShaderResourceStages(state_.ShaderStages, GetResourceCommon(pResource));
Rc<TextureAllocation> new_allocation = dynamic->allocate(ctx_state.cmd_queue.CoherentSeqId());
uint32_t id = ctx_state.current_cmdlist->used_dynamic_lineartextures.size();
// track the current allocation in case of a following NO_OVERWRITE map
Expand Down Expand Up @@ -251,9 +245,7 @@ class MTLD3D11DeferredContext : public DeferredContextBase {
case D3D11_MAP_WRITE_NO_OVERWRITE:
return E_INVALIDARG;
case D3D11_MAP_WRITE_DISCARD: {
for (auto &stage : state_.ShaderStages) {
stage.SRVs.set_dirty();
}
dirtyShaderResourceStages(state_.ShaderStages, GetResourceCommon(pResource));
pMappedResource->pData = MapDynamicBuffer(dynamic);
pMappedResource->RowPitch = row_pitch;
pMappedResource->DepthPitch = depth_pitch;
Expand Down
16 changes: 4 additions & 12 deletions src/d3d11/d3d11_context_imm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,10 @@ class MTLD3D11ImmediateContext : public ImmediateContextBase {
state_.InputAssembler.VertexBuffers.set_dirty();
}
if (bind_flag & D3D11_BIND_CONSTANT_BUFFER) {
for (auto &stage : state_.ShaderStages) {
stage.ConstantBuffers.set_dirty();
}
dirtyConstantBufferStages(state_.ShaderStages, GetResourceCommon(pResource));
}
if (bind_flag & D3D11_BIND_SHADER_RESOURCE) {
for (auto &stage : state_.ShaderStages) {
stage.SRVs.set_dirty();
}
dirtyShaderResourceStages(state_.ShaderStages, GetResourceCommon(pResource));
}

pMappedResource->pData = MapDynamicBuffer(dynamic, current_seq_id, coherent_seq_id);
Expand All @@ -188,9 +184,7 @@ class MTLD3D11ImmediateContext : public ImmediateContextBase {
case D3D11_MAP_WRITE_NO_OVERWRITE:
return E_INVALIDARG;
case D3D11_MAP_WRITE_DISCARD: {
for (auto &stage : state_.ShaderStages) {
stage.SRVs.set_dirty();
}
dirtyShaderResourceStages(state_.ShaderStages, GetResourceCommon(pResource));

pMappedResource->pData = MapDynamicBuffer(dynamic, current_seq_id, coherent_seq_id);
pMappedResource->RowPitch = row_pitch;
Expand All @@ -207,9 +201,7 @@ class MTLD3D11ImmediateContext : public ImmediateContextBase {
case D3D11_MAP_READ_WRITE:
return E_INVALIDARG;
case D3D11_MAP_WRITE_DISCARD: {
for (auto &stage : state_.ShaderStages) {
stage.SRVs.set_dirty();
}
dirtyShaderResourceStages(state_.ShaderStages, GetResourceCommon(pResource));

dynamic->updateImmediateName(current_seq_id, dynamic->allocate(coherent_seq_id), false);
EmitST([allocation = dynamic->immediateName(),
Expand Down
26 changes: 26 additions & 0 deletions src/d3d11/d3d11_context_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,30 @@ class MTLD3D11DeviceContextState
}
};

/** On discard-map the backing rotates, so dirty only the stages that bind the
* mapped resource — the rest would re-encode their tables for nothing. */
inline void
dirtyConstantBufferStages(D3D11StagesState<D3D11ShaderStageState> &stages, D3D11ResourceCommon *resource) {
for (auto &stage : stages) {
for (const auto &[slot, entry] : stage.ConstantBuffers) {
if (entry.Buffer.ptr() == resource) {
stage.ConstantBuffers.set_dirty();
break;
}
}
}
}

inline void
dirtyShaderResourceStages(D3D11StagesState<D3D11ShaderStageState> &stages, D3D11ResourceCommon *resource) {
for (auto &stage : stages) {
for (const auto &[slot, entry] : stage.SRVs) {
if (entry.SRV->resource_.ptr() == resource) {
stage.SRVs.set_dirty();
break;
}
}
}
}

} // namespace dxmt