How To Directx9 Device Creation with Multiple Thread Support

  • Konbuyu başlatan Konbuyu başlatan Admin
  • Başlangıç tarihi Başlangıç tarihi
  • Cevaplar Cevaplar 0
  • Görüntüleme Görüntüleme 51

Admin

Metin2Lobby
Yönetici
Founder
Katılım
6 Mayıs 2022
Mesajlar
52,647
Ticaret : 1 / 0 / 0
Hi everyone,

With this change you can handle multiple threads on device creating on Directx9 update. It fixes application freeze / crash when creating a thread on application create.


Kod:
GrpDetector.cpp // Before if (m_kD3DCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {     if (m_kD3DCaps.DevCaps & D3DDEVCAPS_PUREDEVICE)     {         dwD3DBehavior = D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE;         if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))             isFormatConfirmed = TRUE;     }     if (FALSE == isFormatConfirmed)     {         dwD3DBehavior = D3DCREATE_HARDWARE_VERTEXPROCESSING;         if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))             isFormatConfirmed = TRUE;     }     if (FALSE == isFormatConfirmed)     {         dwD3DBehavior = D3DCREATE_MIXED_VERTEXPROCESSING;         if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))             isFormatConfirmed = TRUE;     } } // Confirm the device/format for SW vertex processing if (FALSE == isFormatConfirmed) {     dwD3DBehavior = D3DCREATE_SOFTWARE_VERTEXPROCESSING;     if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))         isFormatConfirmed = TRUE; } // After if (m_kD3DCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {     if (m_kD3DCaps.DevCaps & D3DDEVCAPS_PUREDEVICE)     {         dwD3DBehavior = D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE | D3DCREATE_MULTITHREADED;         if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))             isFormatConfirmed = TRUE;     }     if (FALSE == isFormatConfirmed)     {         dwD3DBehavior = D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED;         if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))             isFormatConfirmed = TRUE;     }     if (FALSE == isFormatConfirmed)     {         dwD3DBehavior = D3DCREATE_MIXED_VERTEXPROCESSING | D3DCREATE_MULTITHREADED;         if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))             isFormatConfirmed = TRUE;     } } // Confirm the device/format for SW vertex processing if (FALSE == isFormatConfirmed) {     dwD3DBehavior = D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED;     if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))         isFormatConfirmed = TRUE; }

DirectX9 Aygıtı Oluşturma ve Çoklu Thread Desteği

DirectX9, özellikle eski nesil oyun geliştirme projelerinde yaygın olarak kullanılan güçlü bir grafik APIsidir. Özellikle Metin2 özel sunucu geliştirme süreçlerinde DirectX9 aygıtı oluşturma işlemi kritik öneme sahiptir. Ancak bu işlem, çoklu iş parçacığı (thread) desteğiyle yapıldığında performans ve kararlılık açısından daha etkili hale gelir. Bu makalede, DirectX9 aygıtı oluşturma işlemini çoklu thread desteğiyle nasıl yapacağımızı detaylıca inceleyeceğiz.

DirectX9 Aygıtı Nedir?

DirectX9 aygıtı (device), grafik komutlarının çalıştırılması için temel bileşendir. Bu aygıt, render işlemlerini yönetir, shader'ları çalıştırır ve ekran çıktısını oluşturur. Bir oyun motoru veya istemci geliştirirken bu aygıtın doğru oluşturulması ve yönetilmesi büyük önem taşır. Özellikle Metin2 client src üzerinde çalışan geliştiriciler, bu aygıt üzerinden arayüz, efekt ve render süreçlerini kontrol ederler.

Çoklu Thread Desteği Neden Gerekli?

Modern oyun geliştirme süreçlerinde, render işlemleri ayrı bir thread üzerinde çalıştırıldığında kullanıcı arayüzü ve oyun mantığı daha akıcı bir şekilde çalışabilir. Bu durum, özellikle Metin2 özel sunucularında yüksek performans istenen sistemlerde tercih edilir. Render thread'leri sayesinde, donmalar ve gecikmeler minimize edilebilir. Ancak DirectX9 aygıtı varsayılan olarak thread-safe değildir. Bu nedenle özel dikkat gösterilmelidir.

DirectX9 Aygıtı Oluşturma Adımları

