1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-13 16:08:50 +01:00

[dxvk] Make shader stage parameter in bindShader a template parameter

This commit is contained in:
Philip Rebohle 2022-08-07 15:02:48 +02:00
parent 29a2cb9a5e
commit 2e6a2f1be3
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
7 changed files with 29 additions and 23 deletions

View File

@ -3125,7 +3125,7 @@ namespace dxvk {
uint32_t slotId = computeConstantBufferBinding(ShaderStage, uint32_t slotId = computeConstantBufferBinding(ShaderStage,
D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT); D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
ctx->bindShader(stage, ctx->bindShader<stage>(
Forwarder::move(cShader)); Forwarder::move(cShader));
ctx->bindResourceBuffer(stage, slotId, ctx->bindResourceBuffer(stage, slotId,
Forwarder::move(cSlice)); Forwarder::move(cSlice));
@ -3911,6 +3911,14 @@ namespace dxvk {
for (uint32_t i = 0; i < cUsedBindings.soCount; i++) for (uint32_t i = 0; i < cUsedBindings.soCount; i++)
ctx->bindXfbBuffer(i, DxvkBufferSlice(), DxvkBufferSlice()); ctx->bindXfbBuffer(i, DxvkBufferSlice(), DxvkBufferSlice());
// Unbind all shaders
ctx->bindShader<VK_SHADER_STAGE_VERTEX_BIT>(nullptr);
ctx->bindShader<VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT>(nullptr);
ctx->bindShader<VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT>(nullptr);
ctx->bindShader<VK_SHADER_STAGE_GEOMETRY_BIT>(nullptr);
ctx->bindShader<VK_SHADER_STAGE_FRAGMENT_BIT>(nullptr);
ctx->bindShader<VK_SHADER_STAGE_COMPUTE_BIT>(nullptr);
// Unbind per-shader stage resources // Unbind per-shader stage resources
for (uint32_t i = 0; i < 6; i++) { for (uint32_t i = 0; i < 6; i++) {
auto programType = DxbcProgramType(i); auto programType = DxbcProgramType(i);
@ -3918,8 +3926,6 @@ namespace dxvk {
// Unbind constant buffers, including the shader's ICB // Unbind constant buffers, including the shader's ICB
auto cbSlotId = computeConstantBufferBinding(programType, 0); auto cbSlotId = computeConstantBufferBinding(programType, 0);
ctx->bindShader(stage, nullptr);
ctx->bindResourceBuffer(stage, cbSlotId + D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, DxvkBufferSlice()); ctx->bindResourceBuffer(stage, cbSlotId + D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, DxvkBufferSlice());
for (uint32_t j = 0; j < cUsedBindings.stages[i].cbvCount; j++) for (uint32_t j = 0; j < cUsedBindings.stages[i].cbvCount; j++)

View File

@ -1199,8 +1199,8 @@ namespace dxvk {
rt.color[0].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; rt.color[0].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
ctx->bindRenderTargets(std::move(rt), 0u); ctx->bindRenderTargets(std::move(rt), 0u);
ctx->bindShader(VK_SHADER_STAGE_VERTEX_BIT, Rc<DxvkShader>(m_vs)); ctx->bindShader<VK_SHADER_STAGE_VERTEX_BIT>(Rc<DxvkShader>(m_vs));
ctx->bindShader(VK_SHADER_STAGE_FRAGMENT_BIT, Rc<DxvkShader>(m_fs)); ctx->bindShader<VK_SHADER_STAGE_FRAGMENT_BIT>(Rc<DxvkShader>(m_fs));
ctx->bindResourceBuffer(VK_SHADER_STAGE_FRAGMENT_BIT, 0, DxvkBufferSlice(m_ubo)); ctx->bindResourceBuffer(VK_SHADER_STAGE_FRAGMENT_BIT, 0, DxvkBufferSlice(m_ubo));
DxvkInputAssemblyState iaState; DxvkInputAssemblyState iaState;
@ -1314,8 +1314,8 @@ namespace dxvk {
m_ctx->EmitCs([this] (DxvkContext* ctx) { m_ctx->EmitCs([this] (DxvkContext* ctx) {
ctx->bindRenderTargets(DxvkRenderTargets(), 0u); ctx->bindRenderTargets(DxvkRenderTargets(), 0u);
ctx->bindShader(VK_SHADER_STAGE_VERTEX_BIT, nullptr); ctx->bindShader<VK_SHADER_STAGE_VERTEX_BIT>(nullptr);
ctx->bindShader(VK_SHADER_STAGE_FRAGMENT_BIT, nullptr); ctx->bindShader<VK_SHADER_STAGE_FRAGMENT_BIT>(nullptr);
ctx->bindResourceBuffer(VK_SHADER_STAGE_FRAGMENT_BIT, 0, DxvkBufferSlice()); ctx->bindResourceBuffer(VK_SHADER_STAGE_FRAGMENT_BIT, 0, DxvkBufferSlice());
}); });

View File

@ -2668,15 +2668,15 @@ namespace dxvk {
// Unbind the pixel shader, we aren't drawing // Unbind the pixel shader, we aren't drawing
// to avoid val errors / UB. // to avoid val errors / UB.
ctx->bindShader(VK_SHADER_STAGE_FRAGMENT_BIT, nullptr); ctx->bindShader<VK_SHADER_STAGE_FRAGMENT_BIT>(nullptr);
ctx->bindShader(VK_SHADER_STAGE_GEOMETRY_BIT, std::move(shader)); ctx->bindShader<VK_SHADER_STAGE_GEOMETRY_BIT>(std::move(shader));
ctx->bindResourceBuffer(VK_SHADER_STAGE_GEOMETRY_BIT, getSWVPBufferSlot(), std::move(cBufferSlice)); ctx->bindResourceBuffer(VK_SHADER_STAGE_GEOMETRY_BIT, getSWVPBufferSlot(), std::move(cBufferSlice));
ctx->draw( ctx->draw(
drawInfo.vertexCount, drawInfo.instanceCount, drawInfo.vertexCount, drawInfo.instanceCount,
cStartIndex, 0); cStartIndex, 0);
ctx->bindResourceBuffer(VK_SHADER_STAGE_GEOMETRY_BIT, getSWVPBufferSlot(), DxvkBufferSlice()); ctx->bindResourceBuffer(VK_SHADER_STAGE_GEOMETRY_BIT, getSWVPBufferSlot(), DxvkBufferSlice());
ctx->bindShader(VK_SHADER_STAGE_GEOMETRY_BIT, nullptr); ctx->bindShader<VK_SHADER_STAGE_GEOMETRY_BIT>(nullptr);
}); });
// We unbound the pixel shader before, // We unbound the pixel shader before,
@ -6131,7 +6131,7 @@ namespace dxvk {
cShader = pShaderModule->GetShader(Permutation) cShader = pShaderModule->GetShader(Permutation)
] (DxvkContext* ctx) mutable { ] (DxvkContext* ctx) mutable {
constexpr VkShaderStageFlagBits stage = GetShaderStage(ShaderStage); constexpr VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
ctx->bindShader(stage, std::move(cShader)); ctx->bindShader<stage>(std::move(cShader));
}); });
} }
@ -6504,7 +6504,7 @@ namespace dxvk {
&cShaders = m_ffModules &cShaders = m_ffModules
](DxvkContext* ctx) { ](DxvkContext* ctx) {
auto shader = cShaders.GetShaderModule(this, cKey); auto shader = cShaders.GetShaderModule(this, cKey);
ctx->bindShader(VK_SHADER_STAGE_VERTEX_BIT, shader.GetShader()); ctx->bindShader<VK_SHADER_STAGE_VERTEX_BIT>(shader.GetShader());
}); });
} }
@ -6679,7 +6679,7 @@ namespace dxvk {
&cShaders = m_ffModules &cShaders = m_ffModules
](DxvkContext* ctx) { ](DxvkContext* ctx) {
auto shader = cShaders.GetShaderModule(this, cKey); auto shader = cShaders.GetShaderModule(this, cKey);
ctx->bindShader(VK_SHADER_STAGE_FRAGMENT_BIT, shader.GetShader()); ctx->bindShader<VK_SHADER_STAGE_FRAGMENT_BIT>(shader.GetShader());
}); });
} }

