[d3d11] Implemented shader resource binding

This commit is contained in:
Philip Rebohle 2017-12-10 01:56:07 +01:00
parent 9a86178604
commit 9c997120e1
4 changed files with 87 additions and 9 deletions

View File

@ -61,8 +61,8 @@ namespace dxvk {
this->VSSetShader(nullptr, nullptr, 0);
this->VSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, nullptr);
// this->VSSetShaderResources(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, nullptr);
// this->VSSetSamplers (0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, nullptr);
this->VSSetShaderResources(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, nullptr);
this->VSSetSamplers (0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, nullptr);
// this->HSSetShader(nullptr, nullptr, 0);
// this->HSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, nullptr);
@ -81,8 +81,8 @@ namespace dxvk {
this->PSSetShader(nullptr, nullptr, 0);
this->PSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, nullptr);
// this->PSSetShaderResources(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, nullptr);
// this->PSSetSamplers (0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, nullptr);
this->PSSetShaderResources(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, nullptr);
this->PSSetSamplers (0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, nullptr);
// this->CSSetShader(nullptr, nullptr, 0);
// this->CSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, nullptr);
@ -90,8 +90,8 @@ namespace dxvk {
// this->CSSetSamplers (0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, nullptr);
this->OMSetRenderTargets(0, nullptr, nullptr);
// this->OMSetBlendState(nullptr, nullptr, D3D11_DEFAULT_SAMPLE_MASK);
// this->OMSetDepthStencilState(nullptr, 0);
this->OMSetBlendState(nullptr, nullptr, D3D11_DEFAULT_SAMPLE_MASK);
this->OMSetDepthStencilState(nullptr, 0);
this->RSSetState(nullptr);
this->RSSetViewports(0, nullptr);
@ -699,7 +699,11 @@ namespace dxvk {
UINT StartSlot,
UINT NumViews,
ID3D11ShaderResourceView* const* ppShaderResourceViews) {
Logger::err("D3D11DeviceContext::VSSetShaderResources: Not implemented");
this->BindShaderResources(
DxbcProgramType::VertexShader,
&m_state.vs.shaderResources,
StartSlot, NumViews,
ppShaderResourceViews);
}
@ -973,7 +977,11 @@ namespace dxvk {
UINT StartSlot,
UINT NumViews,
ID3D11ShaderResourceView* const* ppShaderResourceViews) {
Logger::err("D3D11DeviceContext::PSSetShaderResources: Not implemented");
this->BindShaderResources(
DxbcProgramType::PixelShader,
&m_state.ps.shaderResources,
StartSlot, NumViews,
ppShaderResourceViews);
}
@ -1408,6 +1416,53 @@ namespace dxvk {
}
void D3D11DeviceContext::BindShaderResources(
DxbcProgramType ShaderStage,
D3D11ShaderResourceBindings* pBindings,
UINT StartSlot,
UINT NumResources,
ID3D11ShaderResourceView* const* ppResources) {
for (uint32_t i = 0; i < NumResources; i++) {
D3D11ShaderResourceView* resView = nullptr;
if (ppResources != nullptr)
resView = static_cast<D3D11ShaderResourceView*>(ppResources[i]);
if (pBindings->at(StartSlot + i) != resView) {
pBindings->at(StartSlot + i) = resView;
// Bind sampler to the DXVK resource slot
const VkPipelineBindPoint bindPoint
= ShaderStage == DxbcProgramType::ComputeShader
? VK_PIPELINE_BIND_POINT_COMPUTE
: VK_PIPELINE_BIND_POINT_GRAPHICS;
const uint32_t slotId = computeResourceSlotId(
ShaderStage, DxbcBindingType::ImageSampler,
StartSlot + i);
if (resView != nullptr) {
// Figure out what we have to bind based on the resource type
if (resView->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER) {
Logger::warn("D3D11: Texel buffers not yet supported");
m_context->bindResourceTexelBuffer(
bindPoint, slotId, nullptr);
} else {
m_context->bindResourceImage(bindPoint,
slotId, resView->GetDXVKImageView());
}
} else {
// When unbinding a resource, it doesn't really matter if
// the resource type is correct, so we'll just bind a null
// image to the given resource slot
m_context->bindResourceImage(
bindPoint, slotId, nullptr);
}
}
}
}
void D3D11DeviceContext::ApplyViewportState() {
// We cannot set less than one viewport in Vulkan, and
// rendering with no active viewport is illegal anyway.

View File

@ -563,6 +563,13 @@ namespace dxvk {
UINT NumSamplers,
ID3D11SamplerState* const* ppSamplers);
void BindShaderResources(
DxbcProgramType ShaderStage,
D3D11ShaderResourceBindings* pBindings,
UINT StartSlot,
UINT NumResources,
ID3D11ShaderResourceView* const* ppResources);
void ApplyViewportState();
void SetupIAStateObjects();

View File

@ -14,15 +14,20 @@ namespace dxvk {
using D3D11ConstantBufferBindings = std::array<
Com<D3D11Buffer>, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT>;
using D3D11SamplerBindings = std::array<
Com<D3D11SamplerState>, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT>;
using D3D11ShaderResourceBindings = std::array<
Com<D3D11ShaderResourceView>, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT>;
struct D3D11ContextStateVS {
Com<D3D11VertexShader> shader;
D3D11ConstantBufferBindings constantBuffers;
D3D11SamplerBindings samplers;
D3D11ShaderResourceBindings shaderResources;
};
@ -30,6 +35,7 @@ namespace dxvk {
Com<D3D11HullShader> shader;
D3D11ConstantBufferBindings constantBuffers;
D3D11SamplerBindings samplers;
D3D11ShaderResourceBindings shaderResources;
};
@ -37,6 +43,7 @@ namespace dxvk {
Com<D3D11DomainShader> shader;
D3D11ConstantBufferBindings constantBuffers;
D3D11SamplerBindings samplers;
D3D11ShaderResourceBindings shaderResources;
};
@ -44,6 +51,7 @@ namespace dxvk {
Com<D3D11GeometryShader> shader;
D3D11ConstantBufferBindings constantBuffers;
D3D11SamplerBindings samplers;
D3D11ShaderResourceBindings shaderResources;
};
@ -51,6 +59,7 @@ namespace dxvk {
Com<D3D11PixelShader> shader;
D3D11ConstantBufferBindings constantBuffers;
D3D11SamplerBindings samplers;
D3D11ShaderResourceBindings shaderResources;
};
@ -58,6 +67,7 @@ namespace dxvk {
Com<D3D11ComputeShader> shader;
D3D11ConstantBufferBindings constantBuffers;
D3D11SamplerBindings samplers;
D3D11ShaderResourceBindings shaderResources;
};

View File

@ -53,6 +53,12 @@ namespace dxvk {
*pDesc = m_desc;
}
D3D11_RESOURCE_DIMENSION GetResourceType() {
D3D11_RESOURCE_DIMENSION type;
m_resource->GetType(&type);
return type;
}
Rc<DxvkBufferView> GetDXVKBufferView() {
return m_bufferView;
}