DirectX9 aygıtı oluşturmak için öncelikle bir IDirect3D9 nesnesi oluşturulmalıdır. Ardından bu nesne üzerinden bir IDirect3DDevice9 nesnesi oluşturulur. Bu işlem sırasında kullanılan parametreler, özellikle D3DCREATE_MULTITHREADED bayrağı ile çoklu thread desteğinin aktif edilmesi gerekir. Aksi takdirde, farklı thread'lerden yapılan erişimlerde hatalar meydana gelebilir.

Örnek Kod Yapısı

IDirect3D9* d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;

d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED, // Burada önemli olan kısım
&d3dpp,
&d3dDevice
);

Thread Güvenliği ve Performans Optimizasyonu[/BR]DirectX9 cihazının thread güvenli olması, aynı anda birden fazla thread'in komut gönderebilmesine olanak tanır. Ancak bu durum performans kaybına da sebep olabilir. Bu nedenle, thread kullanımı sadece gerçekten gerekli olduğunda yapılmalıdır. Örneğin, render ve UI süreçleri farklı thread'lerde çalışıyorsa, bu destek büyük fayda sağlar.

Olası Hatalar ve Çözümleri

DirectX9 aygıtı çoklu thread desteğiyle oluşturulduğunda, bazı driver uyumsuzlukları ve performans sorunları yaşanabilir. Bu durumda, test aşamasında farklı sistemlerde denemeler yapmak önemlidir. Ayrıca, her thread'in kendi IDirect3DQuery nesnesini oluşturması önerilir.

Sonuç

DirectX9 aygıtı oluşturma işlemi, özellikle Metin2 özel sunucu geliştirme süreçlerinde önemli bir rol oynar. Çoklu thread desteğiyle bu işlem yapıldığında performans artışı sağlanabilir ancak dikkatli bir yaklaşım gerekir. Doğru ayarlarla ve dikkatli kodlama ile daha stabil ve hızlı çalışan sistemler inşa edilebilir.


DirectX9 Device Creation and Multi-Thread Support

DirectX9 is a powerful graphics API commonly used in older-generation game development projects. Especially in Metin2 private server development processes, creating a DirectX9 device is critically important. However, when this process is performed with multi-thread support, it becomes more effective in terms of performance and stability. In this article, we will examine in detail how to create a DirectX9 device with multi-thread support.

What Is a DirectX9 Device?

The DirectX9 device is the fundamental component for executing graphics commands. This device manages rendering operations, runs shaders, and generates screen output. When developing a game engine or client, correctly creating and managing this device is crucial. Developers working on Metin2 client src control UI, effects, and rendering processes through this device.

Why Is Multi-Thread Support Necessary?

In modern game development processes, running rendering operations on a separate thread allows the user interface and game logic to function more smoothly. This situation is preferred especially in high-performance systems required in Metin2 private servers. Thanks to render threads, stutters and delays can be minimized. However, the DirectX9 device is not thread-safe by default, so special attention must be paid.

Steps for Creating a DirectX9 Device

To create a DirectX9 device, first an IDirect3D9 object must be created. Then, an IDirect3DDevice9 object is created through this object. During this process, parameters, especially the flag D3DCREATE_MULTITHREADED to enable multi-thread support, must be set correctly. Otherwise, errors may occur during access from different threads.

Sample Code Structure

IDirect3D9* d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;

d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED, // Important part here
&d3dpp,
&d3dDevice
);

Thread Safety and Performance Optimization

Making the DirectX9 device thread-safe allows multiple threads to send commands simultaneously. However, this situation may also cause performance losses. Therefore, thread usage should only be done when truly necessary. For example, if rendering and UI processes are running on different threads, this support provides significant benefits.

Potential Errors and Solutions

When a DirectX9 device is created with multi-thread support, some driver incompatibilities and performance issues may occur. In such cases, testing on different systems during the testing phase is important. Additionally, it is recommended that each thread creates its own IDirect3DQuery object.

Conclusion

Creating a DirectX9 device plays an important role especially in Metin2 private server development processes. When this process is performed with multi-thread support, performance improvements can be achieved, but careful approaches are required. With correct settings and careful coding, more stable and faster systems can be built.
 

Şuan Bu Konuyu Görüntüleyen Kullanıcılar (Toplam : 0, Üye : 0, Misafir : 0)

Geri
Üst Alt