From 0a9ce9e46ca588c4f5bfd64683f343bd5a1baff0 Mon Sep 17 00:00:00 2001 From: PatrickvL Date: Thu, 10 Jan 2019 17:51:19 +0100 Subject: [PATCH] HLE : The plugin on pgraph-based rendering must convert pgraph-state to D3D, here a small commit with some comments in this area (nothing functional, I just wanted to dump this somewhere) --- src/core/hle/D3D8/XbPixelShader.cpp | 2 +- src/core/hle/D3D8/XbPushBuffer.cpp | 48 +++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/core/hle/D3D8/XbPixelShader.cpp b/src/core/hle/D3D8/XbPixelShader.cpp index f69ef25e9..6cafefca4 100644 --- a/src/core/hle/D3D8/XbPixelShader.cpp +++ b/src/core/hle/D3D8/XbPixelShader.cpp @@ -6232,7 +6232,7 @@ VOID XTL::DxbxUpdateActivePixelShader() // NOPATCH if ((RecompiledPixelShader.PSDef.PSFinalCombinerInputsABCD > 0) || (RecompiledPixelShader.PSDef.PSFinalCombinerInputsEFG > 0)) { - g_pD3DDevice.SetRenderState(D3DRS_FOGENABLE, BOOL_FALSE); + g_pD3DDevice->SetRenderState(D3DRS_FOGENABLE, BOOL_FALSE); } */ //PS_TEXTUREMODES psTextureModes[XTL::X_D3DTS_STAGECOUNT]; diff --git a/src/core/hle/D3D8/XbPushBuffer.cpp b/src/core/hle/D3D8/XbPushBuffer.cpp index 45b3094a3..c4fd0f4e2 100644 --- a/src/core/hle/D3D8/XbPushBuffer.cpp +++ b/src/core/hle/D3D8/XbPushBuffer.cpp @@ -241,7 +241,9 @@ void HLE_draw_inline_array(NV2AState *d) using namespace XTL; //DWORD vertex data array, - //To be used as a replacement for DrawVerticesUP, the caller needs to set the vertex format using IDirect3DDevice8::SetVertexShader before calling BeginPush. All attributes in the vertex format must be padded DWORD multiples, and the vertex attributes must be specified in the canonical FVF ordering (position followed by weight, normal, diffuse, and so on). + // To be used as a replacement for DrawVerticesUP, the caller needs to set the vertex format using IDirect3DDevice8::SetVertexShader before calling BeginPush. + // All attributes in the vertex format must be padded DWORD multiples, and the vertex attributes must be specified in the canonical FVF ordering + // (position followed by weight, normal, diffuse, and so on). // retrieve vertex shader XTL::DWORD dwVertexShader = g_CurrentXboxVertexShaderHandle; if (dwVertexShader == 0) { @@ -286,14 +288,54 @@ void HLE_draw_inline_elements(NV2AState *d) } } +DWORD ABGR_to_ARGB(const uint32_t color) +{ + return (color & 0xFF00FF00) | ((color & 0x00FF0000) >> 16) | ((color & 0x000000FF) << 16); +} + void HLE_draw_state_update(NV2AState *d) { - // PGRAPHState *pg = &d->pgraph; + PGRAPHState *pg = &d->pgraph; using namespace XTL; CxbxUpdateNativeD3DResources(); + HRESULT hRet; + +// hRet = g_pD3DDevice->SetRenderState(D3DRS_FOGENABLE, xtBOOL); // NV2A_FOG_ENABLE +// hRet = g_pD3DDevice->SetRenderState(D3DRS_FOGTABLEMODE, xtD3DFOGMODE); // NV2A_FOG_MODE +// hRet = g_pD3DDevice->SetRenderState(D3DRS_FOGSTART, xtFloat); // NV2A_FOG_COORD_DIST +// hRet = g_pD3DDevice->SetRenderState(D3DRS_FOGEND, xtFloat); // NV2A_FOG_MODE +// hRet = g_pD3DDevice->SetRenderState(D3DRS_FOGDENSITY, xtFloat); // NV2A_FOG_EQUATION_CONSTANT / NV2A_FOG_EQUATION_LINEAR / NV2A_FOG_EQUATION_QUADRATIC + // NV2A_FOG_PLANE? + // NV2A_SET_LINEAR_FOG_CONST? +// hRet = g_pD3DDevice->SetRenderState(D3DRS_RANGEFOGENABLE, xtBOOL); // NV2A_FOG_COORD_DIST + // Unused : D3DRS_FOGVERTEXMODE + + uint32_t fog_color = pg->regs[NV_PGRAPH_FOGCOLOR]; + hRet = g_pD3DDevice->SetRenderState(D3DRS_FOGCOLOR, ABGR_to_ARGB(fog_color)); // NV2A_FOG_COLOR + +// Hint : see DxbxRenderStateInfo table for all known Xbox states, their data type and NV2A method +// Also, see D3DDevice_SetRenderState_Simple call EmuXB2PC_* conversion functions for some render states + +// hRet = g_pD3DDevice->SetRenderState(D3DRS_NORMALIZENORMALS, xtBool); // NV2A_NORMALIZE_ENABLE +// hRet = g_pD3DDevice->SetRenderState(D3DRS_TEXTUREFACTOR, xtD3DCOLOR); // NV2A_RC_CONSTANT_COLOR0(0) NV_PGRAPH_COMBINEFACTOR0 +// hRet = g_pD3DDevice->SetRenderState(D3DRS_DEPTHBIAS, xtFloat); // NV2A_POLYGON_OFFSET_FACTOR, NV2A_POLYGON_OFFSET_UNITS, NV2A_POLYGON_OFFSET_POINT_ENABLE, NV2A_POLYGON_OFFSET_LINE_ENABLE, NV2A_POLYGON_OFFSET_FILL_ENABLE, XB2PC conversion needed +// hRet = g_pD3DDevice->SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, xtBool); // Was D3DRS_EDGEANTIALIAS, corresponds to NV2A_LINE_SMOOTH_ENABLE and NV2A_POLYGON_SMOOTH_ENABLE +// hRet = g_pD3DDevice->SetRenderState(D3DRS_FILLMODE, dwFillMode); // NV2A_POLYGON_MODE_FRONT, EmuXB2PC_* conversion needed +// hRet = g_pD3DDevice->SetRenderState(D3DRS_VERTEXBLEND, Value); // NV2A_SKIN_MODE +// hRet = g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, Value); // NV2A_CULL_FACE +// hRet = g_pD3DDevice->SetRenderState(D3DRS_STENCILFAIL, Value); // NV2A_STENCIL_OP_FAIL +// hRet = g_pD3DDevice->SetRenderState(D3DRS_ZENABLE, Value); // NV2A_DEPTH_TEST_ENABLE +// hRet = g_pD3DDevice->SetRenderState(D3DRS_STENCILENABLE, Value); // NV2A_STENCIL_ENABLE +// hRet = g_pD3DDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, Value); // NV2A_MULTISAMPLE_CONTROL +// hRet = g_pD3DDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, Value); // NV2A_MULTISAMPLE_CONTROL +// hRet = g_pD3DDevice->SetRenderState(D3DRS_WRAP0, dwConv); // NV2A_TX_WRAP(0), EmuXB2PC_* conversion needed +// hRet = g_pD3DDevice->SetRenderState(D3DRS_WRAP1, dwConv); // NV2A_TX_WRAP(1), EmuXB2PC_* conversion needed + +// g_pD3DDevice->SetRenderState(D3DRS_LINEPATTERN, Value); // NV2A_POLYGON_STIPPLE_PATTERN? Seems unused in Xbox + LOG_INCOMPLETE(); // TODO : Read state from pgraph, convert to D3D } @@ -305,7 +347,7 @@ void HLE_draw_clear(NV2AState *d) CxbxUpdateNativeD3DResources(); - LOG_INCOMPLETE(); // TODO : Read state from pgraph, convert to D3D + LOG_INCOMPLETE(); // TODO : Read state from pgraph, convert to D3D (call EMUPATCH(D3DDevice_Clear)?) } // Import pgraph_draw_* variables, declared in EmuNV2A_PGRAPH.cpp :