View File

@ -96,7 +96,7 @@ namespace dxvk {
m_context->setSpecConstant(VK_PIPELINE_BIND_POINT_COMPUTE, 0, specConstantValue); m_context->setSpecConstant(VK_PIPELINE_BIND_POINT_COMPUTE, 0, specConstantValue);
m_context->bindResourceImageView(VK_SHADER_STAGE_COMPUTE_BIT, BindingIds::Image, std::move(tmpImageView)); m_context->bindResourceImageView(VK_SHADER_STAGE_COMPUTE_BIT, BindingIds::Image, std::move(tmpImageView));
m_context->bindResourceBufferView(VK_SHADER_STAGE_COMPUTE_BIT, BindingIds::Buffer, std::move(tmpBufferView)); m_context->bindResourceBufferView(VK_SHADER_STAGE_COMPUTE_BIT, BindingIds::Buffer, std::move(tmpBufferView));
m_context->bindShader(VK_SHADER_STAGE_COMPUTE_BIT, Rc<DxvkShader>(m_shaders[videoFormat.FormatType])); m_context->bindShader<VK_SHADER_STAGE_COMPUTE_BIT>(Rc<DxvkShader>(m_shaders[videoFormat.FormatType]));
m_context->pushConstants(0, sizeof(VkExtent2D), &imageExtent); m_context->pushConstants(0, sizeof(VkExtent2D), &imageExtent);
m_context->dispatch( m_context->dispatch(
(imageExtent.width / 8) + (imageExtent.width % 8), (imageExtent.width / 8) + (imageExtent.width % 8),

View File

@ -261,10 +261,10 @@ namespace dxvk {
* \param [in] stage Target shader stage * \param [in] stage Target shader stage
* \param [in] shader The shader to bind * \param [in] shader The shader to bind
*/ */
template<VkShaderStageFlagBits Stage>
void bindShader( void bindShader(
VkShaderStageFlagBits stage,
Rc<DxvkShader>&& shader) { Rc<DxvkShader>&& shader) {
switch (stage) { switch (Stage) {
case VK_SHADER_STAGE_VERTEX_BIT: case VK_SHADER_STAGE_VERTEX_BIT:
m_state.gp.shaders.vs = std::move(shader); m_state.gp.shaders.vs = std::move(shader);
break; break;
@ -293,7 +293,7 @@ namespace dxvk {
return; return;
} }
if (stage == VK_SHADER_STAGE_COMPUTE_BIT) { if (Stage == VK_SHADER_STAGE_COMPUTE_BIT) {
m_flags.set( m_flags.set(
DxvkContextFlag::CpDirtyPipelineState); DxvkContextFlag::CpDirtyPipelineState);
} else { } else {

View File

@ -197,8 +197,8 @@ namespace dxvk {
ctx->bindResourceImageView(VK_SHADER_STAGE_FRAGMENT_BIT, BindingIds::Image, Rc<DxvkImageView>(srcView)); ctx->bindResourceImageView(VK_SHADER_STAGE_FRAGMENT_BIT, BindingIds::Image, Rc<DxvkImageView>(srcView));
ctx->bindResourceImageView(VK_SHADER_STAGE_FRAGMENT_BIT, BindingIds::Gamma, Rc<DxvkImageView>(m_gammaView)); ctx->bindResourceImageView(VK_SHADER_STAGE_FRAGMENT_BIT, BindingIds::Gamma, Rc<DxvkImageView>(m_gammaView));
ctx->bindShader(VK_SHADER_STAGE_VERTEX_BIT, Rc<DxvkShader>(m_vs)); ctx->bindShader<VK_SHADER_STAGE_VERTEX_BIT>(Rc<DxvkShader>(m_vs));
ctx->bindShader(VK_SHADER_STAGE_FRAGMENT_BIT, Rc<DxvkShader>(fs)); ctx->bindShader<VK_SHADER_STAGE_FRAGMENT_BIT>(Rc<DxvkShader>(fs));
PresenterArgs args; PresenterArgs args;
args.srcOffset = srcRect.offset; args.srcOffset = srcRect.offset;

View File

@ -104,8 +104,8 @@ namespace dxvk::hud {
if (m_mode != Mode::RenderText) { if (m_mode != Mode::RenderText) {
m_mode = Mode::RenderText; m_mode = Mode::RenderText;
m_context->bindShader(VK_SHADER_STAGE_VERTEX_BIT, Rc<DxvkShader>(m_textShaders.vert)); m_context->bindShader<VK_SHADER_STAGE_VERTEX_BIT>(Rc<DxvkShader>(m_textShaders.vert));
m_context->bindShader(VK_SHADER_STAGE_FRAGMENT_BIT, Rc<DxvkShader>(m_textShaders.frag)); m_context->bindShader<VK_SHADER_STAGE_FRAGMENT_BIT>(Rc<DxvkShader>(m_textShaders.frag));
m_context->bindResourceBuffer(VK_SHADER_STAGE_VERTEX_BIT, 0, DxvkBufferSlice(m_fontBuffer)); m_context->bindResourceBuffer(VK_SHADER_STAGE_VERTEX_BIT, 0, DxvkBufferSlice(m_fontBuffer));
m_context->bindResourceBufferView(VK_SHADER_STAGE_VERTEX_BIT, 1, Rc<DxvkBufferView>(m_dataView)); m_context->bindResourceBufferView(VK_SHADER_STAGE_VERTEX_BIT, 1, Rc<DxvkBufferView>(m_dataView));
@ -126,8 +126,8 @@ namespace dxvk::hud {
if (m_mode != Mode::RenderGraph) { if (m_mode != Mode::RenderGraph) {
m_mode = Mode::RenderGraph; m_mode = Mode::RenderGraph;
m_context->bindShader(VK_SHADER_STAGE_VERTEX_BIT, Rc<DxvkShader>(m_graphShaders.vert)); m_context->bindShader<VK_SHADER_STAGE_VERTEX_BIT>(Rc<DxvkShader>(m_graphShaders.vert));
m_context->bindShader(VK_SHADER_STAGE_FRAGMENT_BIT, Rc<DxvkShader>(m_graphShaders.frag)); m_context->bindShader<VK_SHADER_STAGE_FRAGMENT_BIT>(Rc<DxvkShader>(m_graphShaders.frag));
m_context->bindResourceBuffer(VK_SHADER_STAGE_FRAGMENT_BIT, 0, DxvkBufferSlice(m_dataBuffer)); m_context->bindResourceBuffer(VK_SHADER_STAGE_FRAGMENT_BIT, 0, DxvkBufferSlice(m_dataBuffer));