D3D: State cache now uses BitField to define packed render states

This commit is contained in:
Yuriy O'Donnell 2014-06-09 11:55:25 +02:00
parent 2e4667caaa
commit e7f8032d7d
3 changed files with 34 additions and 42 deletions

View File

@ -614,7 +614,7 @@ void Renderer::SetBlendMode(bool forceUpdate)
} }
else else
{ {
gx_state.blend.blend_enable = bpmem.blendmode.blendenable; gx_state.blend.blend_enable = (u32)bpmem.blendmode.blendenable;
if (bpmem.blendmode.blendenable) if (bpmem.blendmode.blendenable)
{ {
SetBlendOp(D3D11_BLEND_OP_ADD); SetBlendOp(D3D11_BLEND_OP_ADD);
@ -1213,15 +1213,15 @@ void Renderer::SetSamplerState(int stage, int texindex)
} }
else else
{ {
gx_state.sampler[stage].min_filter = tm0.min_filter; gx_state.sampler[stage].min_filter = (u32)tm0.min_filter;
gx_state.sampler[stage].mag_filter = tm0.mag_filter; gx_state.sampler[stage].mag_filter = (u32)tm0.mag_filter;
} }
gx_state.sampler[stage].wrap_s = tm0.wrap_s; gx_state.sampler[stage].wrap_s = (u32)tm0.wrap_s;
gx_state.sampler[stage].wrap_t = tm0.wrap_t; gx_state.sampler[stage].wrap_t = (u32)tm0.wrap_t;
gx_state.sampler[stage].max_lod = tm1.max_lod; gx_state.sampler[stage].max_lod = (u32)tm1.max_lod;
gx_state.sampler[stage].min_lod = tm1.min_lod; gx_state.sampler[stage].min_lod = (u32)tm1.min_lod;
gx_state.sampler[stage].lod_bias = tm0.lod_bias; gx_state.sampler[stage].lod_bias = (s32)tm0.lod_bias;
} }
void Renderer::SetInterlacingMode() void Renderer::SetInterlacingMode()

View File

@ -38,7 +38,7 @@ ID3D11SamplerState* StateCache::Get(SamplerState state)
if (state.max_anisotropy) if (state.max_anisotropy)
{ {
sampdc.Filter = D3D11_FILTER_ANISOTROPIC; sampdc.Filter = D3D11_FILTER_ANISOTROPIC;
sampdc.MaxAnisotropy = state.max_anisotropy; sampdc.MaxAnisotropy = (u32)state.max_anisotropy;
} }
else if (state.min_filter & 4) // linear min filter else if (state.min_filter & 4) // linear min filter
{ {
@ -114,13 +114,13 @@ ID3D11BlendState* StateCache::Get(BlendState state)
blenddc.AlphaToCoverageEnable = FALSE; blenddc.AlphaToCoverageEnable = FALSE;
blenddc.IndependentBlendEnable = FALSE; blenddc.IndependentBlendEnable = FALSE;
blenddc.RenderTarget[0].BlendEnable = state.blend_enable; blenddc.RenderTarget[0].BlendEnable = state.blend_enable;
blenddc.RenderTarget[0].RenderTargetWriteMask = (D3D11_COLOR_WRITE_ENABLE)state.write_mask; blenddc.RenderTarget[0].RenderTargetWriteMask = (u32)state.write_mask;
blenddc.RenderTarget[0].SrcBlend = (D3D11_BLEND)state.src_blend; blenddc.RenderTarget[0].SrcBlend = state.src_blend;
blenddc.RenderTarget[0].DestBlend = (D3D11_BLEND)state.dst_blend; blenddc.RenderTarget[0].DestBlend = state.dst_blend;
blenddc.RenderTarget[0].BlendOp = (D3D11_BLEND_OP)state.blend_op; blenddc.RenderTarget[0].BlendOp = state.blend_op;
blenddc.RenderTarget[0].SrcBlendAlpha = (D3D11_BLEND)state.src_blend; blenddc.RenderTarget[0].SrcBlendAlpha = state.src_blend;
blenddc.RenderTarget[0].DestBlendAlpha = (D3D11_BLEND)state.dst_blend; blenddc.RenderTarget[0].DestBlendAlpha = state.dst_blend;
blenddc.RenderTarget[0].BlendOpAlpha = (D3D11_BLEND_OP)state.blend_op; blenddc.RenderTarget[0].BlendOpAlpha = state.blend_op;
if (blenddc.RenderTarget[0].SrcBlend == D3D11_BLEND_SRC_COLOR) if (blenddc.RenderTarget[0].SrcBlend == D3D11_BLEND_SRC_COLOR)
blenddc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA; blenddc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
@ -183,7 +183,7 @@ ID3D11RasterizerState* StateCache::Get(RasterizerState state)
} }
D3D11_RASTERIZER_DESC rastdc = CD3D11_RASTERIZER_DESC(state.wireframe ? D3D11_FILL_WIREFRAME : D3D11_FILL_SOLID, D3D11_RASTERIZER_DESC rastdc = CD3D11_RASTERIZER_DESC(state.wireframe ? D3D11_FILL_WIREFRAME : D3D11_FILL_SOLID,
(D3D11_CULL_MODE)state.cull_mode, state.cull_mode,
false, 0, 0.f, 0, false, true, false, false); false, 0, 0.f, 0, false, true, false, false);
ID3D11RasterizerState* res = nullptr; ID3D11RasterizerState* res = nullptr;

View File

@ -6,6 +6,7 @@
#include <unordered_map> #include <unordered_map>
#include "Common/BitField.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "VideoBackends/D3D/D3DBase.h" #include "VideoBackends/D3D/D3DBase.h"
#include "VideoCommon/BPMemory.h" #include "VideoCommon/BPMemory.h"
@ -15,43 +16,34 @@ namespace DX11
union RasterizerState union RasterizerState
{ {
struct BitField<0, 2, D3D11_CULL_MODE> cull_mode;
{ BitField<2, 1, u32> wireframe;
u32 cull_mode : 2;
u32 wireframe : 1;
};
u32 packed; u32 packed;
}; };
union BlendState union BlendState
{ {
struct BitField<0, 1, u32> blend_enable;
{ BitField<1, 3, D3D11_BLEND_OP> blend_op;
u32 blend_enable : 1; BitField<4, 4, u32> write_mask;
u32 blend_op : 3; BitField<8, 5, D3D11_BLEND> src_blend;
u32 write_mask : 4; BitField<13, 5, D3D11_BLEND> dst_blend;
u32 src_blend : 5; BitField<18, 1, u32> use_dst_alpha;
u32 dst_blend : 5;
u32 use_dst_alpha : 1;
};
u32 packed; u32 packed;
}; };
union SamplerState union SamplerState
{ {
struct BitField<0, 3, u64> min_filter;
{ BitField<3, 1, u64> mag_filter;
u64 min_filter : 3; BitField<4, 8, u64> min_lod;
u64 mag_filter : 1; BitField<12, 8, u64> max_lod;
u64 min_lod : 8; BitField<20, 8, s64> lod_bias;
u64 max_lod : 8; BitField<28, 2, u64> wrap_s;
s64 lod_bias : 8; BitField<30, 2, u64> wrap_t;
u64 wrap_s : 2; BitField<32, 5, u64> max_anisotropy;
u64 wrap_t : 2;
u64 max_anisotropy : 5;
};
u64 packed; u64 packed;
}; };