Skip to content

Commit d86ee54

Browse files
K0bindoitsujin
authored andcommitted
[d3d9] Refactor calculating of binding slots.
To get rid of dxso_util.h in preparation of the new shader compiler.
1 parent bcbc563 commit d86ee54

9 files changed

Lines changed: 122 additions & 107 deletions

src/d3d9/d3d9_constant_buffer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ namespace dxvk {
99

1010

1111
D3D9ConstantBuffer::D3D9ConstantBuffer(
12-
D3D9DeviceEx* pDevice,
13-
D3D9ShaderType ShaderStage,
14-
DxsoConstantBuffers BufferType,
15-
VkDeviceSize Size)
12+
D3D9DeviceEx* pDevice,
13+
D3D9ShaderType ShaderStage,
14+
D3D9ShaderResourceMapping::ConstantBuffers BufferType,
15+
VkDeviceSize Size)
1616
: D3D9ConstantBuffer(pDevice, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, GetShaderStage(ShaderStage),
17-
computeResourceSlotId(ShaderStage, DxsoBindingType::ConstantBuffer, BufferType),
17+
D3D9ShaderResourceMapping::computeCbvBinding(ShaderStage, BufferType),
1818
Size) {
1919

2020
}

src/d3d9/d3d9_constant_buffer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "../util/util_math.h"
88

99
#include "d3d9_include.h"
10+
#include "d3d9_shader.h"
1011

