Toggle MSAA

  • Konuyu açan Konuyu açan otuzbiroglu
  • Açılış Tarihi Açılış Tarihi
  • Yanıt Yanıt 0
  • Gösterim Gösterim 251

otuzbiroglu

Üye
Üye
Mesaj
16
Beğeni
24
Puan
405
Ticaret Puanı
0
Merhaba,

Oyun içerisindeki sistem seçeneklerinden oyunu yeniden başlatmaya ya da herhangi bir işleme gerek kalmadan anlık olarak MSAA özelliğini açıp kapatabileceğim bir sistem arıyordum fakat bulamadım. Kendim yazmaya ve paylaşmaya karar verdim.

  • Dinamik ve kayıpsız olarak MSAA'i açıp kapatabilmek için minimum Direct3D 9Ex (DX9Ex) sürümü gereklidir.

Neden DX9Ex?

DX9 ve daha düşük versiyonlarda MSAA gibi bir ayar değiştirildikten sonra "IDirect3DDevice9::Reset" fonksiyonu çağırılmalı, tüm back buffer yapısı değiştirilmeli, tüm bağlılıklar VRAM'e yeniden yüklenmelidir. Bu da yeterince hızlı olmaz. Donmalar, siyah ekranlar, çökmeler yaşanabilir. DX9Ex ise bu sorunu VVM (sanal video belleği) özelliği ile birlikte video belleğini tıpkı RAM gibi sanallaştırarak ve buna binayen reset ihtiyacını ortadan kaldırarak çözer. Herhangi bir yeniden yapılandırma gerekiyorsa "IDirect3DDevice9Ex::ResetEx" fonksiyonu, VRAM'deki tüm kaynakları öldürmeden ya da yeniden yüklemeden sadece swap chain'i güncelleyebilir.

DX9'da çalıştırmak mümkün mü?

DX9'da ısrarcıysanız bunun gibi bir sistem her geçişte birkaç saniyelik donmalara, siyah ekran sorunlarına ya da teşhisi zor bellek sızıntılarına sebep olabilir ve henüz destek veremem.

Bu sistem yalnızca client source ve data üzerinde değişiklik yapar. Makrolar, önünde ve arkasındaki bağlamlarıyla birlikte verilmiştir. MSAA'in kaynak tüketimi çok düşük olduğu ve 4 kat örnekleme versiyonu bile sınırlı görsel performans verebildiği için 8 kat örnekleme versiyonu eğer mümkün değilse en düşük 4 kat örnekleme yapan versiyonu zorlanmıştır.

UserInterface\Locale_inc.h:
Genişlet Daralt Kopyala
#define ANTI_ALIASING

EterLib\GrpDevice.cpp:
Genişlet Daralt Kopyala
#include "EterBase/Debug.h"

#ifdef ANTI_ALIASING
#include "../UserInterface/PythonSystem.h"
#endif

#include <intrin.h>

EterLib\GrpDevice.cpp:
Genişlet Daralt Kopyala
bool CGraphicDevice::Reset()
{
    HRESULT hr;

#ifdef ANTI_ALIASING

    ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_NONE;
    ms_d3dPresentParameter.MultiSampleQuality = 0;

    if (CPythonSystem::Instance().IsMSAAEnable())
    {

        D3DDISPLAYMODE d3dDisplayMode;
        ms_lpd3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3dDisplayMode);
        D3DFORMAT msaaCheckFormat = ms_d3dPresentParameter.Windowed ? d3dDisplayMode.Format : ms_d3dPresentParameter.BackBufferFormat;

        if (SUCCEEDED(ms_lpd3d->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, msaaCheckFormat, ms_d3dPresentParameter.Windowed, D3DMULTISAMPLE_8_SAMPLES, &ms_d3dPresentParameter.MultiSampleQuality)))
        {
            ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_8_SAMPLES;
            ms_d3dPresentParameter.MultiSampleQuality = 0;
        }
    }
#endif

    if (FAILED(hr = ms_lpd3dDevice->Reset(&ms_d3dPresentParameter)))
        return false;

    if (m_pStateManager)
        m_pStateManager->SetDefaultState();

    return true;
}

EterLib\GrpDevice.cpp için else bloğunu kendi kodlarınızla değiştirin.

EterLib\GrpDevice.cpp:
Genişlet Daralt Kopyala
    ms_d3dPresentParameter.EnableAutoDepthStencil            = TRUE;
    ms_d3dPresentParameter.AutoDepthStencilFormat            = D3DFMT_D24S8;

