diff --git a/GPU/Common/ShaderTranslation.cpp b/GPU/Common/ShaderTranslation.cpp index 9ca63f2efe..706f43d865 100644 --- a/GPU/Common/ShaderTranslation.cpp +++ b/GPU/Common/ShaderTranslation.cpp @@ -103,7 +103,7 @@ bool TranslateShader(std::string *dest, ShaderLanguage destLang, TranslatedShade case GLSL_VULKAN: return false; // TODO #ifdef _WIN32 - case HLSL_D3D11: + case HLSL_DX9: { spirv_cross::CompilerHLSL hlsl(spirv); spirv_cross::CompilerHLSL::Options options{}; @@ -113,6 +113,16 @@ bool TranslateShader(std::string *dest, ShaderLanguage destLang, TranslatedShade *dest = hlsl.compile(); return true; } + case HLSL_D3D11: + { + spirv_cross::CompilerHLSL hlsl(spirv); + spirv_cross::CompilerHLSL::Options options{}; + options.fixup_clipspace = true; + options.shader_model = 50; + hlsl.set_options(options); + *dest = hlsl.compile(); + return true; + } #endif case GLSL_140: { diff --git a/Windows/GPU/D3D11Context.cpp b/Windows/GPU/D3D11Context.cpp index 015ad07e37..ed78593b9a 100644 --- a/Windows/GPU/D3D11Context.cpp +++ b/Windows/GPU/D3D11Context.cpp @@ -88,6 +88,14 @@ bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) { return false; } + if (FAILED(device_->QueryInterface(__uuidof (ID3D11Device1), (void **)&device1_))) { + device1_ = nullptr; + } + + if (FAILED(context_->QueryInterface(__uuidof (ID3D11DeviceContext1), (void **)&context1_))) { + context1_ = nullptr; + } + #ifdef _DEBUG if (SUCCEEDED(device_->QueryInterface(__uuidof(ID3D11Debug), (void**)&d3dDebug_))) { if (SUCCEEDED(d3dDebug_->QueryInterface(__uuidof(ID3D11InfoQueue), (void**)&d3dInfoQueue_))) { @@ -98,7 +106,7 @@ bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) { } #endif - draw_ = Draw::T3DCreateD3D11Context(device_, context_, hWnd_); + draw_ = Draw::T3DCreateD3D11Context(device_, context_, device1_, context1_, hWnd_); draw_->HandleEvent(Draw::Event::GOT_BACKBUFFER); return true; } @@ -125,8 +133,13 @@ void D3D11Context::Shutdown() { d3dInfoQueue_->Release(); #endif + if (context1_) + context1_->Release(); context_->Release(); context_ = nullptr; + if (device1_) + device1_->Release(); + device1_ = nullptr; device_->Release(); device_ = nullptr; hWnd_ = nullptr; diff --git a/Windows/GPU/D3D11Context.h b/Windows/GPU/D3D11Context.h index 2b71ffbc63..cb63bdf890 100644 --- a/Windows/GPU/D3D11Context.h +++ b/Windows/GPU/D3D11Context.h @@ -22,6 +22,7 @@ #include "Common/CommonWindows.h" #include "Windows/GPU/WindowsGraphicsContext.h" #include +#include class DrawContext; @@ -41,7 +42,9 @@ public: private: Draw::DrawContext *draw_ = nullptr; ID3D11Device *device_ = nullptr; + ID3D11Device1 *device1_ = nullptr; ID3D11DeviceContext *context_ = nullptr; + ID3D11DeviceContext1 *context1_ = nullptr; #ifdef _DEBUG ID3D11Debug *d3dDebug_ = nullptr; diff --git a/ext/native/thin3d/thin3d.h b/ext/native/thin3d/thin3d.h index f6aa2ea946..4676f880ac 100644 --- a/ext/native/thin3d/thin3d.h +++ b/ext/native/thin3d/thin3d.h @@ -27,6 +27,8 @@ struct IDirect3DDevice9Ex; struct IDirect3D9Ex; struct ID3D11Device; struct ID3D11DeviceContext; +struct ID3D11Device1; +struct ID3D11DeviceContext1; #endif @@ -308,6 +310,7 @@ enum InfoField { enum class NativeObject { CONTEXT, + CONTEXT_EX, DEVICE, DEVICE_EX, BACKBUFFER_COLOR_VIEW, @@ -660,7 +663,7 @@ extern const UniformBufferDesc UBPresetDesc; #ifdef _WIN32 DrawContext *T3DCreateDX9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, IDirect3DDevice9 *device, IDirect3DDevice9Ex *deviceEx); -DrawContext *T3DCreateD3D11Context(ID3D11Device *device, ID3D11DeviceContext *context, HWND hWnd); +DrawContext *T3DCreateD3D11Context(ID3D11Device *device, ID3D11DeviceContext *context, ID3D11Device1 *device1, ID3D11DeviceContext1 *context1, HWND hWnd); #endif DrawContext *T3DCreateVulkanContext(VulkanContext *context); diff --git a/ext/native/thin3d/thin3d_d3d11.cpp b/ext/native/thin3d/thin3d_d3d11.cpp index f5989d7a27..40a0016185 100644 --- a/ext/native/thin3d/thin3d_d3d11.cpp +++ b/ext/native/thin3d/thin3d_d3d11.cpp @@ -22,7 +22,7 @@ class D3D11RasterState; class D3D11DrawContext : public DrawContext { public: - D3D11DrawContext(ID3D11Device *device, ID3D11DeviceContext *deviceContext, HWND hWnd); + D3D11DrawContext(ID3D11Device *device, ID3D11DeviceContext *deviceContext, ID3D11Device1 *device1, ID3D11DeviceContext1 *deviceContext1, HWND hWnd); ~D3D11DrawContext(); const DeviceCaps &GetDeviceCaps() const override { @@ -101,6 +101,10 @@ public: return (uintptr_t)device_; case NativeObject::CONTEXT: return (uintptr_t)context_; + case NativeObject::DEVICE_EX: + return (uintptr_t)device1_; + case NativeObject::CONTEXT_EX: + return (uintptr_t)context1_; case NativeObject::BACKBUFFER_COLOR_TEX: return (uintptr_t)bbRenderTargetTex_; case NativeObject::BACKBUFFER_DEPTH_TEX: @@ -122,6 +126,8 @@ private: HWND hWnd_; ID3D11Device *device_; ID3D11DeviceContext *context_; + ID3D11Device1 *device1_; + ID3D11DeviceContext1 *context1_; IDXGISwapChain *swapChain_ = nullptr; bool b4g4r4a4Supported_ = false; @@ -168,7 +174,12 @@ static void GetRes(HWND hWnd, int &xres, int &yres) { yres = rc.bottom - rc.top; } -D3D11DrawContext::D3D11DrawContext(ID3D11Device *device, ID3D11DeviceContext *context, HWND hWnd) : device_(device), context_(context), hWnd_(hWnd) { +D3D11DrawContext::D3D11DrawContext(ID3D11Device *device, ID3D11DeviceContext *deviceContext, ID3D11Device1 *device1, ID3D11DeviceContext1 *deviceContext1, HWND hWnd) + : device_(device), + context_(deviceContext1), + device1_(device1), + context1_(deviceContext1), + hWnd_(hWnd) { HRESULT hr; // Obtain DXGI factory from device (since we used nullptr for pAdapter above) IDXGIFactory1* dxgiFactory = nullptr; @@ -1256,8 +1267,8 @@ void D3D11DrawContext::GetFramebufferDimensions(Framebuffer *fbo, int *w, int *h *h = fb->height; } -DrawContext *T3DCreateD3D11Context(ID3D11Device *device, ID3D11DeviceContext *context, HWND hWnd) { - return new D3D11DrawContext(device, context, hWnd); +DrawContext *T3DCreateD3D11Context(ID3D11Device *device, ID3D11DeviceContext *context, ID3D11Device1 *device1, ID3D11DeviceContext1 *context1, HWND hWnd) { + return new D3D11DrawContext(device, context, device1, context1, hWnd); } } // namespace Draw \ No newline at end of file