1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-19 05:52:11 +01:00

[d3d9] Use new bitset helper + tzcnt for stateblocks

This commit is contained in:
Joshua Ashton 2019-12-17 01:05:32 +00:00 committed by Philip Rebohle
parent b99b1d153a
commit 312905e8a3
2 changed files with 251 additions and 223 deletions

View File

@ -73,7 +73,7 @@ namespace dxvk {
m_state.renderStates[State] = Value;
m_captures.flags.set(D3D9CapturedStateFlag::RenderStates);
m_captures.renderStates[State] = true;
m_captures.renderStates.set(State, true);
return D3D_OK;
}
@ -85,8 +85,8 @@ namespace dxvk {
m_state.samplerStates[StateSampler][Type] = Value;
m_captures.flags.set(D3D9CapturedStateFlag::SamplerStates);
m_captures.samplers[StateSampler] = true;
m_captures.samplerStates[StateSampler][Type] = true;
m_captures.samplers.set(StateSampler, true);
m_captures.samplerStates[StateSampler].set(Type, true);
return D3D_OK;
}
@ -102,7 +102,7 @@ namespace dxvk {
m_state.vertexBuffers[StreamNumber].stride = Stride;
m_captures.flags.set(D3D9CapturedStateFlag::VertexBuffers);
m_captures.vertexBuffers[StreamNumber] = true;
m_captures.vertexBuffers.set(StreamNumber, true);
return D3D_OK;
}
@ -111,7 +111,7 @@ namespace dxvk {
m_state.streamFreq[StreamNumber] = Setting;
m_captures.flags.set(D3D9CapturedStateFlag::StreamFreq);
m_captures.streamFreq[StreamNumber] = true;
m_captures.streamFreq.set(StreamNumber, true);
return D3D_OK;
}
@ -120,7 +120,7 @@ namespace dxvk {
TextureChangePrivate(m_state.textures[StateSampler], pTexture);
m_captures.flags.set(D3D9CapturedStateFlag::Textures);
m_captures.textures[StateSampler] = true;
m_captures.textures.set(StateSampler, true);
return D3D_OK;
}
@ -153,7 +153,7 @@ namespace dxvk {
m_state.transforms[idx] = ConvertMatrix(pMatrix);
m_captures.flags.set(D3D9CapturedStateFlag::Transforms);
m_captures.transforms.set(idx);
m_captures.transforms.set(idx, true);
return D3D_OK;
}
@ -165,8 +165,8 @@ namespace dxvk {
m_state.textureStages[Stage][Type] = Value;
m_captures.flags.set(D3D9CapturedStateFlag::TextureStages);
m_captures.textureStages[Stage] = true;
m_captures.textureStageStates[Stage][Type] = true;
m_captures.textureStages.set(Stage, true);
m_captures.textureStageStates[Stage].set(Type, true);
return D3D_OK;
}
@ -175,7 +175,7 @@ namespace dxvk {
m_state.transforms[idx] = ConvertMatrix(pMatrix) * m_state.transforms[idx];
m_captures.flags.set(D3D9CapturedStateFlag::Transforms);
m_captures.transforms.set(idx);
m_captures.transforms.set(idx, true);
return D3D_OK;
}
@ -201,7 +201,7 @@ namespace dxvk {
m_state.clipPlanes[Index].coeff[i] = pPlane[i];
m_captures.flags.set(D3D9CapturedStateFlag::ClipPlanes);
m_captures.clipPlanes[Index] = true;
m_captures.clipPlanes.set(Index, true);
return D3D_OK;
}
@ -301,67 +301,67 @@ namespace dxvk {
void D3D9StateBlock::CapturePixelRenderStates() {
m_captures.flags.set(D3D9CapturedStateFlag::RenderStates);
m_captures.renderStates[D3DRS_ZENABLE] = true;
m_captures.renderStates[D3DRS_FILLMODE] = true;
m_captures.renderStates[D3DRS_SHADEMODE] = true;
m_captures.renderStates[D3DRS_ZWRITEENABLE] = true;
m_captures.renderStates[D3DRS_ALPHATESTENABLE] = true;
m_captures.renderStates[D3DRS_LASTPIXEL] = true;
m_captures.renderStates[D3DRS_SRCBLEND] = true;
m_captures.renderStates[D3DRS_DESTBLEND] = true;
m_captures.renderStates[D3DRS_ZFUNC] = true;
m_captures.renderStates[D3DRS_ALPHAREF] = true;
m_captures.renderStates[D3DRS_ALPHAFUNC] = true;
m_captures.renderStates[D3DRS_DITHERENABLE] = true;
m_captures.renderStates[D3DRS_FOGSTART] = true;
m_captures.renderStates[D3DRS_FOGEND] = true;
m_captures.renderStates[D3DRS_FOGDENSITY] = true;
m_captures.renderStates[D3DRS_ALPHABLENDENABLE] = true;
m_captures.renderStates[D3DRS_DEPTHBIAS] = true;
m_captures.renderStates[D3DRS_STENCILENABLE] = true;
m_captures.renderStates[D3DRS_STENCILFAIL] = true;
m_captures.renderStates[D3DRS_STENCILZFAIL] = true;
m_captures.renderStates[D3DRS_STENCILPASS] = true;
m_captures.renderStates[D3DRS_STENCILFUNC] = true;
m_captures.renderStates[D3DRS_STENCILREF] = true;
m_captures.renderStates[D3DRS_STENCILMASK] = true;
m_captures.renderStates[D3DRS_STENCILWRITEMASK] = true;
m_captures.renderStates[D3DRS_TEXTUREFACTOR] = true;
m_captures.renderStates[D3DRS_WRAP0] = true;
m_captures.renderStates[D3DRS_WRAP1] = true;
m_captures.renderStates[D3DRS_WRAP2] = true;
m_captures.renderStates[D3DRS_WRAP3] = true;
m_captures.renderStates[D3DRS_WRAP4] = true;
m_captures.renderStates[D3DRS_WRAP5] = true;
m_captures.renderStates[D3DRS_WRAP6] = true;
m_captures.renderStates[D3DRS_WRAP7] = true;
m_captures.renderStates[D3DRS_WRAP8] = true;
m_captures.renderStates[D3DRS_WRAP9] = true;
m_captures.renderStates[D3DRS_WRAP10] = true;
m_captures.renderStates[D3DRS_WRAP11] = true;
m_captures.renderStates[D3DRS_WRAP12] = true;
m_captures.renderStates[D3DRS_WRAP13] = true;
m_captures.renderStates[D3DRS_WRAP14] = true;
m_captures.renderStates[D3DRS_WRAP15] = true;
m_captures.renderStates[D3DRS_COLORWRITEENABLE] = true;
m_captures.renderStates[D3DRS_BLENDOP] = true;
m_captures.renderStates[D3DRS_SCISSORTESTENABLE] = true;
m_captures.renderStates[D3DRS_SLOPESCALEDEPTHBIAS] = true;
m_captures.renderStates[D3DRS_ANTIALIASEDLINEENABLE] = true;
m_captures.renderStates[D3DRS_TWOSIDEDSTENCILMODE] = true;
m_captures.renderStates[D3DRS_CCW_STENCILFAIL] = true;
m_captures.renderStates[D3DRS_CCW_STENCILZFAIL] = true;
m_captures.renderStates[D3DRS_CCW_STENCILPASS] = true;
m_captures.renderStates[D3DRS_CCW_STENCILFUNC] = true;
m_captures.renderStates[D3DRS_COLORWRITEENABLE1] = true;
m_captures.renderStates[D3DRS_COLORWRITEENABLE2] = true;
m_captures.renderStates[D3DRS_COLORWRITEENABLE3] = true;
m_captures.renderStates[D3DRS_BLENDFACTOR] = true;
m_captures.renderStates[D3DRS_SRGBWRITEENABLE] = true;
m_captures.renderStates[D3DRS_SEPARATEALPHABLENDENABLE] = true;
m_captures.renderStates[D3DRS_SRCBLENDALPHA] = true;
m_captures.renderStates[D3DRS_DESTBLENDALPHA] = true;
m_captures.renderStates[D3DRS_BLENDOPALPHA] = true;
m_captures.renderStates.set(D3DRS_ZENABLE, true);
m_captures.renderStates.set(D3DRS_FILLMODE, true);
m_captures.renderStates.set(D3DRS_SHADEMODE, true);
m_captures.renderStates.set(D3DRS_ZWRITEENABLE, true);
m_captures.renderStates.set(D3DRS_ALPHATESTENABLE, true);
m_captures.renderStates.set(D3DRS_LASTPIXEL, true);
m_captures.renderStates.set(D3DRS_SRCBLEND, true);
m_captures.renderStates.set(D3DRS_DESTBLEND, true);
m_captures.renderStates.set(D3DRS_ZFUNC, true);
m_captures.renderStates.set(D3DRS_ALPHAREF, true);
m_captures.renderStates.set(D3DRS_ALPHAFUNC, true);
m_captures.renderStates.set(D3DRS_DITHERENABLE, true);
m_captures.renderStates.set(D3DRS_FOGSTART, true);
m_captures.renderStates.set(D3DRS_FOGEND, true);
m_captures.renderStates.set(D3DRS_FOGDENSITY, true);
m_captures.renderStates.set(D3DRS_ALPHABLENDENABLE, true);
m_captures.renderStates.set(D3DRS_DEPTHBIAS, true);
m_captures.renderStates.set(D3DRS_STENCILENABLE, true);
m_captures.renderStates.set(D3DRS_STENCILFAIL, true);
m_captures.renderStates.set(D3DRS_STENCILZFAIL, true);
m_captures.renderStates.set(D3DRS_STENCILPASS, true);
m_captures.renderStates.set(D3DRS_STENCILFUNC, true);
m_captures.renderStates.set(D3DRS_STENCILREF, true);
m_captures.renderStates.set(D3DRS_STENCILMASK, true);
m_captures.renderStates.set(D3DRS_STENCILWRITEMASK, true);
m_captures.renderStates.set(D3DRS_TEXTUREFACTOR, true);
m_captures.renderStates.set(D3DRS_WRAP0, true);
m_captures.renderStates.set(D3DRS_WRAP1, true);
m_captures.renderStates.set(D3DRS_WRAP2, true);
m_captures.renderStates.set(D3DRS_WRAP3, true);
m_captures.renderStates.set(D3DRS_WRAP4, true);
m_captures.renderStates.set(D3DRS_WRAP5, true);
m_captures.renderStates.set(D3DRS_WRAP6, true);
m_captures.renderStates.set(D3DRS_WRAP7, true);
m_captures.renderStates.set(D3DRS_WRAP8, true);
m_captures.renderStates.set(D3DRS_WRAP9, true);
m_captures.renderStates.set(D3DRS_WRAP10, true);
m_captures.renderStates.set(D3DRS_WRAP11, true);
m_captures.renderStates.set(D3DRS_WRAP12, true);
m_captures.renderStates.set(D3DRS_WRAP13, true);
m_captures.renderStates.set(D3DRS_WRAP14, true);
m_captures.renderStates.set(D3DRS_WRAP15, true);
m_captures.renderStates.set(D3DRS_COLORWRITEENABLE, true);
m_captures.renderStates.set(D3DRS_BLENDOP, true);
m_captures.renderStates.set(D3DRS_SCISSORTESTENABLE, true);
m_captures.renderStates.set(D3DRS_SLOPESCALEDEPTHBIAS, true);
m_captures.renderStates.set(D3DRS_ANTIALIASEDLINEENABLE, true);
m_captures.renderStates.set(D3DRS_TWOSIDEDSTENCILMODE, true);
m_captures.renderStates.set(D3DRS_CCW_STENCILFAIL, true);
m_captures.renderStates.set(D3DRS_CCW_STENCILZFAIL, true);
m_captures.renderStates.set(D3DRS_CCW_STENCILPASS, true);
m_captures.renderStates.set(D3DRS_CCW_STENCILFUNC, true);
m_captures.renderStates.set(D3DRS_COLORWRITEENABLE1, true);
m_captures.renderStates.set(D3DRS_COLORWRITEENABLE2, true);
m_captures.renderStates.set(D3DRS_COLORWRITEENABLE3, true);
m_captures.renderStates.set(D3DRS_BLENDFACTOR, true);
m_captures.renderStates.set(D3DRS_SRGBWRITEENABLE, true);
m_captures.renderStates.set(D3DRS_SEPARATEALPHABLENDENABLE, true);
m_captures.renderStates.set(D3DRS_SRCBLENDALPHA, true);
m_captures.renderStates.set(D3DRS_DESTBLENDALPHA, true);
m_captures.renderStates.set(D3DRS_BLENDOPALPHA, true);
}
@ -369,20 +369,20 @@ namespace dxvk {
m_captures.flags.set(D3D9CapturedStateFlag::SamplerStates);
for (uint32_t i = 0; i < 17; i++) {
m_captures.samplers[i] = true;
m_captures.samplers.set(i, true);
m_captures.samplerStates[i][D3DSAMP_ADDRESSU] = true;
m_captures.samplerStates[i][D3DSAMP_ADDRESSV] = true;
m_captures.samplerStates[i][D3DSAMP_ADDRESSW] = true;
m_captures.samplerStates[i][D3DSAMP_BORDERCOLOR] = true;
m_captures.samplerStates[i][D3DSAMP_MAGFILTER] = true;
m_captures.samplerStates[i][D3DSAMP_MINFILTER] = true;
m_captures.samplerStates[i][D3DSAMP_MIPFILTER] = true;
m_captures.samplerStates[i][D3DSAMP_MIPMAPLODBIAS] = true;
m_captures.samplerStates[i][D3DSAMP_MAXMIPLEVEL] = true;
m_captures.samplerStates[i][D3DSAMP_MAXANISOTROPY] = true;
m_captures.samplerStates[i][D3DSAMP_SRGBTEXTURE] = true;
m_captures.samplerStates[i][D3DSAMP_ELEMENTINDEX] = true;
m_captures.samplerStates[i].set(D3DSAMP_ADDRESSU, true);
m_captures.samplerStates[i].set(D3DSAMP_ADDRESSV, true);
m_captures.samplerStates[i].set(D3DSAMP_ADDRESSW, true);
m_captures.samplerStates[i].set(D3DSAMP_BORDERCOLOR, true);
m_captures.samplerStates[i].set(D3DSAMP_MAGFILTER, true);
m_captures.samplerStates[i].set(D3DSAMP_MINFILTER, true);
m_captures.samplerStates[i].set(D3DSAMP_MIPFILTER, true);
m_captures.samplerStates[i].set(D3DSAMP_MIPMAPLODBIAS, true);
m_captures.samplerStates[i].set(D3DSAMP_MAXMIPLEVEL, true);
m_captures.samplerStates[i].set(D3DSAMP_MAXANISOTROPY, true);
m_captures.samplerStates[i].set(D3DSAMP_SRGBTEXTURE, true);
m_captures.samplerStates[i].set(D3DSAMP_ELEMENTINDEX, true);
}
}
@ -391,60 +391,60 @@ namespace dxvk {
m_captures.flags.set(D3D9CapturedStateFlag::PixelShader);
m_captures.flags.set(D3D9CapturedStateFlag::PsConstants);
m_captures.psConsts.fConsts.flip();
m_captures.psConsts.iConsts.flip();
m_captures.psConsts.bConsts.flip();
m_captures.psConsts.fConsts.setAll();
m_captures.psConsts.iConsts.setAll();
m_captures.psConsts.bConsts.setAll();
}
void D3D9StateBlock::CaptureVertexRenderStates() {
m_captures.flags.set(D3D9CapturedStateFlag::RenderStates);
m_captures.renderStates[D3DRS_CULLMODE] = true;
m_captures.renderStates[D3DRS_FOGENABLE] = true;
m_captures.renderStates[D3DRS_FOGCOLOR] = true;
m_captures.renderStates[D3DRS_FOGTABLEMODE] = true;
m_captures.renderStates[D3DRS_FOGSTART] = true;
m_captures.renderStates[D3DRS_FOGEND] = true;
m_captures.renderStates[D3DRS_FOGDENSITY] = true;
m_captures.renderStates[D3DRS_RANGEFOGENABLE] = true;
m_captures.renderStates[D3DRS_AMBIENT] = true;
m_captures.renderStates[D3DRS_COLORVERTEX] = true;
m_captures.renderStates[D3DRS_FOGVERTEXMODE] = true;
m_captures.renderStates[D3DRS_CLIPPING] = true;
m_captures.renderStates[D3DRS_LIGHTING] = true;
m_captures.renderStates[D3DRS_LOCALVIEWER] = true;
m_captures.renderStates[D3DRS_EMISSIVEMATERIALSOURCE] = true;
m_captures.renderStates[D3DRS_AMBIENTMATERIALSOURCE] = true;
m_captures.renderStates[D3DRS_DIFFUSEMATERIALSOURCE] = true;
m_captures.renderStates[D3DRS_SPECULARMATERIALSOURCE] = true;
m_captures.renderStates[D3DRS_VERTEXBLEND] = true;
m_captures.renderStates[D3DRS_CLIPPLANEENABLE] = true;
m_captures.renderStates[D3DRS_POINTSIZE] = true;
m_captures.renderStates[D3DRS_POINTSIZE_MIN] = true;
m_captures.renderStates[D3DRS_POINTSPRITEENABLE] = true;
m_captures.renderStates[D3DRS_POINTSCALEENABLE] = true;
m_captures.renderStates[D3DRS_POINTSCALE_A] = true;
m_captures.renderStates[D3DRS_POINTSCALE_B] = true;
m_captures.renderStates[D3DRS_POINTSCALE_C] = true;
m_captures.renderStates[D3DRS_MULTISAMPLEANTIALIAS] = true;
m_captures.renderStates[D3DRS_MULTISAMPLEMASK] = true;
m_captures.renderStates[D3DRS_PATCHEDGESTYLE] = true;
m_captures.renderStates[D3DRS_POINTSIZE_MAX] = true;
m_captures.renderStates[D3DRS_INDEXEDVERTEXBLENDENABLE] = true;
m_captures.renderStates[D3DRS_TWEENFACTOR] = true;
m_captures.renderStates[D3DRS_POSITIONDEGREE] = true;
m_captures.renderStates[D3DRS_NORMALDEGREE] = true;
m_captures.renderStates[D3DRS_MINTESSELLATIONLEVEL] = true;
m_captures.renderStates[D3DRS_MAXTESSELLATIONLEVEL] = true;
m_captures.renderStates[D3DRS_ADAPTIVETESS_X] = true;
m_captures.renderStates[D3DRS_ADAPTIVETESS_Y] = true;
m_captures.renderStates[D3DRS_ADAPTIVETESS_Z] = true;
m_captures.renderStates[D3DRS_ADAPTIVETESS_W] = true;
m_captures.renderStates[D3DRS_ENABLEADAPTIVETESSELLATION] = true;
m_captures.renderStates[D3DRS_NORMALIZENORMALS] = true;
m_captures.renderStates[D3DRS_SPECULARENABLE] = true;
m_captures.renderStates[D3DRS_SHADEMODE] = true;
m_captures.renderStates.set(D3DRS_CULLMODE, true);
m_captures.renderStates.set(D3DRS_FOGENABLE, true);
m_captures.renderStates.set(D3DRS_FOGCOLOR, true);
m_captures.renderStates.set(D3DRS_FOGTABLEMODE, true);
m_captures.renderStates.set(D3DRS_FOGSTART, true);
m_captures.renderStates.set(D3DRS_FOGEND, true);
m_captures.renderStates.set(D3DRS_FOGDENSITY, true);
m_captures.renderStates.set(D3DRS_RANGEFOGENABLE, true);
m_captures.renderStates.set(D3DRS_AMBIENT, true);
m_captures.renderStates.set(D3DRS_COLORVERTEX, true);
m_captures.renderStates.set(D3DRS_FOGVERTEXMODE, true);
m_captures.renderStates.set(D3DRS_CLIPPING, true);
m_captures.renderStates.set(D3DRS_LIGHTING, true);
m_captures.renderStates.set(D3DRS_LOCALVIEWER, true);
m_captures.renderStates.set(D3DRS_EMISSIVEMATERIALSOURCE, true);
m_captures.renderStates.set(D3DRS_AMBIENTMATERIALSOURCE, true);
m_captures.renderStates.set(D3DRS_DIFFUSEMATERIALSOURCE, true);
m_captures.renderStates.set(D3DRS_SPECULARMATERIALSOURCE, true);
m_captures.renderStates.set(D3DRS_VERTEXBLEND, true);
m_captures.renderStates.set(D3DRS_CLIPPLANEENABLE, true);
m_captures.renderStates.set(D3DRS_POINTSIZE, true);
m_captures.renderStates.set(D3DRS_POINTSIZE_MIN, true);
m_captures.renderStates.set(D3DRS_POINTSPRITEENABLE, true);
m_captures.renderStates.set(D3DRS_POINTSCALEENABLE, true);
m_captures.renderStates.set(D3DRS_POINTSCALE_A, true);
m_captures.renderStates.set(D3DRS_POINTSCALE_B, true);
m_captures.renderStates.set(D3DRS_POINTSCALE_C, true);
m_captures.renderStates.set(D3DRS_MULTISAMPLEANTIALIAS, true);
m_captures.renderStates.set(D3DRS_MULTISAMPLEMASK, true);
m_captures.renderStates.set(D3DRS_PATCHEDGESTYLE, true);
m_captures.renderStates.set(D3DRS_POINTSIZE_MAX, true);
m_captures.renderStates.set(D3DRS_INDEXEDVERTEXBLENDENABLE, true);
m_captures.renderStates.set(D3DRS_TWEENFACTOR, true);
m_captures.renderStates.set(D3DRS_POSITIONDEGREE, true);
m_captures.renderStates.set(D3DRS_NORMALDEGREE, true);
m_captures.renderStates.set(D3DRS_MINTESSELLATIONLEVEL, true);
m_captures.renderStates.set(D3DRS_MAXTESSELLATIONLEVEL, true);
m_captures.renderStates.set(D3DRS_ADAPTIVETESS_X, true);
m_captures.renderStates.set(D3DRS_ADAPTIVETESS_Y, true);
m_captures.renderStates.set(D3DRS_ADAPTIVETESS_Z, true);
m_captures.renderStates.set(D3DRS_ADAPTIVETESS_W, true);
m_captures.renderStates.set(D3DRS_ENABLEADAPTIVETESSELLATION, true);
m_captures.renderStates.set(D3DRS_NORMALIZENORMALS, true);
m_captures.renderStates.set(D3DRS_SPECULARENABLE, true);
m_captures.renderStates.set(D3DRS_SHADEMODE, true);
}
@ -452,8 +452,8 @@ namespace dxvk {
m_captures.flags.set(D3D9CapturedStateFlag::SamplerStates);
for (uint32_t i = 17; i < SamplerCount; i++) {
m_captures.samplers[i] = true;
m_captures.samplerStates[i][D3DSAMP_DMAPOFFSET] = true;
m_captures.samplers.set(i, true);
m_captures.samplerStates[i].set(D3DSAMP_DMAPOFFSET, true);
}
}
@ -462,9 +462,9 @@ namespace dxvk {
m_captures.flags.set(D3D9CapturedStateFlag::VertexShader);
m_captures.flags.set(D3D9CapturedStateFlag::VsConstants);
m_captures.vsConsts.fConsts.flip();
m_captures.vsConsts.iConsts.flip();
m_captures.vsConsts.bConsts.flip();
m_captures.vsConsts.fConsts.setAll();
m_captures.vsConsts.iConsts.setAll();
m_captures.vsConsts.bConsts.setAll();
}
@ -475,9 +475,9 @@ namespace dxvk {
CapturePixelShaderStates();
m_captures.flags.set(D3D9CapturedStateFlag::TextureStages);
m_captures.textureStages.flip();
m_captures.textureStages.setAll();
for (auto& stage : m_captures.textureStageStates)
stage.flip();
stage.setAll();
}
if (Type == D3D9StateBlockType::VertexState || Type == D3D9StateBlockType::All) {
@ -489,25 +489,25 @@ namespace dxvk {
m_captures.flags.set(D3D9CapturedStateFlag::StreamFreq);
for (uint32_t i = 0; i < caps::MaxStreams; i++)
m_captures.streamFreq[i] = true;
m_captures.streamFreq.set(i, true);
}
if (Type == D3D9StateBlockType::All) {
m_captures.flags.set(D3D9CapturedStateFlag::Textures);
m_captures.textures.flip();
m_captures.textures.setAll();
m_captures.flags.set(D3D9CapturedStateFlag::VertexBuffers);
m_captures.vertexBuffers.flip();
m_captures.vertexBuffers.setAll();
m_captures.flags.set(D3D9CapturedStateFlag::Indices);
m_captures.flags.set(D3D9CapturedStateFlag::Viewport);
m_captures.flags.set(D3D9CapturedStateFlag::ScissorRect);
m_captures.flags.set(D3D9CapturedStateFlag::ClipPlanes);
m_captures.clipPlanes.flip();
m_captures.clipPlanes.setAll();
m_captures.flags.set(D3D9CapturedStateFlag::Transforms);
m_captures.transforms.flip();
m_captures.transforms.setAll();
m_captures.flags.set(D3D9CapturedStateFlag::Material);
}

View File

@ -4,6 +4,8 @@
#include "d3d9_device.h"
#include "d3d9_state.h"
#include "../util/util_bit.h"
namespace dxvk {
enum class D3D9CapturedStateFlag : uint32_t {
@ -31,33 +33,33 @@ namespace dxvk {
struct D3D9StateCaptures {
D3D9CapturedStateFlags flags;
std::bitset<RenderStateCount> renderStates;
bit::bitset<RenderStateCount> renderStates;
std::bitset<SamplerCount> samplers;
bit::bitset<SamplerCount> samplers;
std::array<
std::bitset<SamplerStateCount>,
bit::bitset<SamplerStateCount>,
SamplerCount> samplerStates;
std::bitset<caps::MaxStreams> vertexBuffers;
std::bitset<SamplerCount> textures;
std::bitset<caps::MaxClipPlanes> clipPlanes;
std::bitset<caps::MaxStreams> streamFreq;
std::bitset<caps::MaxTransforms> transforms;
std::bitset<caps::TextureStageCount> textureStages;
bit::bitset<caps::MaxStreams> vertexBuffers;
bit::bitset<SamplerCount> textures;
bit::bitset<caps::MaxClipPlanes> clipPlanes;
bit::bitset<caps::MaxStreams> streamFreq;
bit::bitset<caps::MaxTransforms> transforms;
bit::bitset<caps::TextureStageCount> textureStages;
std::array<
std::bitset<D3DTSS_CONSTANT>,
bit::bitset<D3DTSS_CONSTANT>,
caps::TextureStageCount> textureStageStates;
struct {
std::bitset<caps::MaxFloatConstantsSoftware> fConsts;
std::bitset<caps::MaxOtherConstantsSoftware> iConsts;
std::bitset<caps::MaxOtherConstantsSoftware> bConsts;
bit::bitset<caps::MaxFloatConstantsSoftware> fConsts;
bit::bitset<caps::MaxOtherConstantsSoftware> iConsts;
bit::bitset<caps::MaxOtherConstantsSoftware> bConsts;
} vsConsts;
struct {
std::bitset<caps::MaxFloatConstantsPS> fConsts;
std::bitset<caps::MaxOtherConstants> iConsts;
std::bitset<caps::MaxOtherConstants> bConsts;
bit::bitset<caps::MaxFloatConstantsPS> fConsts;
bit::bitset<caps::MaxOtherConstants> iConsts;
bit::bitset<caps::MaxOtherConstants> bConsts;
} psConsts;
};
@ -176,9 +178,12 @@ namespace dxvk {
dst->SetVertexDeclaration(src->vertexDecl.ptr());
if (m_captures.flags.test(D3D9CapturedStateFlag::StreamFreq)) {
for (uint32_t i = 0; i < caps::MaxStreams; i++) {
if (m_captures.streamFreq[i])
dst->SetStreamSourceFreq(i, src->streamFreq[i]);
for (uint32_t i = 0; i < m_captures.streamFreq.dwordCount(); i++) {
for (uint32_t stream = m_captures.streamFreq.dword(i); stream; stream &= stream - 1) {
uint32_t idx = i * 32 + bit::tzcnt(stream);
dst->SetStreamSourceFreq(idx, src->streamFreq[idx]);
}
}
}
@ -186,29 +191,39 @@ namespace dxvk {
dst->SetIndices(src->indices.ptr());
if (m_captures.flags.test(D3D9CapturedStateFlag::RenderStates)) {
for (uint32_t i = 0; i < m_captures.renderStates.size(); i++) {
if (m_captures.renderStates[i])
dst->SetRenderState(D3DRENDERSTATETYPE(i), src->renderStates[i]);
for (uint32_t i = 0; i < m_captures.renderStates.dwordCount(); i++) {
for (uint32_t rs = m_captures.renderStates.dword(i); rs; rs &= rs - 1) {
uint32_t idx = i * 32 + bit::tzcnt(rs);
dst->SetRenderState(D3DRENDERSTATETYPE(idx), src->renderStates[idx]);
}
}
}
if (m_captures.flags.test(D3D9CapturedStateFlag::SamplerStates)) {
for (uint32_t i = 0; i < m_captures.samplerStates.size(); i++) {
if (m_captures.samplers[i]) {
for (uint32_t j = 0; j < m_captures.samplerStates[i].size(); j++) {
if (m_captures.samplerStates[i][j])
dst->SetStateSamplerState(i, D3DSAMPLERSTATETYPE(j), src->samplerStates[i][j]);
for (uint32_t i = 0; i < m_captures.samplers.dwordCount(); i++) {
for (uint32_t sampler = m_captures.samplers.dword(i); sampler; sampler &= sampler - 1) {
uint32_t samplerIdx = i * 32 + bit::tzcnt(sampler);
for (uint32_t j = 0; j < m_captures.samplerStates[i].dwordCount(); j++) {
for (uint32_t state = m_captures.samplerStates[i].dword(j); state; state &= state - 1) {
uint32_t stateIdx = j * 32 + bit::tzcnt(state);
dst->SetStateSamplerState(samplerIdx, D3DSAMPLERSTATETYPE(stateIdx), src->samplerStates[samplerIdx][stateIdx]);
}
}
}
}
}
if (m_captures.flags.test(D3D9CapturedStateFlag::VertexBuffers)) {
for (uint32_t i = 0; i < m_captures.vertexBuffers.size(); i++) {
if (m_captures.vertexBuffers[i]) {
const auto& vbo = src->vertexBuffers[i];
for (uint32_t i = 0; i < m_captures.vertexBuffers.dwordCount(); i++) {
for (uint32_t vb = m_captures.vertexBuffers.dword(i); vb; vb &= vb - 1) {
uint32_t idx = i * 32 + bit::tzcnt(vb);
const auto& vbo = src->vertexBuffers[idx];
dst->SetStreamSource(
i,
idx,
vbo.vertexBuffer.ptr(),
vbo.offset,
vbo.stride);
@ -220,9 +235,12 @@ namespace dxvk {
dst->SetMaterial(&src->material);
if (m_captures.flags.test(D3D9CapturedStateFlag::Textures)) {
for (uint32_t i = 0; i < m_captures.textures.size(); i++) {
if (m_captures.textures[i])
dst->SetStateTexture(i, src->textures[i]);
for (uint32_t i = 0; i < m_captures.textures.dwordCount(); i++) {
for (uint32_t tex = m_captures.textures.dword(i); tex; tex &= tex - 1) {
uint32_t idx = i * 32 + bit::tzcnt(tex);
dst->SetStateTexture(idx, src->textures[idx]);
}
}
}
@ -233,18 +251,26 @@ namespace dxvk {
dst->SetPixelShader(src->pixelShader.ptr());
if (m_captures.flags.test(D3D9CapturedStateFlag::Transforms)) {
for (uint32_t i = 0; i < m_captures.transforms.size(); i++) {
if (m_captures.transforms[i])
dst->SetStateTransform(i, reinterpret_cast<const D3DMATRIX*>(&src->transforms[i]));
for (uint32_t i = 0; i < m_captures.transforms.dwordCount(); i++) {
for (uint32_t trans = m_captures.transforms.dword(i); trans; trans &= trans - 1) {
uint32_t idx = i * 32 + bit::tzcnt(trans);
dst->SetStateTransform(idx, reinterpret_cast<const D3DMATRIX*>(&src->transforms[idx]));
}
}
}
if (m_captures.flags.test(D3D9CapturedStateFlag::TextureStages)) {
for (uint32_t i = 0; i < m_captures.textureStages.size(); i++) {
if (m_captures.textureStages[i]) {
for (uint32_t j = 0; j < m_captures.textureStageStates[i].size(); j++) {
if (m_captures.textureStageStates[i][j])
dst->SetTextureStageState(i, (D3DTEXTURESTAGESTATETYPE)j, src->textureStages[i][j]);
for (uint32_t i = 0; i < m_captures.textureStages.dwordCount(); i++) {
for (uint32_t stage = m_captures.textureStages.dword(i); stage; stage &= stage - 1) {
uint32_t stageIdx = i * 32 + bit::tzcnt(stage);
for (uint32_t j = 0; j < m_captures.textureStageStates[i].dwordCount(); j++) {
for (uint32_t state = m_captures.textureStageStates[i].dword(j); state; state &= state - 1) {
uint32_t stateIdx = j * 32 + bit::tzcnt(state);
dst->SetTextureStageState(stageIdx, (D3DTEXTURESTAGESTATETYPE)stateIdx, src->textureStages[stageIdx][stateIdx]);
}
}
}
}
@ -257,53 +283,55 @@ namespace dxvk {
dst->SetScissorRect(&src->scissorRect);
if (m_captures.flags.test(D3D9CapturedStateFlag::ClipPlanes)) {
for (uint32_t i = 0; i < m_captures.clipPlanes.size(); i++) {
if (m_captures.clipPlanes[i])
dst->SetClipPlane(i, src->clipPlanes[i].coeff);
for (uint32_t i = 0; i < m_captures.clipPlanes.dwordCount(); i++) {
for (uint32_t plane = m_captures.clipPlanes.dword(i); plane; plane &= plane - 1) {
uint32_t idx = i * 32 + bit::tzcnt(plane);
dst->SetClipPlane(idx, src->clipPlanes[idx].coeff);
}
}
}
if (m_captures.flags.test(D3D9CapturedStateFlag::VsConstants)) {
for (uint32_t i = 0; i < m_captures.vsConsts.fConsts.size(); i++) {
if (m_captures.vsConsts.fConsts[i])
dst->SetVertexShaderConstantF(i, (float*)&src->vsConsts.fConsts[i], 1);
}
for (uint32_t i = 0; i < m_captures.vsConsts.fConsts.dwordCount(); i++) {
for (uint32_t consts = m_captures.vsConsts.fConsts.dword(i); consts; consts &= consts - 1) {
uint32_t idx = i * 32 + bit::tzcnt(consts);
for (uint32_t i = 0; i < m_captures.vsConsts.iConsts.size(); i++) {
if (m_captures.vsConsts.iConsts[i])
dst->SetVertexShaderConstantI(i, (int*)&src->vsConsts.iConsts[i], 1);
}
const uint32_t bitfieldCount = m_parent->GetVertexConstantLayout().bitmaskCount;
for (uint32_t i = 0; i < bitfieldCount; i++) {
uint32_t boolMask = 0;
for (uint32_t j = 0; j < 32; j++) {
if (m_captures.vsConsts.bConsts[i * 32 + j])
boolMask |= 1u << j;
dst->SetVertexShaderConstantF(idx, (float*)&src->vsConsts.fConsts[idx], 1);
}
dst->SetVertexBoolBitfield(i, boolMask, src->vsConsts.bConsts[i]);
}
for (uint32_t i = 0; i < m_captures.vsConsts.iConsts.dwordCount(); i++) {
for (uint32_t consts = m_captures.vsConsts.iConsts.dword(i); consts; consts &= consts - 1) {
uint32_t idx = i * 32 + bit::tzcnt(consts);
dst->SetVertexShaderConstantI(idx, (int*)&src->vsConsts.iConsts[idx], 1);
}
}
for (uint32_t i = 0; i < m_captures.vsConsts.bConsts.dwordCount(); i++)
dst->SetVertexBoolBitfield(i, m_captures.vsConsts.bConsts.dword(i), src->vsConsts.bConsts[i]);
}
if (m_captures.flags.test(D3D9CapturedStateFlag::PsConstants)) {
for (uint32_t i = 0; i < m_captures.psConsts.fConsts.size(); i++) {
if (m_captures.psConsts.fConsts[i])
dst->SetPixelShaderConstantF(i, (float*)&src->psConsts.fConsts[i], 1);
for (uint32_t i = 0; i < m_captures.psConsts.fConsts.dwordCount(); i++) {
for (uint32_t consts = m_captures.psConsts.fConsts.dword(i); consts; consts &= consts - 1) {
uint32_t idx = i * 32 + bit::tzcnt(consts);
dst->SetPixelShaderConstantF(idx, (float*)&src->psConsts.fConsts[idx], 1);
}
}
for (uint32_t i = 0; i < m_captures.psConsts.iConsts.size(); i++) {
if (m_captures.psConsts.iConsts[i])
dst->SetPixelShaderConstantI(i, (int*)&src->psConsts.iConsts[i], 1);
for (uint32_t i = 0; i < m_captures.psConsts.iConsts.dwordCount(); i++) {
for (uint32_t consts = m_captures.psConsts.iConsts.dword(i); consts; consts &= consts - 1) {
uint32_t idx = i * 32 + bit::tzcnt(consts);
dst->SetPixelShaderConstantI(idx, (int*)&src->psConsts.iConsts[idx], 1);
}
}
uint32_t boolMask = 0;
for (uint32_t i = 0; i < m_captures.psConsts.bConsts.size(); i++) {
if (m_captures.psConsts.bConsts[i])
boolMask |= 1u << i;
}
dst->SetPixelBoolBitfield(0, boolMask, src->psConsts.bConsts[0]);
for (uint32_t i = 0; i < m_captures.psConsts.bConsts.dwordCount(); i++)
dst->SetPixelBoolBitfield(i, m_captures.psConsts.bConsts.dword(i), src->psConsts.bConsts[i]);
}
}
@ -332,11 +360,11 @@ namespace dxvk {
for (uint32_t i = 0; i < Count; i++) {
uint32_t reg = StartRegister + i;
if constexpr (ConstantType == D3D9ConstantType::Float)
setCaptures.fConsts[reg] = true;
setCaptures.fConsts.set(reg, true);
else if constexpr (ConstantType == D3D9ConstantType::Int)
setCaptures.iConsts[reg] = true;
setCaptures.iConsts.set(reg, true);
else if constexpr (ConstantType == D3D9ConstantType::Bool)
setCaptures.bConsts[reg] = true;
setCaptures.bConsts.set(reg, true);
}
UpdateStateConstants<