#ifdef ANTI_ALIASING
    if (CPythonSystem::Instance().IsMSAAEnable() && !disableMSAA)
    {
        D3DFORMAT msaaCheckFormat = Windowed ? d3dDisplayMode.Format : ms_d3dPresentParameter.BackBufferFormat;
       
        if (SUCCEEDED(ms_lpd3d->CheckDeviceMultiSampleType(
            D3DADAPTER_DEFAULT,
            D3DDEVTYPE_HAL,
            msaaCheckFormat,
            Windowed,
            D3DMULTISAMPLE_8_SAMPLES,
            &ms_d3dPresentParameter.MultiSampleQuality)))
        {
            ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_8_SAMPLES;
            ms_d3dPresentParameter.MultiSampleQuality = 0;
        }
        else if (SUCCEEDED(ms_lpd3d->CheckDeviceMultiSampleType(
            D3DADAPTER_DEFAULT,
            D3DDEVTYPE_HAL,
            msaaCheckFormat,
            Windowed,
            D3DMULTISAMPLE_4_SAMPLES,
            &ms_d3dPresentParameter.MultiSampleQuality)))
        {
            ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_4_SAMPLES;
            ms_d3dPresentParameter.MultiSampleQuality = 0;
        }
    }
#else
    if (!Windowed && !disableMSAA)
    {
        D3DFORMAT msaaCheckFormat = ms_d3dPresentParameter.BackBufferFormat;
        if (SUCCEEDED(ms_lpd3d->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, msaaCheckFormat, FALSE, D3DMULTISAMPLE_2_SAMPLES, &ms_d3dPresentParameter.MultiSampleQuality)))
        {
            ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
            ms_d3dPresentParameter.MultiSampleQuality = 0;
        }
        if (SUCCEEDED(ms_lpd3d->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, msaaCheckFormat, FALSE, D3DMULTISAMPLE_4_SAMPLES, &ms_d3dPresentParameter.MultiSampleQuality)))
        {
            ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_4_SAMPLES;
            ms_d3dPresentParameter.MultiSampleQuality = 0;
        }
    }
#endif

    D3DDISPLAYMODEEX displayModeEx;
    ZeroMemory(&displayModeEx, sizeof(displayModeEx));

EterLib\StateManager.cpp:
Genişlet Daralt Kopyala
CStateManager::CStateManager(LPDIRECT3DDEVICE9EX lpDevice) : m_lpD3DDev(NULL)
{
    m_bScene = false;

#ifdef ANTI_ALIASING
    m_bMSAAEnabled = true;
#endif

    m_dwBestMinFilter = D3DTEXF_ANISOTROPIC;
    m_dwBestMagFilter = D3DTEXF_ANISOTROPIC;

EterLib\StateManager.cpp:
Genişlet Daralt Kopyala
    SaveVertexProcessing(FALSE);
    SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);

#ifdef ANTI_ALIASING
    SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, m_bMSAAEnabled ? TRUE : FALSE);
#else
    SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
#endif

    SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF);
    SetRenderState(D3DRS_PATCHEDGESTYLE, D3DPATCHEDGE_CONTINUOUS);

EterLib\StateManager.cpp:
Genişlet Daralt Kopyala
    m_lpD3DDev->SetIndices(pIndexData);
    m_CurrentState.m_IndexData = kIndexData;
}

#ifdef ANTI_ALIASING
void CStateManager::SetMSAAOption(bool bEnable)
{
    m_bMSAAEnabled = bEnable;

    SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, bEnable ? TRUE : FALSE);
}
#endif