1112
namespace dxvk {
1213

@@ -24,7 +25,7 @@ namespace dxvk {
2425
D3D9ConstantBuffer(
2526
D3D9DeviceEx* pDevice,
2627
D3D9ShaderType ShaderStage,
27-
DxsoConstantBuffers BufferType,
28+
D3D9ShaderResourceMapping::ConstantBuffers BufferType,
2829
VkDeviceSize Size);
2930

3031
D3D9ConstantBuffer(

src/d3d9/d3d9_device.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,10 +3396,10 @@ namespace dxvk {
33963396
uint32_t byteOffset = cBufferOffset;
33973397

33983398
ctx->bindShader<VK_SHADER_STAGE_GEOMETRY_BIT>(std::move(shader));
3399-
ctx->bindResourceBufferView(VK_SHADER_STAGE_GEOMETRY_BIT, getSWVPBufferSlot(), std::move(bufferView));
3399+
ctx->bindResourceBufferView(VK_SHADER_STAGE_GEOMETRY_BIT, D3D9ShaderResourceMapping::getSWVPBufferSlot(), std::move(bufferView));
34003400
ctx->pushData(VK_SHADER_STAGE_GEOMETRY_BIT, 0u, sizeof(byteOffset), &byteOffset);
34013401
ctx->draw(1u, &draw);
3402-
ctx->bindResourceBufferView(VK_SHADER_STAGE_GEOMETRY_BIT, getSWVPBufferSlot(), nullptr);
3402+
ctx->bindResourceBufferView(VK_SHADER_STAGE_GEOMETRY_BIT, D3D9ShaderResourceMapping::getSWVPBufferSlot(), nullptr);
34033403
ctx->bindShader<VK_SHADER_STAGE_GEOMETRY_BIT>(nullptr);
34043404
});
34053405

@@ -6023,47 +6023,47 @@ namespace dxvk {
60236023

60246024
m_consts[uint32_t(D3D9ShaderType::VertexShader)].buffer = D3D9ConstantBuffer(this,
60256025
D3D9ShaderType::VertexShader,
6026-
DxsoConstantBuffers::VSConstantBuffer,
6026+
D3D9ShaderResourceMapping::ConstantBuffers::VSConstantBuffer,
60276027
DefaultConstantBufferSize);
60286028

60296029
m_consts[uint32_t(D3D9ShaderType::VertexShader)].swvp.intBuffer = D3D9ConstantBuffer(this,
60306030
D3D9ShaderType::VertexShader,
6031-
DxsoConstantBuffers::VSIntConstantBuffer,
6031+
D3D9ShaderResourceMapping::ConstantBuffers::VSIntConstantBuffer,
60326032
SmallConstantBufferSize);
60336033

60346034
m_consts[uint32_t(D3D9ShaderType::VertexShader)].swvp.boolBuffer = D3D9ConstantBuffer(this,
60356035
D3D9ShaderType::VertexShader,
6036-
DxsoConstantBuffers::VSBoolConstantBuffer,
6036+
D3D9ShaderResourceMapping::ConstantBuffers::VSBoolConstantBuffer,
60376037
SmallConstantBufferSize);
60386038

60396039
m_consts[uint32_t(D3D9ShaderType::PixelShader)].buffer = D3D9ConstantBuffer(this,
60406040
D3D9ShaderType::PixelShader,
6041-
DxsoConstantBuffers::PSConstantBuffer,
6041+
D3D9ShaderResourceMapping::ConstantBuffers::PSConstantBuffer,
60426042
DefaultConstantBufferSize);
60436043

60446044
m_vsClipPlanes = D3D9ConstantBuffer(this,
60456045
D3D9ShaderType::VertexShader,
6046-
DxsoConstantBuffers::VSClipPlanes,
6046+
D3D9ShaderResourceMapping::ConstantBuffers::VSClipPlanes,
60476047
caps::MaxClipPlanes * sizeof(D3D9ClipPlane));
60486048

60496049
m_vsFixedFunction = D3D9ConstantBuffer(this,
60506050
D3D9ShaderType::VertexShader,
6051-
DxsoConstantBuffers::VSFixedFunction,
6051+
D3D9ShaderResourceMapping::ConstantBuffers::VSFixedFunction,
60526052
sizeof(D3D9FixedFunctionVS));
60536053

60546054
m_psFixedFunction = D3D9ConstantBuffer(this,
60556055
D3D9ShaderType::PixelShader,
6056-
DxsoConstantBuffers::PSFixedFunction,
6056+
D3D9ShaderResourceMapping::ConstantBuffers::PSFixedFunction,
60576057
sizeof(D3D9FixedFunctionPS));
60586058

60596059
m_psShared = D3D9ConstantBuffer(this,
60606060
D3D9ShaderType::PixelShader,
6061-
DxsoConstantBuffers::PSShared,
6061+
D3D9ShaderResourceMapping::ConstantBuffers::VSVertexBlendData,
60626062
sizeof(D3D9SharedPS));
60636063

60646064
m_vsVertexBlend = D3D9ConstantBuffer(this,
60656065
D3D9ShaderType::VertexShader,
6066-
DxsoConstantBuffers::VSVertexBlendData,
6066+
D3D9ShaderResourceMapping::ConstantBuffers::VSVertexBlendData,
60676067
CanSWVP()
60686068
? sizeof(D3D9FixedFunctionVertexBlendDataSW)
60696069
: sizeof(D3D9FixedFunctionVertexBlendDataHW));
@@ -6073,7 +6073,7 @@ namespace dxvk {
60736073
m_specBuffer = D3D9ConstantBuffer(this,
60746074
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
60756075
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
6076-
getSpecConstantBufferSlot(),
6076+
D3D9ShaderResourceMapping::getSpecConstantBufferSlot(),
60776077
D3D9SpecializationInfo::UBOSize);
60786078
}
60796079
}
@@ -7435,9 +7435,8 @@ namespace dxvk {
74357435
void D3D9DeviceEx::BindSampler(DWORD Sampler) {
74367436
auto samplerInfo = RemapStateSamplerShader(Sampler);
74377437

7438-
const uint32_t slot = computeResourceSlotId(
7439-
samplerInfo.first, DxsoBindingType::Image,
7440-
samplerInfo.second);
7438+
const uint32_t slot = D3D9ShaderResourceMapping::computeTextureBinding(
7439+
samplerInfo.first, uint32_t(samplerInfo.second));
74417440

74427441
m_samplerBindCount++;
74437442

@@ -7523,8 +7522,8 @@ namespace dxvk {
75237522
void D3D9DeviceEx::BindTexture(DWORD StateSampler) {
75247523
auto shaderSampler = RemapStateSamplerShader(StateSampler);
75257524

7526-
uint32_t slot = computeResourceSlotId(shaderSampler.first,
7527-
DxsoBindingType::Image, uint32_t(shaderSampler.second));
7525+
uint32_t slot = D3D9ShaderResourceMapping::computeTextureBinding(shaderSampler.first,
7526+
uint32_t(shaderSampler.second));
75287527

75297528
const bool srgb =
75307529
m_state.samplerStates[StateSampler][D3DSAMP_SRGBTEXTURE] & 0x1;
@@ -7551,8 +7550,8 @@ namespace dxvk {
75517550
for (uint32_t i : bit::BitMask(cMask)) {
75527551
auto shaderSampler = RemapStateSamplerShader(i);
75537552

7554-
uint32_t slot = computeResourceSlotId(shaderSampler.first,
7555-
DxsoBindingType::Image, uint32_t(shaderSampler.second));
7553+
uint32_t slot = D3D9ShaderResourceMapping::computeTextureBinding(shaderSampler.first,
7554+
uint32_t(shaderSampler.second));
75567555

75577556
VkShaderStageFlags stage = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
75587557
ctx->bindResourceImageView(stage, slot, nullptr);
@@ -9032,12 +9031,10 @@ namespace dxvk {
90329031
EmitCs([
90339032
cSize = m_state.textures->size()
90349033
](DxvkContext* ctx) {
9035-
VkShaderStageFlags stage = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
9036-
90379034
for (uint32_t i = 0; i < cSize; i++) {
90389035
auto samplerInfo = RemapStateSamplerShader(DWORD(i));
9039-
uint32_t slot = computeResourceSlotId(samplerInfo.first, DxsoBindingType::Image, uint32_t(samplerInfo.second));
9040-
ctx->bindResourceImageView(stage, slot, nullptr);
9036+
uint32_t slot = D3D9ShaderResourceMapping::computeTextureBinding(samplerInfo.first, uint32_t(samplerInfo.second));
9037+
ctx->bindResourceImageView(GetShaderStage(samplerInfo.first), slot, nullptr);
90419038
}
90429039
});
90439040

src/d3d9/d3d9_fixed_function.cpp

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,12 @@ namespace dxvk {
480480

481481
spvModule.setDebugName (specBlock, "spec_state");
482482
spvModule.decorateDescriptorSet(specBlock, 0);
483-
spvModule.decorateBinding (specBlock, getSpecConstantBufferSlot());
483+
spvModule.decorateBinding (specBlock, D3D9ShaderResourceMapping::getSpecConstantBufferSlot());
484484

485485
auto& binding = bindings.emplace_back();
486486
binding.set = 0u;
487-
binding.binding = getSpecConstantBufferSlot();
488-
binding.resourceIndex = getSpecConstantBufferSlot();
487+
binding.binding = D3D9ShaderResourceMapping::getSpecConstantBufferSlot();
488+
binding.resourceIndex = D3D9ShaderResourceMapping::getSpecConstantBufferSlot();
489489
binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
490490
binding.access = VK_ACCESS_UNIFORM_READ_BIT;
491491
binding.flags.set(DxvkDescriptorFlag::UniformBuffer);
@@ -1700,9 +1700,8 @@ namespace dxvk {
17001700

17011701
m_module.setDebugName(m_vs.constantBuffer, "consts");
17021702

1703-
const uint32_t bindingId = computeResourceSlotId(
1704-
D3D9ShaderType::VertexShader, DxsoBindingType::ConstantBuffer,
1705-
DxsoConstantBuffers::VSFixedFunction);
1703+
const uint32_t bindingId = D3D9ShaderResourceMapping::computeCbvBinding(D3D9ShaderType::VertexShader,
1704+
D3D9ShaderResourceMapping::ConstantBuffers::VSFixedFunction);
17061705

17071706
m_module.decorateDescriptorSet(m_vs.constantBuffer, 0);
17081707
m_module.decorateBinding(m_vs.constantBuffer, bindingId);
@@ -1739,9 +1738,8 @@ namespace dxvk {
17391738

17401739
m_module.setDebugName(m_vs.vertexBlendData, "VertexBlendData");
17411740

1742-
const uint32_t bindingId = computeResourceSlotId(
1743-
D3D9ShaderType::VertexShader, DxsoBindingType::ConstantBuffer,
1744-
DxsoConstantBuffers::VSVertexBlendData);
1741+
const uint32_t bindingId = D3D9ShaderResourceMapping::computeCbvBinding(D3D9ShaderType::VertexShader,
1742+
D3D9ShaderResourceMapping::ConstantBuffers::VSVertexBlendData);
17451743

17461744
m_module.decorateDescriptorSet(m_vs.vertexBlendData, 0);
17471745
m_module.decorateBinding(m_vs.vertexBlendData, bindingId);
@@ -2445,9 +2443,8 @@ namespace dxvk {
24452443

24462444
m_module.setDebugName(m_ps.constantBuffer, "consts");
24472445

2448-
const uint32_t bindingId = computeResourceSlotId(
2449-
D3D9ShaderType::PixelShader, DxsoBindingType::ConstantBuffer,
2450-
DxsoConstantBuffers::PSFixedFunction);
2446+
const uint32_t bindingId = D3D9ShaderResourceMapping::computeCbvBinding(D3D9ShaderType::PixelShader,
2447+
D3D9ShaderResourceMapping::ConstantBuffers::PSFixedFunction);
24512448

24522449
m_module.decorateDescriptorSet(m_ps.constantBuffer, 0);
24532450
m_module.decorateBinding(m_ps.constantBuffer, bindingId);
@@ -2473,8 +2470,7 @@ namespace dxvk {
24732470

24742471
// Samplers
24752472
for (uint32_t i = 0; i < caps::TextureStageCount; i++) {
2476-
const uint32_t imageBindingId = computeResourceSlotId(D3D9ShaderType::PixelShader,
2477-
DxsoBindingType::Image, i);
2473+
const uint32_t imageBindingId = D3D9ShaderResourceMapping::computeTextureBinding(D3D9ShaderType::PixelShader, i);
24782474

24792475
auto& imageBinding = m_bindings.emplace_back();
24802476
imageBinding.set = 0u;
@@ -2545,9 +2541,8 @@ namespace dxvk {
25452541
void D3D9FFShaderCompiler::emitPsSharedConstants() {
25462542
m_ps.sharedState = GetSharedConstants(m_module);
25472543

2548-
const uint32_t bindingId = computeResourceSlotId(
2549-
m_shaderType, DxsoBindingType::ConstantBuffer,
2550-
PSShared);
2544+
const uint32_t bindingId = D3D9ShaderResourceMapping::computeCbvBinding(m_shaderType,
2545+
D3D9ShaderResourceMapping::ConstantBuffers::PSShared);
25512546

25522547
m_module.decorateDescriptorSet(m_ps.sharedState, 0);
25532548
m_module.decorateBinding(m_ps.sharedState, bindingId);
@@ -2585,10 +2580,8 @@ namespace dxvk {
25852580
m_module.decorate (clipPlaneStruct, spv::DecorationBlock);
25862581
m_module.memberDecorateOffset (clipPlaneStruct, 0, 0);
25872582

2588-
uint32_t bindingId = computeResourceSlotId(
2589-
D3D9ShaderType::VertexShader,
2590-
DxsoBindingType::ConstantBuffer,
2591-
DxsoConstantBuffers::VSClipPlanes);
2583+
const uint32_t bindingId = D3D9ShaderResourceMapping::computeCbvBinding(D3D9ShaderType::VertexShader,
2584+
D3D9ShaderResourceMapping::ConstantBuffers::VSClipPlanes);
25922585

25932586
m_module.setDebugName (clipPlaneBlock, "clip_info");
25942587
m_module.decorateDescriptorSet(clipPlaneBlock, 0);
@@ -2743,7 +2736,7 @@ namespace dxvk {
27432736
if (isVS) {
27442737
std::array<DxvkBindingInfo, 4> bindings;
27452738

2746-
constexpr uint32_t specConstantBufferBindingId = getSpecConstantBufferSlot();
2739+
constexpr uint32_t specConstantBufferBindingId = D3D9ShaderResourceMapping::getSpecConstantBufferSlot();
27472740
auto& specConstantBufferBinding = bindings[0];
27482741
specConstantBufferBinding.set = 0u;
27492742
specConstantBufferBinding.binding = specConstantBufferBindingId;
@@ -2752,9 +2745,8 @@ namespace dxvk {
27522745
specConstantBufferBinding.access = VK_ACCESS_UNIFORM_READ_BIT;
27532746
specConstantBufferBinding.flags.set(DxvkDescriptorFlag::UniformBuffer);
27542747

2755-
constexpr uint32_t fixedFunctionDataBindingId = computeResourceSlotId(
2756-
D3D9ShaderType::VertexShader, DxsoBindingType::ConstantBuffer,
2757-
DxsoConstantBuffers::VSFixedFunction);
2748+
constexpr uint32_t fixedFunctionDataBindingId = D3D9ShaderResourceMapping::computeCbvBinding(
2749+
D3D9ShaderType::VertexShader, D3D9ShaderResourceMapping::ConstantBuffers::VSFixedFunction);
27582750
auto& fixedFunctionDataBinding = bindings[1];
27592751
fixedFunctionDataBinding.set = 0u;
27602752
fixedFunctionDataBinding.binding = fixedFunctionDataBindingId;
@@ -2763,9 +2755,8 @@ namespace dxvk {
27632755
fixedFunctionDataBinding.access = VK_ACCESS_UNIFORM_READ_BIT;
27642756
fixedFunctionDataBinding.flags.set(DxvkDescriptorFlag::UniformBuffer);
27652757

2766-
constexpr uint32_t vertexBlendBindingId = computeResourceSlotId(
2767-
D3D9ShaderType::VertexShader, DxsoBindingType::ConstantBuffer,
2768-
DxsoConstantBuffers::VSVertexBlendData);
2758+
constexpr uint32_t vertexBlendBindingId = D3D9ShaderResourceMapping::computeCbvBinding(
2759+
D3D9ShaderType::VertexShader, D3D9ShaderResourceMapping::ConstantBuffers::VSVertexBlendData);
27692760
auto& vertexBlendBinding = bindings[2];
27702761
vertexBlendBinding.set = 0u;
27712762
vertexBlendBinding.binding = vertexBlendBindingId;
@@ -2774,9 +2765,8 @@ namespace dxvk {
27742765
vertexBlendBinding.access = VK_ACCESS_SHADER_READ_BIT;
27752766
vertexBlendBinding.flags.set(DxvkDescriptorFlag::UniformBuffer);
27762767

2777-
constexpr uint32_t clipPlanesBindingId = computeResourceSlotId(
2778-
D3D9ShaderType::VertexShader, DxsoBindingType::ConstantBuffer,
2779-
DxsoConstantBuffers::VSClipPlanes);
2768+
constexpr uint32_t clipPlanesBindingId = D3D9ShaderResourceMapping::computeCbvBinding(
2769+
D3D9ShaderType::VertexShader, D3D9ShaderResourceMapping::ConstantBuffers::VSClipPlanes);
27802770
auto& clipPlanesBinding = bindings[3];
27812771
clipPlanesBinding.set = 0u;
27822772
clipPlanesBinding.binding = clipPlanesBindingId;
@@ -2798,7 +2788,7 @@ namespace dxvk {
27982788
} else {
27992789
std::vector<DxvkBindingInfo> bindings;
28002790

2801-
constexpr uint32_t specConstantBufferBindingId = getSpecConstantBufferSlot();
2791+
constexpr uint32_t specConstantBufferBindingId = D3D9ShaderResourceMapping::getSpecConstantBufferSlot();
28022792
auto& specConstantBufferBinding = bindings.emplace_back();
28032793
specConstantBufferBinding.set = 0u;
28042794
specConstantBufferBinding.binding = specConstantBufferBindingId;
@@ -2807,9 +2797,8 @@ namespace dxvk {
28072797
specConstantBufferBinding.access = VK_ACCESS_UNIFORM_READ_BIT;
28082798
specConstantBufferBinding.flags.set(DxvkDescriptorFlag::UniformBuffer);
28092799

2810-
constexpr uint32_t fixedFunctionDataBindingId = computeResourceSlotId(
2811-
D3D9ShaderType::PixelShader, DxsoBindingType::ConstantBuffer,
2812-
DxsoConstantBuffers::PSFixedFunction);
2800+
constexpr uint32_t fixedFunctionDataBindingId = D3D9ShaderResourceMapping::computeCbvBinding(
2801+
D3D9ShaderType::PixelShader, D3D9ShaderResourceMapping::ConstantBuffers::PSFixedFunction);
28132802
auto& fixedFunctionDataBinding = bindings.emplace_back();
28142803
fixedFunctionDataBinding.set = 0u;
28152804
fixedFunctionDataBinding.binding = fixedFunctionDataBindingId;
@@ -2818,9 +2807,8 @@ namespace dxvk {
28182807
fixedFunctionDataBinding.access = VK_ACCESS_UNIFORM_READ_BIT;
28192808
fixedFunctionDataBinding.flags.set(DxvkDescriptorFlag::UniformBuffer);
28202809

2821-
constexpr uint32_t sharedDataBindingId = computeResourceSlotId(
2822-
D3D9ShaderType::PixelShader, DxsoBindingType::ConstantBuffer,
2823-
DxsoConstantBuffers::PSShared);
2810+
constexpr uint32_t sharedDataBindingId = D3D9ShaderResourceMapping::computeCbvBinding(
2811+
D3D9ShaderType::PixelShader, D3D9ShaderResourceMapping::ConstantBuffers::PSShared);
28242812
auto& sharedDataBinding = bindings.emplace_back();
28252813
sharedDataBinding.set = 0u;
28262814
sharedDataBinding.binding = sharedDataBindingId;
@@ -2829,10 +2817,7 @@ namespace dxvk {
28292817
sharedDataBinding.access = VK_ACCESS_SHADER_READ_BIT;
28302818
sharedDataBinding.flags.set(DxvkDescriptorFlag::UniformBuffer);
28312819

2832-
constexpr uint32_t textureBindingId = computeResourceSlotId(
2833-
D3D9ShaderType::PixelShader,
2834-
DxsoBindingType::Image,
2835-
0);
2820+
constexpr uint32_t textureBindingId = D3D9ShaderResourceMapping::computeTextureBinding(D3D9ShaderType::PixelShader, 0u);
28362821
auto& textureBinding = bindings.emplace_back();
28372822
textureBinding.set = 0u;
28382823
textureBinding.binding = textureBindingId;
@@ -2842,10 +2827,7 @@ namespace dxvk {
28422827
textureBinding.descriptorCount = caps::TextureStageCount;
28432828

28442829
for (uint32_t i = 0; i < caps::TextureStageCount; i++) {
2845-
uint32_t samplerBindingId = computeResourceSlotId(
2846-
D3D9ShaderType::PixelShader,
2847-
DxsoBindingType::Image,
2848-
i);
2830+
uint32_t samplerBindingId = D3D9ShaderResourceMapping::computeTextureBinding(D3D9ShaderType::PixelShader, i);
28492831

28502832
auto& samplerBinding = bindings.emplace_back();
28512833
samplerBinding.resourceIndex = samplerBindingId;

0 commit comments

Comments
 (0)