From 39850af147312d74c40c5b5e0dc019158b15af11 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 5 Nov 2019 00:23:31 +1000 Subject: [PATCH] Common: Add GS support to D3D11 shader compiler --- src/common/d3d11/shader_compiler.cpp | 32 ++++++++++++++++++++++------ src/common/d3d11/shader_compiler.h | 2 ++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/common/d3d11/shader_compiler.cpp b/src/common/d3d11/shader_compiler.cpp index c96d06072..8184161b1 100644 --- a/src/common/d3d11/shader_compiler.cpp +++ b/src/common/d3d11/shader_compiler.cpp @@ -17,21 +17,21 @@ ComPtr CompileShader(Type type, D3D_FEATURE_LEVEL feature_level, std:: { case D3D_FEATURE_LEVEL_10_0: { - static constexpr std::array targets = {{"vs_4_0", "ps_4_0", "cs_4_0"}}; + static constexpr std::array targets = {{"vs_4_0", "gs_4_0", "ps_4_0", "cs_4_0"}}; target = targets[static_cast(type)]; } break; case D3D_FEATURE_LEVEL_10_1: { - static constexpr std::array targets = {{"vs_4_1", "ps_4_1", "cs_4_1"}}; + static constexpr std::array targets = {{"vs_4_1", "gs_4_1", "ps_4_1", "cs_4_1"}}; target = targets[static_cast(type)]; } break; case D3D_FEATURE_LEVEL_11_0: { - static constexpr std::array targets = {{"vs_5_0", "ps_5_0", "cs_5_0"}}; + static constexpr std::array targets = {{"vs_5_0", "gs_5_0", "ps_5_0", "cs_5_0"}}; target = targets[static_cast(type)]; } break; @@ -39,7 +39,7 @@ ComPtr CompileShader(Type type, D3D_FEATURE_LEVEL feature_level, std:: case D3D_FEATURE_LEVEL_11_1: default: { - static constexpr std::array targets = {{"vs_5_1", "ps_5_1", "cs_5_1"}}; + static constexpr std::array targets = {{"vs_5_1", "gs_5_1", "ps_5_1", "cs_5_1"}}; target = targets[static_cast(type)]; } break; @@ -91,16 +91,34 @@ ComPtr CompileAndCreateVertexShader(ID3D11Device* device, st if (!blob) return {}; - ComPtr vs; + ComPtr shader; const HRESULT hr = - device->CreateVertexShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, vs.GetAddressOf()); + device->CreateVertexShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, shader.GetAddressOf()); if (FAILED(hr)) { Log_ErrorPrintf("Failed to create vertex shader: 0x%08X", hr); return {}; } - return vs; + return shader; +} + +ComPtr CompileAndCreateGeometryShader(ID3D11Device* device, std::string_view code, bool debug) +{ + ComPtr blob = CompileShader(Type::Geometry, device->GetFeatureLevel(), std::move(code), debug); + if (!blob) + return {}; + + ComPtr shader; + const HRESULT hr = + device->CreateGeometryShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, shader.GetAddressOf()); + if (FAILED(hr)) + { + Log_ErrorPrintf("Failed to create geometry shader: 0x%08X", hr); + return {}; + } + + return shader; } ComPtr CompileAndCreatePixelShader(ID3D11Device* device, std::string_view code, bool debug) diff --git a/src/common/d3d11/shader_compiler.h b/src/common/d3d11/shader_compiler.h index c1fba1481..496778b2e 100644 --- a/src/common/d3d11/shader_compiler.h +++ b/src/common/d3d11/shader_compiler.h @@ -12,6 +12,7 @@ using ComPtr = Microsoft::WRL::ComPtr; enum class Type { Vertex, + Geometry, Pixel, Compute }; @@ -19,6 +20,7 @@ enum class Type ComPtr CompileShader(Type type, D3D_FEATURE_LEVEL feature_level, std::string_view code, bool debug); ComPtr CompileAndCreateVertexShader(ID3D11Device* device, std::string_view code, bool debug); +ComPtr CompileAndCreateGeometryShader(ID3D11Device* device, std::string_view code, bool debug); ComPtr CompileAndCreatePixelShader(ID3D11Device* device, std::string_view code, bool debug); ComPtr CompileAndCreateComputeShader(ID3D11Device* device, std::string_view code, bool debug);