HRESULT CStateManager::DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
{

EterLib\StateManager.h:
Genişlet Daralt Kopyala
    void StateManager_Capture();
    void StateManager_Apply();

    LPDIRECT3DDEVICE9EX GetDevice();

#ifdef _DEBUG
    void ResetDrawCallCounter();
    int GetDrawCallCount() const;
#endif

#ifdef ANTI_ALIASING
    void SetMSAAOption(bool bEnable);
#endif

private:
    void SetDevice(LPDIRECT3DDEVICE9EX lpDevice);

EterLib\StateManager.h:
Genişlet Daralt Kopyala
    bool                m_bForce;
    bool                m_bScene;

#ifdef ANTI_ALIASING
    bool                m_bMSAAEnabled;
#endif

    DWORD                m_dwBestMinFilter;
    DWORD                m_dwBestMagFilter;

UserInterface\PythonApplication.cpp:
Genişlet Daralt Kopyala
void CPythonApplication::SetForceSightRange(int iRange)
{
    m_iForceSightRange = iRange;
}

#ifdef ANTI_ALIASING
void CPythonApplication::ResetDevice()
{
    m_grpDevice.Reset();
}
#endif

void CPythonApplication::Clear()
{
    m_pySystem.Clear();
}

UserInterface\PythonApplication.h:
Genişlet Daralt Kopyala
class CPythonApplication : public CMSApplication, public CInputKeyboard, public IAbstractApplication
{
    public:

    #ifdef ANTI_ALIASING
        void ResetDevice();
    #endif

        enum EDeviceState
        {
            DEVICE_STATE_FALSE,
            DEVICE_STATE_SKIP,
            DEVICE_STATE_OK,
        };

UserInterface\PythonSystem.cpp:
Genişlet Daralt Kopyala
    m_Config.bShowDamage        = true;
    m_Config.bShowSalesText        = true;

#ifdef ANTI_ALIASING
    m_Config.bMSAA = true;
#endif
}

bool CPythonSystem::IsWindowed()
{
    return m_Config.bWindowed;
}

UserInterface\PythonSystem.cpp:
Genişlet Daralt Kopyala
        else if (!stricmp(command, "SHOW_DAMAGE"))
            m_Config.bShowDamage = atoi(value) == 1 ? true : false;
        else if (!stricmp(command, "SHOW_SALESTEXT"))
            m_Config.bShowSalesText = atoi(value) == 1 ? true : false;

#ifdef ANTI_ALIASING
        else if (!stricmp(command, "MSAA"))
        {
            m_Config.bMSAA = atoi(value) == 1 ? true : false;
            continue;
        }
#endif
    }

    if (m_Config.bWindowed)
    {

UserInterface\PythonSystem.cpp:
Genişlet Daralt Kopyala
    fprintf(fp, "SHADOW_LEVEL            %d\n", m_Config.iShadowLevel);
    fprintf(fp, "FOG_LEVEL                %d\n", m_Config.iFogLevel);

#ifdef ANTI_ALIASING
    fprintf(fp, "MSAA\t\t%d\n", m_Config.bMSAA ? 1 : 0);
#endif

    fprintf(fp, "\n");

    fclose(fp);
    return true;
}

UserInterface\PythonSystem.cpp:
Genişlet Daralt Kopyala
void CPythonSystem::Clear()
{
    SetInterfaceHandler(NULL);
}

#ifdef ANTI_ALIASING
void CPythonSystem::SetMSAAState(bool bEnable)
{
    if (m_Config.bMSAA == bEnable)
        return;

    m_Config.bMSAA = bEnable;

    CPythonApplication::Instance().ResetDevice();
}

bool CPythonSystem::IsMSAAEnable()
{
    return m_Config.bMSAA;
}
#endif

CPythonSystem::CPythonSystem()
{

UserInterface\PythonSystem.h:
Genişlet Daralt Kopyala
            bool            bShowDamage;
            bool            bShowSalesText;

#ifdef ANTI_ALIASING
            bool            bMSAA;
#endif
        } TConfig;

    public:
        CPythonSystem();

UserInterface\PythonSystem.h:
Genişlet Daralt Kopyala
        TConfig *                        GetConfig();
        void                            ChangeSystem();

#ifdef ANTI_ALIASING
        void                            SetMSAAState(bool bEnable);
        bool                            IsMSAAEnable();
#endif

        bool                            LoadInterfaceStatus();
        void                            SaveInterfaceStatus();

UserInterface\PythonSystemModule.cpp:
Genişlet Daralt Kopyala
#include "StdAfx.h"
#include "PythonSystem.h"

#ifdef ANTI_ALIASING
#include "../EterLib/StateManager.h"
#endif

PyObject * systemGetWidth(PyObject* poSelf, PyObject* poArgs)
{
    return Py_BuildValue("i", CPythonSystem::Instance().GetWidth());
}

UserInterface\PythonSystemModule.cpp:
Genişlet Daralt Kopyala
    CPythonSystem::Instance().SetFogLevel(iLevel);
    return Py_BuildNone();
}

#ifdef ANTI_ALIASING
PyObject* systemSetMSAAState(PyObject* poSelf, PyObject* poArgs)
{
    int iEnable;
    if (!PyArg_ParseTuple(poArgs, "i", &iEnable))
        return Py_BuildException();

    CStateManager::Instance().SetMSAAOption(iEnable ? true : false);

    CPythonSystem::Instance().SetMSAAState(iEnable ? true : false);

    return Py_BuildNone();
}

PyObject* systemIsMSAAEnable(PyObject* poSelf, PyObject* poArgs)
{
    return Py_BuildValue("i", CPythonSystem::Instance().IsMSAAEnable() ? 1 : 0);
}
#endif

