1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-29 01:24:11 +01:00

[dxso+d3d9] Clean up texture slots

This commit is contained in:
Robin Kertels 2021-11-14 14:09:28 +01:00 committed by Joshie
parent b672c07a93
commit 39039f9ac8
7 changed files with 22 additions and 14 deletions

View File

@ -29,4 +29,7 @@ namespace dxvk::caps {
constexpr uint32_t MaxEnabledLights = 8;
constexpr uint32_t MaxTexturesVS = 4;
constexpr uint32_t MaxTexturesPS = 16;
}

View File

@ -3721,7 +3721,7 @@ namespace dxvk {
// We need to check our ops and disable respective stages.
// Given we have transition from a null resource to
// a valid resource or vice versa.
if (StateSampler < 16) {
if (StateSampler < caps::MaxTexturesPS) {
const uint32_t offset = StateSampler * 2;
const uint32_t textureType = newTexture != nullptr
? uint32_t(newTexture->GetType() - D3DRTYPE_TEXTURE)
@ -6101,7 +6101,7 @@ namespace dxvk {
if (likely(UseProgrammablePS())) {
UploadConstants<DxsoProgramTypes::PixelShader>();
const uint32_t psTextureMask = usedTextureMask & ((1u << 16u) - 1u);
const uint32_t psTextureMask = usedTextureMask & ((1u << caps::MaxTexturesPS) - 1u);
const uint32_t fetch4 = m_fetch4 & psTextureMask;
const uint32_t projected = m_projectionBitfield & psTextureMask;

View File

@ -1,5 +1,6 @@
#include "d3d9_shader.h"
#include "d3d9_caps.h"
#include "d3d9_device.h"
#include "d3d9_util.h"
@ -63,7 +64,7 @@ namespace dxvk {
// do an or per-draw in the device.
// We shift by 17 because 16 ps samplers + 1 dmap (tess)
if (ShaderStage == VK_SHADER_STAGE_VERTEX_BIT)
m_usedSamplers <<= 17;
m_usedSamplers <<= caps::MaxTexturesPS + 1;
m_usedRTs = pModule->usedRTs();

View File

@ -18,7 +18,7 @@ namespace dxvk {
static constexpr uint32_t RenderStateCount = 256;
static constexpr uint32_t SamplerStateCount = D3DSAMP_DMAPOFFSET + 1;
static constexpr uint32_t SamplerCount = 21;
static constexpr uint32_t SamplerCount = caps::MaxTexturesPS + caps::MaxTexturesVS + 1;
static constexpr uint32_t TextureStageStateCount = DXVK_TSS_COUNT;
namespace hacks::PointSize {

View File

@ -1,5 +1,6 @@
#include "d3d9_stateblock.h"
#include "d3d9_caps.h"
#include "d3d9_device.h"
#include "d3d9_vertex_declaration.h"
#include "d3d9_buffer.h"
@ -375,7 +376,7 @@ namespace dxvk {
void D3D9StateBlock::CapturePixelSamplerStates() {
m_captures.flags.set(D3D9CapturedStateFlag::SamplerStates);
for (uint32_t i = 0; i < 17; i++) {
for (uint32_t i = 0; i < caps::MaxTexturesPS + 1; i++) {
m_captures.samplers.set(i, true);
m_captures.samplerStates[i].set(D3DSAMP_ADDRESSU, true);
@ -458,7 +459,7 @@ namespace dxvk {
void D3D9StateBlock::CaptureVertexSamplerStates() {
m_captures.flags.set(D3D9CapturedStateFlag::SamplerStates);
for (uint32_t i = 17; i < SamplerCount; i++) {
for (uint32_t i = caps::MaxTexturesPS + 1; i < SamplerCount; i++) {
m_captures.samplers.set(i, true);
m_captures.samplerStates[i].set(D3DSAMP_DMAPOFFSET, true);
}

View File

@ -1,6 +1,7 @@
#pragma once
#include "d3d9_include.h"
#include "d3d9_caps.h"
#include "d3d9_format.h"
@ -46,25 +47,25 @@ namespace dxvk {
}
inline bool InvalidSampler(DWORD Sampler) {
if (Sampler > 15 && Sampler < D3DDMAPSAMPLER)
if (Sampler >= caps::MaxTexturesPS && Sampler < D3DDMAPSAMPLER)
return true;
if (Sampler > D3DVERTEXTEXTURESAMPLER3)
return true;
return false;
}
inline DWORD RemapSamplerState(DWORD Sampler) {
if (Sampler >= D3DDMAPSAMPLER)
Sampler = 16 + (Sampler - D3DDMAPSAMPLER);
Sampler = caps::MaxTexturesPS + (Sampler - D3DDMAPSAMPLER);
return Sampler;
}
inline std::pair<DxsoProgramType, DWORD> RemapStateSamplerShader(DWORD Sampler) {
if (Sampler >= 17)
return std::make_pair(DxsoProgramTypes::VertexShader, Sampler - 17);
if (Sampler >= caps::MaxTexturesPS + 1)
return std::make_pair(DxsoProgramTypes::VertexShader, Sampler - caps::MaxTexturesPS - 1);
return std::make_pair(DxsoProgramTypes::PixelShader, Sampler);
}

View File

@ -5,6 +5,8 @@
#include "dxso_common.h"
#include "dxso_decoder.h"
#include "../d3d9/d3d9_caps.h"
namespace dxvk {
enum class DxsoBindingType : uint32_t {
@ -38,17 +40,17 @@ namespace dxvk {
DxsoProgramType shaderStage,
DxsoBindingType bindingType,
uint32_t bindingIndex) {
const uint32_t stageOffset = (VSCount + 4) * uint32_t(shaderStage);
const uint32_t stageOffset = (DxsoConstantBuffers::VSCount + caps::MaxTexturesVS) * uint32_t(shaderStage);
if (bindingType == DxsoBindingType::ConstantBuffer)
return bindingIndex + stageOffset;
else // if (bindingType == DxsoBindingType::Image)
return bindingIndex + stageOffset + (shaderStage == DxsoProgramType::PixelShader ? PSCount : VSCount);
return bindingIndex + stageOffset + (shaderStage == DxsoProgramType::PixelShader ? DxsoConstantBuffers::PSCount : DxsoConstantBuffers::VSCount);
}
// TODO: Intergrate into compute resource slot ID/refactor all of this?
constexpr uint32_t getSWVPBufferSlot() {
return 27; // From last pixel shader slot, above.
return DxsoConstantBuffers::VSCount + caps::MaxTexturesVS + DxsoConstantBuffers::PSCount + caps::MaxTexturesPS + 1; // From last pixel shader slot, above.
}
uint32_t RegisterLinkerSlot(DxsoSemantic semantic);