void initsystem()
{

UserInterface\PythonSystemModule.cpp:
Genişlet Daralt Kopyala
        { "GetShadowLevel",                systemGetShadowLevel,            METH_VARARGS },
        { "SetShadowLevel",                systemSetShadowLevel,            METH_VARARGS },

#ifdef ANTI_ALIASING
        { "SetMSAAState",               systemSetMSAAState,             METH_VARARGS },
        { "IsMSAAEnable",               systemIsMSAAEnable,             METH_VARARGS },
#endif

        { NULL,                            NULL,                            NULL }
    };

    PyObject * poModule = Py_InitModule("systemSetting", s_methods);

    PyModule_AddIntConstant(poModule, "WINDOW_STATUS",        CPythonSystem::WINDOW_STATUS);

root/uisystemoption.py:
Genişlet Daralt Kopyala
        self.tilingModeButtonList = []
        self.ctrlShadowQuality = 0
        self.msaaEnableButton = None
        self.msaaDisableButton = None

    def Destroy(self):
        self.ClearDictionary()

root/uisystemoption.py:
Genişlet Daralt Kopyala
            self.tilingModeButtonList.append(GetObject("tiling_gpu"))
            self.tilingApplyButton=GetObject("tiling_apply")
            self.msaaEnableButton = self.GetChild("msaa_enable_button")
            self.msaaDisableButton = self.GetChild("msaa_disable_button")
        except:
            import exception
            exception.Abort("OptionDialog.__Load_BindObject")

root/uisystemoption.py:
Genişlet Daralt Kopyala
        self.tilingApplyButton.SAFE_SetEvent(self.__OnClickTilingApplyButton)

        self.msaaEnableButton.SAFE_SetEvent(self.__OnClickMSAAEnable)
        self.msaaDisableButton.SAFE_SetEvent(self.__OnClickMSAADisable)

        self.__SetCurTilingMode()

root/uisystemoption.py:
Genişlet Daralt Kopyala
        self.__ClickRadioButton(self.cameraModeButtonList, constInfo.GET_CAMERA_MAX_DISTANCE_INDEX())

        if systemSetting.IsMSAAEnable():
            self.msaaEnableButton.Down()
            self.msaaDisableButton.SetUp()
        else:
            self.msaaEnableButton.SetUp()
            self.msaaDisableButton.Down()

        if musicInfo.fieldMusic==musicInfo.METIN2THEMA:
            self.selectMusicFile.SetText(uiSelectMusic.DEFAULT_THEMA)

root/uisystemoption.py:
Genişlet Daralt Kopyala
            background.EnableSoftwareTiling(0)

        net.ExitGame()

    def __OnClickMSAAEnable(self):
        systemSetting.SetMSAAState(1)
        self.msaaEnableButton.Down()
        self.msaaDisableButton.SetUp()

    def __OnClickMSAADisable(self):
        systemSetting.SetMSAAState(0)
        self.msaaEnableButton.SetUp()
        self.msaaDisableButton.Down()

    def __OnClickChangeMusicButton(self):
        if not self.musicListDlg:

uiscript/systemoptiondialog.py:
Genişlet Daralt Kopyala
                {
                    "name" : "tiling_apply",
                    "type" : "button",

                    "x" : 110+100,
                    "y" : 185,

                    "text" : uiScriptLocale.OPTION_TILING_APPLY,

                    "default_image" : ROOT_PATH + "middle_Button_01.sub",
                    "over_image" : ROOT_PATH + "middle_Button_02.sub",
                    "down_image" : ROOT_PATH + "middle_Button_03.sub",
                },

                {
                    "name" : "msaa_mode",
                    "type" : "text",

                    "x" : 40 + TEXT_TEMPORARY_X,
                    "y" : 210+2,

                    "text" : "MSAA",
                },

                {
                    "name" : "msaa_enable_button",
                    "type" : "radio_button",

                    "x" : 110,
                    "y" : 210,

                    "text" : "Açık",

                    "default_image" : ROOT_PATH + "small_Button_01.sub",
                    "over_image" : ROOT_PATH + "small_Button_02.sub",
                    "down_image" : ROOT_PATH + "small_Button_03.sub",
                },

                {
                    "name" : "msaa_disable_button",
                    "type" : "radio_button",

                    "x" : 110+50,
                    "y" : 210,

                    "text" : "Kapalı",

                    "default_image" : ROOT_PATH + "small_Button_01.sub",
                    "over_image" : ROOT_PATH + "small_Button_02.sub",
                    "down_image" : ROOT_PATH + "small_Button_03.sub",
                },

hcpo6qe.png

jwlzw28.png


Herhangi bir problemle karşılaşmanız durumunda iletişime geçebilirsiniz.​
 
Son düzenleme:
Geri
Üst