diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index 4baa21db47..d1f84e3308 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -179,7 +179,7 @@ endif()
if(WIN32)
enable_language(ASM_MASM)
target_sources(common PRIVATE FastJmp.asm)
- target_link_libraries(common PUBLIC WIL::WIL D3D12MemAlloc winmm)
+ target_link_libraries(common PUBLIC WIL::WIL winmm)
target_sources(common PRIVATE
CrashHandler.cpp
CrashHandler.h
@@ -188,24 +188,6 @@ if(WIN32)
HTTPDownloaderWinHTTP.h
StackWalker.cpp
StackWalker.h
- D3D11/ShaderCache.cpp
- D3D11/ShaderCache.h
- D3D11/ShaderCompiler.cpp
- D3D11/ShaderCompiler.h
- D3D12/Builders.cpp
- D3D12/Builders.h
- D3D12/Context.cpp
- D3D12/Context.h
- D3D12/DescriptorHeapManager.cpp
- D3D12/DescriptorHeapManager.h
- D3D12/ShaderCache.cpp
- D3D12/ShaderCache.h
- D3D12/StreamBuffer.cpp
- D3D12/StreamBuffer.h
- D3D12/Texture.cpp
- D3D12/Texture.h
- D3D12/Util.cpp
- D3D12/Util.h
)
endif()
diff --git a/common/D3D11/ShaderCache.h b/common/D3D11/ShaderCache.h
deleted file mode 100644
index 001aa14d94..0000000000
--- a/common/D3D11/ShaderCache.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/* PCSX2 - PS2 Emulator for PCs
- * Copyright (C) 2002-2022 PCSX2 Dev Team
- *
- * PCSX2 is free software: you can redistribute it and/or modify it under the terms
- * of the GNU Lesser General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with PCSX2.
- * If not, see .
- */
-
-#pragma once
-#include "common/Pcsx2Defs.h"
-#include "common/HashCombine.h"
-#include "common/RedtapeWindows.h"
-#include "common/RedtapeWilCom.h"
-#include "common/D3D11/ShaderCompiler.h"
-
-#include
-#include
-#include
-#include
-#include
-
-namespace D3D11
-{
- class ShaderCache
- {
- public:
- ShaderCache();
- ~ShaderCache();
-
- D3D_FEATURE_LEVEL GetFeatureLevel() const { return m_feature_level; }
- bool UsingDebugShaders() const { return m_debug; }
-
- bool Open(std::string_view base_path, D3D_FEATURE_LEVEL feature_level, u32 version, bool debug);
- void Close();
-
- wil::com_ptr_nothrow GetShaderBlob(ShaderCompiler::Type type, const std::string_view& shader_code,
- const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
-
- wil::com_ptr_nothrow GetVertexShader(ID3D11Device* device, const std::string_view& shader_code,
- const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
-
- bool GetVertexShaderAndInputLayout(ID3D11Device* device,
- ID3D11VertexShader** vs, ID3D11InputLayout** il,
- const D3D11_INPUT_ELEMENT_DESC* layout, size_t layout_size,
- const std::string_view& shader_code, const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
-
- wil::com_ptr_nothrow GetPixelShader(ID3D11Device* device, const std::string_view& shader_code,
- const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
-
- wil::com_ptr_nothrow GetComputeShader(ID3D11Device* device, const std::string_view& shader_code,
- const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
-
- private:
- static constexpr u32 FILE_VERSION = 1;
-
- struct CacheIndexKey
- {
- u64 source_hash_low;
- u64 source_hash_high;
- u64 macro_hash_low;
- u64 macro_hash_high;
- u64 entry_point_low;
- u64 entry_point_high;
- u32 source_length;
- ShaderCompiler::Type shader_type;
-
- bool operator==(const CacheIndexKey& key) const;
- bool operator!=(const CacheIndexKey& key) const;
- };
-
- struct CacheIndexEntryHasher
- {
- std::size_t operator()(const CacheIndexKey& e) const noexcept
- {
- std::size_t h = 0;
- HashCombine(h, e.entry_point_low, e.entry_point_high, e.macro_hash_low, e.macro_hash_high,
- e.source_hash_low, e.source_hash_high, e.source_length, e.shader_type);
- return h;
- }
- };
-
- struct CacheIndexData
- {
- u32 file_offset;
- u32 blob_size;
- };
-
- using CacheIndex = std::unordered_map;
-
- static std::string GetCacheBaseFileName(const std::string_view& base_path, D3D_FEATURE_LEVEL feature_level,
- bool debug);
- static CacheIndexKey GetCacheKey(ShaderCompiler::Type type, const std::string_view& shader_code,
- const D3D_SHADER_MACRO* macros, const char* entry_point);
-
- bool CreateNew(const std::string& index_filename, const std::string& blob_filename);
- bool ReadExisting(const std::string& index_filename, const std::string& blob_filename);
-
- wil::com_ptr_nothrow CompileAndAddShaderBlob(const CacheIndexKey& key, const std::string_view& shader_code,
- const D3D_SHADER_MACRO* macros, const char* entry_point);
-
- std::FILE* m_index_file = nullptr;
- std::FILE* m_blob_file = nullptr;
-
- CacheIndex m_index;
-
- D3D_FEATURE_LEVEL m_feature_level = D3D_FEATURE_LEVEL_11_0;
- u32 m_version = 0;
- bool m_debug = false;
- };
-} // namespace D3D11
diff --git a/common/D3D11/ShaderCompiler.cpp b/common/D3D11/ShaderCompiler.cpp
deleted file mode 100644
index 39b78be5a0..0000000000
--- a/common/D3D11/ShaderCompiler.cpp
+++ /dev/null
@@ -1,186 +0,0 @@
-/* PCSX2 - PS2 Emulator for PCs
- * Copyright (C) 2002-2022 PCSX2 Dev Team
- *
- * PCSX2 is free software: you can redistribute it and/or modify it under the terms
- * of the GNU Lesser General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with PCSX2.
- * If not, see .
- */
-
-#include "common/PrecompiledHeader.h"
-#include "common/D3D11/ShaderCompiler.h"
-#include "common/Console.h"
-#include "common/StringUtil.h"
-#include
-#include
-#include
-
-static unsigned s_next_bad_shader_id = 1;
-
-wil::com_ptr_nothrow D3D11::ShaderCompiler::CompileShader(Type type, D3D_FEATURE_LEVEL feature_level, bool debug,
- const std::string_view& code, const D3D_SHADER_MACRO* macros /* = nullptr */, const char* entry_point /* = "main" */)
-{
- const char* target;
- switch (feature_level)
- {
- case D3D_FEATURE_LEVEL_10_0:
- {
- static constexpr std::array targets = {{"vs_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"}};
- 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"}};
- target = targets[static_cast(type)];
- }
- break;
-
- case D3D_FEATURE_LEVEL_11_1:
- default:
- {
- static constexpr std::array targets = {{"vs_5_1", "ps_5_1", "cs_5_1"}};
- target = targets[static_cast(type)];
- }
- break;
- }
-
- static constexpr UINT flags_non_debug = D3DCOMPILE_OPTIMIZATION_LEVEL3;
- static constexpr UINT flags_debug = D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_DEBUG;
-
- wil::com_ptr_nothrow blob;
- wil::com_ptr_nothrow error_blob;
- const HRESULT hr =
- D3DCompile(code.data(), code.size(), "0", macros, nullptr, entry_point, target, debug ? flags_debug : flags_non_debug,
- 0, blob.put(), error_blob.put());
-
- std::string error_string;
- if (error_blob)
- {
- error_string.append(static_cast(error_blob->GetBufferPointer()), error_blob->GetBufferSize());
- error_blob.reset();
- }
-
- if (FAILED(hr))
- {
- Console.WriteLn("Failed to compile '%s':\n%s", target, error_string.c_str());
-
- std::ofstream ofs(StringUtil::StdStringFromFormat("pcsx2_bad_shader_%u.txt", s_next_bad_shader_id++).c_str(),
- std::ofstream::out | std::ofstream::binary);
- if (ofs.is_open())
- {
- ofs << code;
- ofs << "\n\nCompile as " << target << " failed: " << hr << "\n";
- ofs.write(error_string.c_str(), error_string.size());
- ofs.close();
- }
-
- return {};
- }
-
- if (!error_string.empty())
- Console.Warning("'%s' compiled with warnings:\n%s", target, error_string.c_str());
-
- return blob;
-}
-
-wil::com_ptr_nothrow D3D11::ShaderCompiler::CompileAndCreateVertexShader(ID3D11Device* device, bool debug,
- const std::string_view& code, const D3D_SHADER_MACRO* macros /* = nullptr */, const char* entry_point /* = "main" */)
-{
- wil::com_ptr_nothrow blob = CompileShader(Type::Vertex, device->GetFeatureLevel(), debug, code, macros, entry_point);
- if (!blob)
- return {};
-
- return CreateVertexShader(device, blob.get());
-}
-
-wil::com_ptr_nothrow D3D11::ShaderCompiler::CompileAndCreatePixelShader(ID3D11Device* device, bool debug,
- const std::string_view& code, const D3D_SHADER_MACRO* macros /* = nullptr */, const char* entry_point /* = "main" */)
-{
- wil::com_ptr_nothrow blob = CompileShader(Type::Pixel, device->GetFeatureLevel(), debug, code, macros, entry_point);
- if (!blob)
- return {};
-
- return CreatePixelShader(device, blob.get());
-}
-
-wil::com_ptr_nothrow D3D11::ShaderCompiler::CompileAndCreateComputeShader(ID3D11Device* device, bool debug,
- const std::string_view& code, const D3D_SHADER_MACRO* macros /* = nullptr */, const char* entry_point /* = "main" */)
-{
- wil::com_ptr_nothrow blob = CompileShader(Type::Compute, device->GetFeatureLevel(), debug, code, macros, entry_point);
- if (!blob)
- return {};
-
- return CreateComputeShader(device, blob.get());
-}
-
-wil::com_ptr_nothrow D3D11::ShaderCompiler::CreateVertexShader(ID3D11Device* device, const void* bytecode, size_t bytecode_length)
-{
- wil::com_ptr_nothrow shader;
- const HRESULT hr = device->CreateVertexShader(bytecode, bytecode_length, nullptr, shader.put());
- if (FAILED(hr))
- {
- Console.Error("Failed to create vertex shader: 0x%08X", hr);
- return {};
- }
-
- return shader;
-}
-
-wil::com_ptr_nothrow D3D11::ShaderCompiler::CreateVertexShader(ID3D11Device* device, const ID3DBlob* blob)
-{
- return CreateVertexShader(device, const_cast(blob)->GetBufferPointer(),
- const_cast(blob)->GetBufferSize());
-}
-
-wil::com_ptr_nothrow D3D11::ShaderCompiler::CreatePixelShader(ID3D11Device* device, const void* bytecode, size_t bytecode_length)
-{
- wil::com_ptr_nothrow shader;
- const HRESULT hr = device->CreatePixelShader(bytecode, bytecode_length, nullptr, shader.put());
- if (FAILED(hr))
- {
- Console.Error("Failed to create pixel shader: 0x%08X", hr);
- return {};
- }
-
- return shader;
-}
-
-wil::com_ptr_nothrow D3D11::ShaderCompiler::CreatePixelShader(ID3D11Device* device, const ID3DBlob* blob)
-{
- return CreatePixelShader(device, const_cast(blob)->GetBufferPointer(),
- const_cast(blob)->GetBufferSize());
-}
-
-wil::com_ptr_nothrow D3D11::ShaderCompiler::CreateComputeShader(ID3D11Device* device, const void* bytecode, size_t bytecode_length)
-{
- wil::com_ptr_nothrow shader;
- const HRESULT hr = device->CreateComputeShader(bytecode, bytecode_length, nullptr, shader.put());
- if (FAILED(hr))
- {
- Console.Error("Failed to create compute shader: 0x%08X", hr);
- return {};
- }
-
- return shader;
-}
-
-wil::com_ptr_nothrow D3D11::ShaderCompiler::CreateComputeShader(ID3D11Device* device, const ID3DBlob* blob)
-{
- return CreateComputeShader(device, const_cast(blob)->GetBufferPointer(),
- const_cast(blob)->GetBufferSize());
-}
diff --git a/common/D3D11/ShaderCompiler.h b/common/D3D11/ShaderCompiler.h
deleted file mode 100644
index fb2be0eb6a..0000000000
--- a/common/D3D11/ShaderCompiler.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* PCSX2 - PS2 Emulator for PCs
- * Copyright (C) 2002-2022 PCSX2 Dev Team
- *
- * PCSX2 is free software: you can redistribute it and/or modify it under the terms
- * of the GNU Lesser General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with PCSX2.
- * If not, see .
- */
-
-#pragma once
-
-#include "common/RedtapeWindows.h"
-#include "common/RedtapeWilCom.h"
-
-#include
-#include
-#include
-
-namespace D3D11::ShaderCompiler
-{
- enum class Type
- {
- Vertex,
- Pixel,
- Compute
- };
-
- wil::com_ptr_nothrow CompileShader(Type type, D3D_FEATURE_LEVEL feature_level, bool debug, const std::string_view& code,
- const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
-
- wil::com_ptr_nothrow CompileAndCreateVertexShader(ID3D11Device* device, bool debug, const std::string_view& code,
- const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
- wil::com_ptr_nothrow CompileAndCreatePixelShader(ID3D11Device* device, bool debug, const std::string_view& code,
- const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
- wil::com_ptr_nothrow CompileAndCreateComputeShader(ID3D11Device* device, bool debug, const std::string_view& code,
- const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
-
- wil::com_ptr_nothrow CreateVertexShader(ID3D11Device* device, const void* bytecode, size_t bytecode_length);
- wil::com_ptr_nothrow CreateVertexShader(ID3D11Device* device, const ID3DBlob* blob);
- wil::com_ptr_nothrow CreatePixelShader(ID3D11Device* device, const void* bytecode, size_t bytecode_length);
- wil::com_ptr_nothrow CreatePixelShader(ID3D11Device* device, const ID3DBlob* blob);
- wil::com_ptr_nothrow CreateComputeShader(ID3D11Device* device, const void* bytecode, size_t bytecode_length);
- wil::com_ptr_nothrow CreateComputeShader(ID3D11Device* device, const ID3DBlob* blob);
-}; // namespace D3D11::ShaderCompiler
diff --git a/common/D3D12/Context.h b/common/D3D12/Context.h
deleted file mode 100644
index 74c2769978..0000000000
--- a/common/D3D12/Context.h
+++ /dev/null
@@ -1,219 +0,0 @@
-/* PCSX2 - PS2 Emulator for PCs
- * Copyright (C) 2002-2022 PCSX2 Dev Team
- *
- * PCSX2 is free software: you can redistribute it and/or modify it under the terms
- * of the GNU Lesser General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with PCSX2.
- * If not, see .
- */
-
-#pragma once
-
-#include "common/Pcsx2Defs.h"
-#include "common/RedtapeWindows.h"
-#include "common/D3D12/DescriptorHeapManager.h"
-#include "common/D3D12/StreamBuffer.h"
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-struct IDXGIAdapter;
-struct IDXGIFactory;
-namespace D3D12MA
-{
- class Allocator;
- class Allocation;
-} // namespace D3D12MA
-
-namespace D3D12
-{
- class Context
- {
- public:
- template
- using ComPtr = wil::com_ptr_nothrow;
-
- enum : u32
- {
- /// Number of command lists. One is being built while the other(s) are executed.
- NUM_COMMAND_LISTS = 3,
-
- /// Textures that don't fit into this buffer will be uploaded with a staging buffer.
- TEXTURE_UPLOAD_BUFFER_SIZE = 64 * 1024 * 1024,
-
- /// Maximum number of samples in a single allocation group.
- SAMPLER_GROUP_SIZE = 2,
-
- /// Start/End timestamp queries.
- NUM_TIMESTAMP_QUERIES_PER_CMDLIST = 2,
- };
-
- ~Context();
-
- /// Creates new device and context.
- static bool Create(IDXGIFactory5* dxgi_factory, IDXGIAdapter1* adapter, bool enable_debug_layer);
-
- /// Destroys active context.
- static void Destroy();
-
- __fi IDXGIAdapter* GetAdapter() const { return m_adapter.get(); }
- __fi ID3D12Device* GetDevice() const { return m_device.get(); }
- __fi ID3D12CommandQueue* GetCommandQueue() const { return m_command_queue.get(); }
- __fi D3D12MA::Allocator* GetAllocator() const { return m_allocator.get(); }
-
- /// Returns the PCI vendor ID of the device, if known.
- u32 GetAdapterVendorID() const;
-
- /// Returns the current command list, commands can be recorded directly.
- ID3D12GraphicsCommandList4* GetCommandList() const
- {
- return m_command_lists[m_current_command_list].command_lists[1].get();
- }
-
- /// Returns the init command list for uploading.
- ID3D12GraphicsCommandList4* GetInitCommandList();
-
- /// Returns the per-frame SRV/CBV/UAV allocator.
- DescriptorAllocator& GetDescriptorAllocator()
- {
- return m_command_lists[m_current_command_list].descriptor_allocator;
- }
-
- /// Returns the per-frame sampler allocator.
- GroupedSamplerAllocator& GetSamplerAllocator()
- {
- return m_command_lists[m_current_command_list].sampler_allocator;
- }
-
- /// Invalidates GPU-side sampler caches for all command lists. Call after you've freed samplers,
- /// and are going to re-use the handles from GetSamplerHeapManager().
- void InvalidateSamplerGroups();
-
- // Descriptor manager access.
- DescriptorHeapManager& GetDescriptorHeapManager() { return m_descriptor_heap_manager; }
- DescriptorHeapManager& GetRTVHeapManager() { return m_rtv_heap_manager; }
- DescriptorHeapManager& GetDSVHeapManager() { return m_dsv_heap_manager; }
- DescriptorHeapManager& GetSamplerHeapManager() { return m_sampler_heap_manager; }
- const DescriptorHandle& GetNullSRVDescriptor() const { return m_null_srv_descriptor; }
- StreamBuffer& GetTextureStreamBuffer() { return m_texture_stream_buffer; }
-
- // Root signature access.
- ComPtr SerializeRootSignature(const D3D12_ROOT_SIGNATURE_DESC* desc);
- ComPtr CreateRootSignature(const D3D12_ROOT_SIGNATURE_DESC* desc);
-
- /// Fence value for current command list.
- u64 GetCurrentFenceValue() const { return m_current_fence_value; }
-
- /// Last "completed" fence.
- u64 GetCompletedFenceValue() const { return m_completed_fence_value; }
-
- /// Feature level to use when compiling shaders.
- D3D_FEATURE_LEVEL GetFeatureLevel() const { return m_feature_level; }
-
- /// Test for support for the specified texture format.
- bool SupportsTextureFormat(DXGI_FORMAT format);
-
- enum class WaitType
- {
- None, ///< Don't wait (async)
- Sleep, ///< Wait normally
- Spin, ///< Wait by spinning
- };
-
- /// Executes the current command list.
- bool ExecuteCommandList(WaitType wait_for_completion);
-
- /// Waits for a specific fence.
- void WaitForFence(u64 fence, bool spin);
-
- /// Waits for any in-flight command buffers to complete.
- void WaitForGPUIdle();
-
- /// Defers destruction of a D3D resource (associates it with the current list).
- void DeferObjectDestruction(ID3D12DeviceChild* resource);
-
- /// Defers destruction of a D3D resource (associates it with the current list).
- void DeferResourceDestruction(D3D12MA::Allocation* allocation, ID3D12Resource* resource);
-
- /// Defers destruction of a descriptor handle (associates it with the current list).
- void DeferDescriptorDestruction(DescriptorHeapManager& manager, u32 index);
- void DeferDescriptorDestruction(DescriptorHeapManager& manager, DescriptorHandle* handle);
-
- float GetAndResetAccumulatedGPUTime();
- void SetEnableGPUTiming(bool enabled);
-
- // Allocates a temporary CPU staging buffer, fires the callback with it to populate, then copies to a GPU buffer.
- bool AllocatePreinitializedGPUBuffer(u32 size, ID3D12Resource** gpu_buffer, D3D12MA::Allocation** gpu_allocation,
- const std::function& fill_callback);
-
- private:
- struct CommandListResources
- {
- std::array, 2> command_allocators;
- std::array, 2> command_lists;
- DescriptorAllocator descriptor_allocator;
- GroupedSamplerAllocator sampler_allocator;
- std::vector> pending_resources;
- std::vector> pending_descriptors;
- u64 ready_fence_value = 0;
- bool init_command_list_used = false;
- bool has_timestamp_query = false;
- };
-
- Context();
-
- bool CreateDevice(IDXGIFactory5* dxgi_factory, IDXGIAdapter1* adapter, bool enable_debug_layer);
- bool CreateCommandQueue();
- bool CreateAllocator();
- bool CreateFence();
- bool CreateDescriptorHeaps();
- bool CreateCommandLists();
- bool CreateTextureStreamBuffer();
- bool CreateTimestampQuery();
- void MoveToNextCommandList();
- void DestroyPendingResources(CommandListResources& cmdlist);
- void DestroyResources();
-
- ComPtr m_adapter;
- ComPtr m_debug_interface;
- ComPtr m_device;
- ComPtr m_command_queue;
- ComPtr m_allocator;
-
- ComPtr m_fence;
- HANDLE m_fence_event = {};
- u32 m_current_fence_value = 0;
- u64 m_completed_fence_value = 0;
-
- std::array m_command_lists;
- u32 m_current_command_list = NUM_COMMAND_LISTS - 1;
-
- ComPtr m_timestamp_query_heap;
- ComPtr m_timestamp_query_buffer;
- ComPtr m_timestamp_query_allocation;
- double m_timestamp_frequency = 0.0;
- float m_accumulated_gpu_time = 0.0f;
- bool m_gpu_timing_enabled = false;
-
- DescriptorHeapManager m_descriptor_heap_manager;
- DescriptorHeapManager m_rtv_heap_manager;
- DescriptorHeapManager m_dsv_heap_manager;
- DescriptorHeapManager m_sampler_heap_manager;
- DescriptorHandle m_null_srv_descriptor;
- StreamBuffer m_texture_stream_buffer;
-
- D3D_FEATURE_LEVEL m_feature_level = D3D_FEATURE_LEVEL_11_0;
- };
-} // namespace D3D12
-
-extern std::unique_ptr g_d3d12_context;
diff --git a/common/D3D12/DescriptorHeapManager.h b/common/D3D12/DescriptorHeapManager.h
deleted file mode 100644
index 875ee6cb5f..0000000000
--- a/common/D3D12/DescriptorHeapManager.h
+++ /dev/null
@@ -1,269 +0,0 @@
-/* PCSX2 - PS2 Emulator for PCs
- * Copyright (C) 2002-2022 PCSX2 Dev Team
- *
- * PCSX2 is free software: you can redistribute it and/or modify it under the terms
- * of the GNU Lesser General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with PCSX2.
- * If not, see .
- */
-
-#pragma once
-
-#include "common/Pcsx2Defs.h"
-#include "common/HashCombine.h"
-#include "common/RedtapeWindows.h"
-#include "common/RedtapeWilCom.h"
-
-#include
-#include
-#include
-#include
-#include
-
-namespace D3D12
-{
- // This class provides an abstraction for D3D12 descriptor heaps.
- struct DescriptorHandle final
- {
- enum : u32
- {
- INVALID_INDEX = 0xFFFFFFFF
- };
-
- D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle{};
- D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle{};
- u32 index = INVALID_INDEX;
-
- __fi operator bool() const { return index != INVALID_INDEX; }
-
- __fi operator D3D12_CPU_DESCRIPTOR_HANDLE() const { return cpu_handle; }
- __fi operator D3D12_GPU_DESCRIPTOR_HANDLE() const { return gpu_handle; }
-
- __fi bool operator==(const DescriptorHandle& rhs) const { return (index == rhs.index); }
- __fi bool operator!=(const DescriptorHandle& rhs) const { return (index != rhs.index); }
- __fi bool operator<(const DescriptorHandle& rhs) const { return (index < rhs.index); }
- __fi bool operator<=(const DescriptorHandle& rhs) const { return (index <= rhs.index); }
- __fi bool operator>(const DescriptorHandle& rhs) const { return (index > rhs.index); }
- __fi bool operator>=(const DescriptorHandle& rhs) const { return (index >= rhs.index); }
-
- __fi void Clear()
- {
- cpu_handle = {};
- gpu_handle = {};
- index = INVALID_INDEX;
- }
- };
-
- class DescriptorHeapManager final
- {
- public:
- DescriptorHeapManager();
- ~DescriptorHeapManager();
-
- ID3D12DescriptorHeap* GetDescriptorHeap() const { return m_descriptor_heap.get(); }
- u32 GetDescriptorIncrementSize() const { return m_descriptor_increment_size; }
-
- bool Create(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_TYPE type, u32 num_descriptors, bool shader_visible);
- void Destroy();
-
- bool Allocate(DescriptorHandle* handle);
- void Free(DescriptorHandle* handle);
- void Free(u32 index);
-
- private:
- wil::com_ptr_nothrow m_descriptor_heap;
- u32 m_num_descriptors = 0;
- u32 m_descriptor_increment_size = 0;
- bool m_shader_visible = false;
-
- D3D12_CPU_DESCRIPTOR_HANDLE m_heap_base_cpu = {};
- D3D12_GPU_DESCRIPTOR_HANDLE m_heap_base_gpu = {};
-
- static constexpr u32 BITSET_SIZE = 1024;
- using BitSetType = std::bitset;
- std::vector m_free_slots = {};
- };
-
- class DescriptorAllocator
- {
- public:
- DescriptorAllocator();
- ~DescriptorAllocator();
-
- __fi ID3D12DescriptorHeap* GetDescriptorHeap() const { return m_descriptor_heap.get(); }
- __fi u32 GetDescriptorIncrementSize() const { return m_descriptor_increment_size; }
-
- bool Create(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_TYPE type, u32 num_descriptors);
- void Destroy();
-
- bool Allocate(u32 num_handles, DescriptorHandle* out_base_handle);
- void Reset();
-
- private:
- wil::com_ptr_nothrow m_descriptor_heap;
- u32 m_descriptor_increment_size = 0;
- u32 m_num_descriptors = 0;
- u32 m_current_offset = 0;
-
- D3D12_CPU_DESCRIPTOR_HANDLE m_heap_base_cpu = {};
- D3D12_GPU_DESCRIPTOR_HANDLE m_heap_base_gpu = {};
- };
-
- template
- class GroupedSamplerAllocator : private DescriptorAllocator
- {
- struct Key
- {
- u32 idx[NumSamplers];
-
- __fi bool operator==(const Key& rhs) const
- {
- return (std::memcmp(idx, rhs.idx, sizeof(idx)) == 0);
- }
- __fi bool operator!=(const Key& rhs) const
- {
- return (std::memcmp(idx, rhs.idx, sizeof(idx)) != 0);
- }
- };
-
- struct KeyHash
- {
- __fi std::size_t operator()(const Key& key) const
- {
- size_t seed = 0;
- for (u32 key : key.idx)
- HashCombine(seed, key);
- return seed;
- }
- };
-
-
- public:
- GroupedSamplerAllocator();
- ~GroupedSamplerAllocator();
-
- using DescriptorAllocator::GetDescriptorHeap;
- using DescriptorAllocator::GetDescriptorIncrementSize;
-
- bool Create(ID3D12Device* device, u32 num_descriptors);
- void Destroy();
-
- bool LookupSingle(DescriptorHandle* gpu_handle, const DescriptorHandle& cpu_handle);
- bool LookupGroup(DescriptorHandle* gpu_handle, const DescriptorHandle* cpu_handles);
-
- // Clears cache but doesn't reset allocator.
- void InvalidateCache();
-
- void Reset();
- bool ShouldReset() const;
-
- private:
- wil::com_ptr_nothrow m_device;
- std::unordered_map m_groups;
- };
-
- template
- GroupedSamplerAllocator::GroupedSamplerAllocator() = default;
-
- template
- GroupedSamplerAllocator::~GroupedSamplerAllocator() = default;
-
- template
- bool GroupedSamplerAllocator::Create(ID3D12Device* device, u32 num_descriptors)
- {
- if (!DescriptorAllocator::Create(device, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, num_descriptors))
- return false;
-
- m_device = device;
- return true;
- }
-
- template
- void GroupedSamplerAllocator::Destroy()
- {
- DescriptorAllocator::Destroy();
- m_device.reset();
- }
-
- template
- void GroupedSamplerAllocator::Reset()
- {
- m_groups.clear();
- DescriptorAllocator::Reset();
- }
-
- template
- void GroupedSamplerAllocator::InvalidateCache()
- {
- m_groups.clear();
- }
-
- template
- bool GroupedSamplerAllocator::LookupSingle(DescriptorHandle* gpu_handle, const DescriptorHandle& cpu_handle)
- {
- Key key;
- key.idx[0] = cpu_handle.index;
- for (u32 i = 1; i < NumSamplers; i++)
- key.idx[i] = 0;
-
- auto it = m_groups.find(key);
- if (it != m_groups.end())
- {
- *gpu_handle = it->second;
- return true;
- }
-
- if (!Allocate(1, gpu_handle))
- return false;
-
- m_device->CopyDescriptorsSimple(1, *gpu_handle, cpu_handle, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
- m_groups.emplace(key, *gpu_handle);
- return true;
- }
-
- template
- bool GroupedSamplerAllocator::LookupGroup(DescriptorHandle* gpu_handle, const DescriptorHandle* cpu_handles)
- {
- Key key;
- for (u32 i = 0; i < NumSamplers; i++)
- key.idx[i] = cpu_handles[i].index;
-
- auto it = m_groups.find(key);
- if (it != m_groups.end())
- {
- *gpu_handle = it->second;
- return true;
- }
-
- if (!Allocate(NumSamplers, gpu_handle))
- return false;
-
- D3D12_CPU_DESCRIPTOR_HANDLE dst_handle = *gpu_handle;
- UINT dst_size = NumSamplers;
- D3D12_CPU_DESCRIPTOR_HANDLE src_handles[NumSamplers];
- UINT src_sizes[NumSamplers];
- for (u32 i = 0; i < NumSamplers; i++)
- {
- src_handles[i] = cpu_handles[i];
- src_sizes[i] = 1;
- }
- m_device->CopyDescriptors(1, &dst_handle, &dst_size, NumSamplers, src_handles, src_sizes, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
-
- m_groups.emplace(key, *gpu_handle);
- return true;
- }
-
- template
- bool GroupedSamplerAllocator::ShouldReset() const
- {
- // We only reset the sampler heap if more than half of the descriptors are used.
- // This saves descriptor copying when there isn't a large number of sampler configs per frame.
- return m_groups.size() >= (D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE / 2);
- }
-} // namespace D3D12
diff --git a/common/D3D12/ShaderCache.h b/common/D3D12/ShaderCache.h
deleted file mode 100644
index dfca321829..0000000000
--- a/common/D3D12/ShaderCache.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/* PCSX2 - PS2 Emulator for PCs
- * Copyright (C) 2002-2022 PCSX2 Dev Team
- *
- * PCSX2 is free software: you can redistribute it and/or modify it under the terms
- * of the GNU Lesser General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with PCSX2.
- * If not, see .
- */
-
-#pragma once
-
-#include "common/Pcsx2Defs.h"
-#include "common/HashCombine.h"
-#include "common/RedtapeWindows.h"
-#include "common/RedtapeWilCom.h"
-
-#include
-#include
-#include
-#include
-#include
-
-namespace D3D12
-{
- class ShaderCache
- {
- public:
- template
- using ComPtr = wil::com_ptr_nothrow;
-
- enum class EntryType
- {
- VertexShader,
- PixelShader,
- ComputeShader,
- GraphicsPipeline,
- ComputePipeline,
- };
-
- ShaderCache();
- ~ShaderCache();
-
- __fi D3D_FEATURE_LEVEL GetFeatureLevel() const { return m_feature_level; }
- __fi u32 GetDataVersion() const { return m_data_version; }
- __fi bool UsingDebugShaders() const { return m_debug; }
-
- bool Open(std::string_view base_path, D3D_FEATURE_LEVEL feature_level, u32 version, bool debug);
- void Close();
-
- __fi ComPtr GetVertexShader(std::string_view shader_code,
- const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main")
- {
- return GetShaderBlob(EntryType::VertexShader, shader_code, macros, entry_point);
- }
- __fi ComPtr GetPixelShader(std::string_view shader_code,
- const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main")
- {
- return GetShaderBlob(EntryType::PixelShader, shader_code, macros, entry_point);
- }
- __fi ComPtr GetComputeShader(std::string_view shader_code,
- const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main")
- {
- return GetShaderBlob(EntryType::ComputeShader, shader_code, macros, entry_point);
- }
-
- ComPtr GetShaderBlob(EntryType type, std::string_view shader_code,
- const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
-
- ComPtr GetPipelineState(ID3D12Device* device, const D3D12_GRAPHICS_PIPELINE_STATE_DESC& desc);
- ComPtr GetPipelineState(ID3D12Device* device, const D3D12_COMPUTE_PIPELINE_STATE_DESC& desc);
-
- private:
- static constexpr u32 FILE_VERSION = 1;
-
- struct CacheIndexKey
- {
- u64 source_hash_low;
- u64 source_hash_high;
- u64 macro_hash_low;
- u64 macro_hash_high;
- u64 entry_point_low;
- u64 entry_point_high;
- u32 source_length;
- EntryType type;
-
- bool operator==(const CacheIndexKey& key) const;
- bool operator!=(const CacheIndexKey& key) const;
- };
-
- struct CacheIndexEntryHasher
- {
- std::size_t operator()(const CacheIndexKey& e) const noexcept
- {
- std::size_t h = 0;
- HashCombine(h, e.entry_point_low, e.entry_point_high, e.macro_hash_low, e.macro_hash_high,
- e.source_hash_low, e.source_hash_high, e.source_length, e.type);
- return h;
- }
- };
-
- struct CacheIndexData
- {
- u32 file_offset;
- u32 blob_size;
- };
-
- using CacheIndex = std::unordered_map;
-
- static std::string GetCacheBaseFileName(const std::string_view& base_path, const std::string_view& type,
- D3D_FEATURE_LEVEL feature_level, bool debug);
- static CacheIndexKey GetShaderCacheKey(EntryType type, const std::string_view& shader_code,
- const D3D_SHADER_MACRO* macros, const char* entry_point);
- static CacheIndexKey GetPipelineCacheKey(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& gpdesc);
- static CacheIndexKey GetPipelineCacheKey(const D3D12_COMPUTE_PIPELINE_STATE_DESC& gpdesc);
-
- bool CreateNew(const std::string& index_filename, const std::string& blob_filename, std::FILE*& index_file,
- std::FILE*& blob_file);
- bool ReadExisting(const std::string& index_filename, const std::string& blob_filename, std::FILE*& index_file,
- std::FILE*& blob_file, CacheIndex& index);
- void InvalidatePipelineCache();
-
- ComPtr CompileAndAddShaderBlob(const CacheIndexKey& key, std::string_view shader_code,
- const D3D_SHADER_MACRO* macros, const char* entry_point);
- ComPtr CompileAndAddPipeline(ID3D12Device* device, const CacheIndexKey& key,
- const D3D12_GRAPHICS_PIPELINE_STATE_DESC& gpdesc);
- ComPtr CompileAndAddPipeline(ID3D12Device* device, const CacheIndexKey& key,
- const D3D12_COMPUTE_PIPELINE_STATE_DESC& gpdesc);
- bool AddPipelineToBlob(const CacheIndexKey& key, ID3D12PipelineState* pso);
-
- std::string m_base_path;
-
- std::FILE* m_shader_index_file = nullptr;
- std::FILE* m_shader_blob_file = nullptr;
- CacheIndex m_shader_index;
-
- std::FILE* m_pipeline_index_file = nullptr;
- std::FILE* m_pipeline_blob_file = nullptr;
- CacheIndex m_pipeline_index;
-
- D3D_FEATURE_LEVEL m_feature_level = D3D_FEATURE_LEVEL_11_0;
- u32 m_data_version = 0;
- bool m_debug = false;
- };
-} // namespace D3D12
diff --git a/common/D3D12/StreamBuffer.h b/common/D3D12/StreamBuffer.h
deleted file mode 100644
index 4eb467bc43..0000000000
--- a/common/D3D12/StreamBuffer.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* PCSX2 - PS2 Emulator for PCs
- * Copyright (C) 2002-2022 PCSX2 Dev Team
- *
- * PCSX2 is free software: you can redistribute it and/or modify it under the terms
- * of the GNU Lesser General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with PCSX2.
- * If not, see .
- */
-
-#pragma once
-
-#include "common/Pcsx2Defs.h"
-#include "common/RedtapeWindows.h"
-#include "common/RedtapeWilCom.h"
-
-#include
-#include
-#include
-
-namespace D3D12MA
-{
- class Allocation;
-}
-
-namespace D3D12
-{
- class StreamBuffer
- {
- public:
- StreamBuffer();
- ~StreamBuffer();
-
- bool Create(u32 size);
-
- __fi bool IsValid() const { return static_cast(m_buffer); }
- __fi ID3D12Resource* GetBuffer() const { return m_buffer.get(); }
- __fi D3D12_GPU_VIRTUAL_ADDRESS GetGPUPointer() const { return m_gpu_pointer; }
- __fi void* GetHostPointer() const { return m_host_pointer; }
- __fi void* GetCurrentHostPointer() const { return m_host_pointer + m_current_offset; }
- __fi D3D12_GPU_VIRTUAL_ADDRESS GetCurrentGPUPointer() const { return m_gpu_pointer + m_current_offset; }
- __fi u32 GetSize() const { return m_size; }
- __fi u32 GetCurrentOffset() const { return m_current_offset; }
- __fi u32 GetCurrentSpace() const { return m_current_space; }
-
- bool ReserveMemory(u32 num_bytes, u32 alignment);
- void CommitMemory(u32 final_num_bytes);
-
- void Destroy(bool defer = true);
-
- private:
- void UpdateCurrentFencePosition();
- void UpdateGPUPosition();
-
- // Waits for as many fences as needed to allocate num_bytes bytes from the buffer.
- bool WaitForClearSpace(u32 num_bytes);
-
- u32 m_size = 0;
- u32 m_current_offset = 0;
- u32 m_current_space = 0;
- u32 m_current_gpu_position = 0;
-
- wil::com_ptr_nothrow m_buffer;
- wil::com_ptr_nothrow m_allocation;
- D3D12_GPU_VIRTUAL_ADDRESS m_gpu_pointer = {};
- u8* m_host_pointer = nullptr;
-
- // List of fences and the corresponding positions in the buffer
- std::deque> m_tracked_fences;
- };
-
-} // namespace D3D12
diff --git a/common/D3D12/Texture.h b/common/D3D12/Texture.h
deleted file mode 100644
index 8f936cd195..0000000000
--- a/common/D3D12/Texture.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/* PCSX2 - PS2 Emulator for PCs
- * Copyright (C) 2002-2022 PCSX2 Dev Team
- *
- * PCSX2 is free software: you can redistribute it and/or modify it under the terms
- * of the GNU Lesser General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with PCSX2.
- * If not, see .
- */
-
-#pragma once
-
-#include "common/Pcsx2Defs.h"
-#include "common/RedtapeWindows.h"
-#include "common/D3D12/DescriptorHeapManager.h"
-
-#include
-#include
-
-namespace D3D12MA
-{
-class Allocation;
-}
-
-namespace D3D12
-{
- class StreamBuffer;
-
- class Texture final
- {
- public:
- template
- using ComPtr = wil::com_ptr_nothrow;
-
- Texture();
- Texture(ID3D12Resource* resource, D3D12_RESOURCE_STATES state);
- Texture(Texture&& texture);
- Texture(const Texture&) = delete;
- ~Texture();
-
- __fi ID3D12Resource* GetResource() const { return m_resource.get(); }
- __fi D3D12MA::Allocation* GetAllocation() const { return m_allocation.get(); }
- __fi const DescriptorHandle& GetSRVDescriptor() const { return m_srv_descriptor; }
- __fi const DescriptorHandle& GetWriteDescriptor() const { return m_write_descriptor; }
- __fi D3D12_RESOURCE_STATES GetState() const { return m_state; }
-
- __fi u32 GetWidth() const { return m_width; }
- __fi u32 GetHeight() const { return m_height; }
- __fi u32 GetLevels() const { return m_levels; }
- __fi DXGI_FORMAT GetFormat() const { return m_format; }
-
- __fi operator ID3D12Resource*() const { return m_resource.get(); }
- __fi operator bool() const { return static_cast(m_resource); }
-
- bool Create(u32 width, u32 height, u32 levels, DXGI_FORMAT format, DXGI_FORMAT srv_format,
- DXGI_FORMAT rtv_format, DXGI_FORMAT dsv_format, D3D12_RESOURCE_FLAGS flags, u32 alloc_flags = 0);
- bool Adopt(ComPtr texture, DXGI_FORMAT srv_format, DXGI_FORMAT rtv_format, DXGI_FORMAT dsv_format,
- D3D12_RESOURCE_STATES state);
-
- D3D12_RESOURCE_DESC GetDesc() const;
-
- void Destroy(bool defer = true);
-
- void TransitionToState(ID3D12GraphicsCommandList* cmdlist, D3D12_RESOURCE_STATES state);
- void TransitionSubresourceToState(ID3D12GraphicsCommandList* cmdlist, u32 level,
- D3D12_RESOURCE_STATES before_state, D3D12_RESOURCE_STATES after_state) const;
-
- Texture& operator=(const Texture&) = delete;
- Texture& operator=(Texture&& texture);
-
- // NOTE: Does not handle compressed formats.
- ID3D12GraphicsCommandList* BeginStreamUpdate(ID3D12GraphicsCommandList* cmdlist, u32 level, u32 x, u32 y, u32 width, u32 height, void** out_data, u32* out_data_pitch);
- void EndStreamUpdate(ID3D12GraphicsCommandList* cmdlist, u32 level, u32 x, u32 y, u32 width, u32 height);
- bool LoadData(ID3D12GraphicsCommandList* cmdlist, u32 level, u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch);
- void CopyFromBuffer(ID3D12GraphicsCommandList* cmdlist, u32 level, u32 x, u32 y, u32 width, u32 height, u32 pitch, ID3D12Resource* buffer, u32 buffer_offset);
-
- private:
- static bool CreateSRVDescriptor(ID3D12Resource* resource, u32 levels, DXGI_FORMAT format, DescriptorHandle* dh);
- static bool CreateRTVDescriptor(ID3D12Resource* resource, DXGI_FORMAT format, DescriptorHandle* dh);
- static bool CreateDSVDescriptor(ID3D12Resource* resource, DXGI_FORMAT format, DescriptorHandle* dh);
- static bool CreateUAVDescriptor(ID3D12Resource* resource, DXGI_FORMAT format, DescriptorHandle* dh);
-
- enum class WriteDescriptorType : u8
- {
- None,
- RTV,
- DSV,
- UAV
- };
-
- ComPtr m_resource;
- ComPtr m_allocation;
- DescriptorHandle m_srv_descriptor = {};
- DescriptorHandle m_write_descriptor = {};
- u32 m_width = 0;
- u32 m_height = 0;
- u32 m_levels = 0;
- DXGI_FORMAT m_format = DXGI_FORMAT_UNKNOWN;
-
- D3D12_RESOURCE_STATES m_state = D3D12_RESOURCE_STATE_COMMON;
-
- WriteDescriptorType m_write_descriptor_type = WriteDescriptorType::None;
- };
-} // namespace D3D12
\ No newline at end of file
diff --git a/common/D3D12/Util.cpp b/common/D3D12/Util.cpp
deleted file mode 100644
index 3c9c1c6ac4..0000000000
--- a/common/D3D12/Util.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/* PCSX2 - PS2 Emulator for PCs
- * Copyright (C) 2002-2022 PCSX2 Dev Team
- *
- * PCSX2 is free software: you can redistribute it and/or modify it under the terms
- * of the GNU Lesser General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with PCSX2.
- * If not, see .
- */
-
-#include "common/PrecompiledHeader.h"
-
-#include "common/D3D12/Util.h"
-#include "common/Assertions.h"
-#include "common/StringUtil.h"
-
-u32 D3D12::GetTexelSize(DXGI_FORMAT format)
-{
- switch (format)
- {
- case DXGI_FORMAT_R32G32B32A32_FLOAT:
- case DXGI_FORMAT_BC1_UNORM:
- case DXGI_FORMAT_BC2_UNORM:
- case DXGI_FORMAT_BC3_UNORM:
- case DXGI_FORMAT_BC7_UNORM:
- return 16;
-
- case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
- return 4;
-
- case DXGI_FORMAT_R8G8B8A8_UNORM:
- case DXGI_FORMAT_R8G8B8A8_SNORM:
- case DXGI_FORMAT_R8G8B8A8_TYPELESS:
- case DXGI_FORMAT_B8G8R8A8_UNORM:
- case DXGI_FORMAT_B8G8R8A8_TYPELESS:
- case DXGI_FORMAT_R32_UINT:
- case DXGI_FORMAT_R32_SINT:
- return 4;
-
- case DXGI_FORMAT_B5G5R5A1_UNORM:
- case DXGI_FORMAT_B5G6R5_UNORM:
- case DXGI_FORMAT_R16_UINT:
- case DXGI_FORMAT_R16_SINT:
- return 2;
-
- case DXGI_FORMAT_A8_UNORM:
- case DXGI_FORMAT_R8_UNORM:
- return 1;
-
- default:
- pxFailRel("Unknown format");
- return 1;
- }
-}
-
-void D3D12::SetDefaultSampler(D3D12_SAMPLER_DESC* desc)
-{
- desc->Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
- desc->AddressU = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
- desc->AddressV = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
- desc->AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
- desc->MipLODBias = 0;
- desc->MaxAnisotropy = 1;
- desc->ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER;
- desc->BorderColor[0] = 1.0f;
- desc->BorderColor[1] = 1.0f;
- desc->BorderColor[2] = 1.0f;
- desc->BorderColor[3] = 1.0f;
- desc->MinLOD = -3.402823466e+38F; // -FLT_MAX
- desc->MaxLOD = 3.402823466e+38F; // FLT_MAX
-}
-
-#ifdef _DEBUG
-
-void D3D12::SetObjectName(ID3D12Object* object, const char* name)
-{
- object->SetName(StringUtil::UTF8StringToWideString(name).c_str());
-}
-
-void D3D12::SetObjectNameFormatted(ID3D12Object* object, const char* format, ...)
-{
- std::va_list ap;
- va_start(ap, format);
- SetObjectName(object, StringUtil::StdStringFromFormatV(format, ap).c_str());
- va_end(ap);
-}
-
-#endif
diff --git a/common/D3D12/Util.h b/common/D3D12/Util.h
deleted file mode 100644
index 848805a083..0000000000
--- a/common/D3D12/Util.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* PCSX2 - PS2 Emulator for PCs
- * Copyright (C) 2002-2022 PCSX2 Dev Team
- *
- * PCSX2 is free software: you can redistribute it and/or modify it under the terms
- * of the GNU Lesser General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with PCSX2.
- * If not, see .
- */
-
-#pragma once
-
-#include "common/Pcsx2Defs.h"
-#include "common/RedtapeWindows.h"
-
-#include
-#include
-
-namespace D3D12
-{
- static inline void ResourceBarrier(ID3D12GraphicsCommandList* cmdlist, ID3D12Resource* resource,
- D3D12_RESOURCE_STATES from_state, D3D12_RESOURCE_STATES to_state)
- {
- const D3D12_RESOURCE_BARRIER barrier = {D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
- D3D12_RESOURCE_BARRIER_FLAG_NONE,
- {{resource, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, from_state, to_state}}};
- cmdlist->ResourceBarrier(1, &barrier);
- }
-
- static inline void SetViewport(ID3D12GraphicsCommandList* cmdlist, int x, int y, int width, int height,
- float min_depth = 0.0f, float max_depth = 1.0f)
- {
- const D3D12_VIEWPORT vp{static_cast(x),
- static_cast(y),
- static_cast(width),
- static_cast(height),
- min_depth,
- max_depth};
- cmdlist->RSSetViewports(1, &vp);
- }
-
- static inline void SetScissor(ID3D12GraphicsCommandList* cmdlist, int x, int y, int width, int height)
- {
- const D3D12_RECT r{x, y, x + width, y + height};
- cmdlist->RSSetScissorRects(1, &r);
- }
-
- static inline void SetViewportAndScissor(ID3D12GraphicsCommandList* cmdlist, int x, int y, int width, int height,
- float min_depth = 0.0f, float max_depth = 1.0f)
- {
- SetViewport(cmdlist, x, y, width, height, min_depth, max_depth);
- SetScissor(cmdlist, x, y, width, height);
- }
-
- u32 GetTexelSize(DXGI_FORMAT format);
-
- void SetDefaultSampler(D3D12_SAMPLER_DESC* desc);
-
-#ifdef _DEBUG
-
- void SetObjectName(ID3D12Object* object, const char* name);
- void SetObjectNameFormatted(ID3D12Object* object, const char* format, ...);
-
-#else
-
- static inline void SetObjectName(ID3D12Object* object, const char* name)
- {
- }
- static inline void SetObjectNameFormatted(ID3D12Object* object, const char* format, ...) {}
-
-#endif
-} // namespace D3D12
\ No newline at end of file
diff --git a/common/common.vcxproj b/common/common.vcxproj
index 9c981505a4..de13b778c1 100644
--- a/common/common.vcxproj
+++ b/common/common.vcxproj
@@ -34,7 +34,7 @@
- $(SolutionDir)3rdparty\d3d12memalloc\include;$(SolutionDir)3rdparty\glad\include;$(SolutionDir)3rdparty\glslang\glslang;%(AdditionalIncludeDirectories)
+ $(SolutionDir)3rdparty\glad\include;$(SolutionDir)3rdparty\glslang\glslang;%(AdditionalIncludeDirectories)
%(AdditionalIncludeDirectories);$(SolutionDir)3rdparty\rapidyaml\rapidyaml\ext\c4core\src\c4\ext\fast_float\include
%(AdditionalIncludeDirectories);$(SolutionDir)3rdparty\libpng
%(AdditionalIncludeDirectories);$(SolutionDir)3rdparty\jpgd
@@ -56,15 +56,6 @@
-
-
-
-
-
-
-
-
-
@@ -138,15 +129,6 @@
-
-
-
-
-
-
-
-
-
@@ -230,9 +212,6 @@
-
- {d45cec7a-3171-40dd-975d-e1544cf16139}
-
{c0293b32-5acf-40f0-aa6c-e6da6f3bf33a}
@@ -247,4 +226,4 @@
-
\ No newline at end of file
+
diff --git a/common/common.vcxproj.filters b/common/common.vcxproj.filters
index 00a6998d07..120c0d0f22 100644
--- a/common/common.vcxproj.filters
+++ b/common/common.vcxproj.filters
@@ -154,33 +154,6 @@
Source Files\Vulkan
-
- Source Files\D3D11
-
-
- Source Files\D3D11
-
-
- Source Files\D3D12
-
-
- Source Files\D3D12
-
-
- Source Files\D3D12
-
-
- Source Files\D3D12
-
-
- Source Files\D3D12
-
-
- Source Files\D3D12
-
-
- Source Files\D3D12
-
Source Files
@@ -421,36 +394,9 @@
Header Files\GL
-
- Header Files\D3D11
-
-
- Header Files\D3D11
-
Header Files
-
- Header Files\D3D12
-
-
- Header Files\D3D12
-
-
- Header Files\D3D12
-
-
- Header Files\D3D12
-
-
- Header Files\D3D12
-
-
- Header Files\D3D12
-
-
- Header Files\D3D12
-
Header Files
@@ -513,18 +459,6 @@
{46f36c68-0e0e-4acd-a621-3365e3167c4f}
-
- {f428aac0-c9c5-4b66-b218-9829dce45d13}
-
-
- {764ddf71-77a6-41b8-bc65-1eef94b6997b}
-
-
- {96f78eb9-089b-4166-a23e-78c4e7d90b64}
-
-
- {cf37623d-bb05-4c54-8c72-1c20b5331c69}
-
diff --git a/pcsx2-gsrunner/pcsx2-gsrunner.vcxproj b/pcsx2-gsrunner/pcsx2-gsrunner.vcxproj
index 7834626e90..88e6e101ec 100644
--- a/pcsx2-gsrunner/pcsx2-gsrunner.vcxproj
+++ b/pcsx2-gsrunner/pcsx2-gsrunner.vcxproj
@@ -71,7 +71,7 @@
Console
Yes
comctl32.lib;ws2_32.lib;shlwapi.lib;winmm.lib;rpcrt4.lib;iphlpapi.lib;dsound.lib;%(AdditionalDependencies)
- dxguid.lib;dinput8.lib;hid.lib;PowrProf.lib;d3dcompiler.lib;d3d11.lib;dxgi.lib;strmiids.lib;opengl32.lib;comsuppw.lib;OneCore.lib;%(AdditionalDependencies)
+ dxguid.lib;dinput8.lib;hid.lib;PowrProf.lib;d3dcompiler.lib;d3d11.lib;d3d12.lib;dxgi.lib;strmiids.lib;opengl32.lib;comsuppw.lib;OneCore.lib;%(AdditionalDependencies)
diff --git a/pcsx2-qt/pcsx2-qt.vcxproj b/pcsx2-qt/pcsx2-qt.vcxproj
index 42ac55cb57..50a83f7723 100644
--- a/pcsx2-qt/pcsx2-qt.vcxproj
+++ b/pcsx2-qt/pcsx2-qt.vcxproj
@@ -79,7 +79,7 @@
Windows
Yes
comctl32.lib;ws2_32.lib;shlwapi.lib;winmm.lib;rpcrt4.lib;iphlpapi.lib;dsound.lib;%(AdditionalDependencies)
- dxguid.lib;dinput8.lib;hid.lib;PowrProf.lib;d3dcompiler.lib;d3d11.lib;dxgi.lib;strmiids.lib;opengl32.lib;comsuppw.lib;OneCore.lib;%(AdditionalDependencies)
+ dxguid.lib;dinput8.lib;hid.lib;PowrProf.lib;d3dcompiler.lib;d3d11.lib;d3d12.lib;dxgi.lib;strmiids.lib;opengl32.lib;comsuppw.lib;OneCore.lib;%(AdditionalDependencies)
$(QtEntryPointLib);%(AdditionalDependencies)
@@ -443,4 +443,4 @@
-
\ No newline at end of file
+
diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt
index 25915587e5..fb8eaf925d 100644
--- a/pcsx2/CMakeLists.txt
+++ b/pcsx2/CMakeLists.txt
@@ -644,16 +644,30 @@ if(WIN32)
list(APPEND pcsx2GSSources
GS/Renderers/DX11/D3D.cpp
+ GS/Renderers/DX11/D3D11ShaderCache.cpp
GS/Renderers/DX11/GSDevice11.cpp
GS/Renderers/DX11/GSTexture11.cpp
GS/Renderers/DX11/GSTextureFX11.cpp
+ GS/Renderers/DX12/D3D12Builders.cpp
+ GS/Renderers/DX12/D3D12Context.cpp
+ GS/Renderers/DX12/D3D12DescriptorHeapManager.cpp
+ GS/Renderers/DX12/D3D12ShaderCache.cpp
+ GS/Renderers/DX12/D3D12StreamBuffer.cpp
+ GS/Renderers/DX12/D3D12Texture.cpp
GS/Renderers/DX12/GSDevice12.cpp
GS/Renderers/DX12/GSTexture12.cpp
)
list(APPEND pcsx2GSHeaders
GS/Renderers/DX11/D3D.h
+ GS/Renderers/DX11/D3D11ShaderCache.h
GS/Renderers/DX11/GSDevice11.h
GS/Renderers/DX11/GSTexture11.h
+ GS/Renderers/DX12/D3D12Builders.h
+ GS/Renderers/DX12/D3D12Context.h
+ GS/Renderers/DX12/D3D12DescriptorHeapManager.h
+ GS/Renderers/DX12/D3D12ShaderCache.h
+ GS/Renderers/DX12/D3D12StreamBuffer.h
+ GS/Renderers/DX12/D3D12Texture.h
GS/Renderers/DX12/GSDevice12.h
GS/Renderers/DX12/GSTexture12.h
)
@@ -1149,6 +1163,7 @@ if(WIN32)
PowrProf.lib
d3dcompiler.lib
d3d11.lib
+ d3d12.lib
dxgi.lib
strmiids.lib
opengl32.lib
diff --git a/pcsx2/GS/Renderers/DX11/D3D.cpp b/pcsx2/GS/Renderers/DX11/D3D.cpp
index fdeef46ce9..6e9272d020 100644
--- a/pcsx2/GS/Renderers/DX11/D3D.cpp
+++ b/pcsx2/GS/Renderers/DX11/D3D.cpp
@@ -14,17 +14,25 @@
*/
#include "PrecompiledHeader.h"
+
+#include "Config.h"
#include "GS/Renderers/Common/GSDevice.h"
#include "GS/Renderers/DX11/D3D.h"
#include "GS/GSExtra.h"
#include "common/Console.h"
#include "common/StringUtil.h"
+#include "common/Path.h"
+#include
#include
+#include
+#include
#include "fmt/format.h"
+static u32 s_next_bad_shader_id = 1;
+
wil::com_ptr_nothrow D3D::CreateFactory(bool debug)
{
UINT flags = 0;
@@ -49,7 +57,7 @@ static std::string FixupDuplicateAdapterNames(const std::vector& ad
u32 current_extra = 2;
do
{
- adapter_name = StringUtil::StdStringFromFormat("%s (%u)", original_adapter_name.c_str(), current_extra);
+ adapter_name = fmt::format("{} ({})", original_adapter_name.c_str(), current_extra);
current_extra++;
} while (std::any_of(adapter_names.begin(), adapter_names.end(),
[&adapter_name](const std::string& other) { return (adapter_name == other); }));
@@ -405,3 +413,78 @@ GSRendererType D3D::GetPreferredRenderer()
}
}
}
+
+wil::com_ptr_nothrow D3D::CompileShader(D3D::ShaderType type, D3D_FEATURE_LEVEL feature_level, bool debug,
+ const std::string_view& code, const D3D_SHADER_MACRO* macros /* = nullptr */,
+ const char* entry_point /* = "main" */)
+{
+ const char* target;
+ switch (feature_level)
+ {
+ case D3D_FEATURE_LEVEL_10_0:
+ {
+ static constexpr std::array targets = {{"vs_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"}};
+ 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"}};
+ target = targets[static_cast(type)];
+ }
+ break;
+
+ case D3D_FEATURE_LEVEL_11_1:
+ default:
+ {
+ static constexpr std::array targets = {{"vs_5_1", "ps_5_1", "cs_5_1"}};
+ target = targets[static_cast(type)];
+ }
+ break;
+ }
+
+ static constexpr UINT flags_non_debug = D3DCOMPILE_OPTIMIZATION_LEVEL3;
+ static constexpr UINT flags_debug = D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_DEBUG;
+
+ wil::com_ptr_nothrow blob;
+ wil::com_ptr_nothrow error_blob;
+ const HRESULT hr = D3DCompile(code.data(), code.size(), "0", macros, nullptr, entry_point, target,
+ debug ? flags_debug : flags_non_debug, 0, blob.put(), error_blob.put());
+
+ std::string error_string;
+ if (error_blob)
+ {
+ error_string.append(static_cast(error_blob->GetBufferPointer()), error_blob->GetBufferSize());
+ error_blob.reset();
+ }
+
+ if (FAILED(hr))
+ {
+ Console.WriteLn("Failed to compile '%s':\n%s", target, error_string.c_str());
+
+ std::ofstream ofs(Path::Combine(EmuFolders::Logs, fmt::format("pcsx2_bad_shader_{}.txt", s_next_bad_shader_id++)),
+ std::ofstream::out | std::ofstream::binary);
+ if (ofs.is_open())
+ {
+ ofs << code;
+ ofs << "\n\nCompile as " << target << " failed: " << hr << "\n";
+ ofs.write(error_string.c_str(), error_string.size());
+ ofs.close();
+ }
+
+ return {};
+ }
+
+ if (!error_string.empty())
+ Console.Warning("'%s' compiled with warnings:\n%s", target, error_string.c_str());
+
+ return blob;
+}
diff --git a/pcsx2/GS/Renderers/DX11/D3D.h b/pcsx2/GS/Renderers/DX11/D3D.h
index aeb6e1e358..0dcb5ab543 100644
--- a/pcsx2/GS/Renderers/DX11/D3D.h
+++ b/pcsx2/GS/Renderers/DX11/D3D.h
@@ -20,6 +20,7 @@
#include "pcsx2/Config.h"
+#include
#include
#include
#include
@@ -67,4 +68,15 @@ namespace D3D
VendorID GetVendorID(IDXGIAdapter1* adapter);
GSRendererType GetPreferredRenderer();
+
+ // D3DCompiler wrapper.
+ enum class ShaderType
+ {
+ Vertex,
+ Pixel,
+ Compute
+ };
+
+ wil::com_ptr_nothrow CompileShader(ShaderType type, D3D_FEATURE_LEVEL feature_level, bool debug,
+ const std::string_view& code, const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
}; // namespace D3D
diff --git a/common/D3D11/ShaderCache.cpp b/pcsx2/GS/Renderers/DX11/D3D11ShaderCache.cpp
similarity index 63%
rename from common/D3D11/ShaderCache.cpp
rename to pcsx2/GS/Renderers/DX11/D3D11ShaderCache.cpp
index 0f216a16e7..9c6aba8bd3 100644
--- a/common/D3D11/ShaderCache.cpp
+++ b/pcsx2/GS/Renderers/DX11/D3D11ShaderCache.cpp
@@ -1,5 +1,5 @@
/* PCSX2 - PS2 Emulator for PCs
- * Copyright (C) 2002-2022 PCSX2 Dev Team
+ * Copyright (C) 2002-2023 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
@@ -13,12 +13,19 @@
* If not, see .
*/
-#include "common/PrecompiledHeader.h"
-#include "common/D3D11/ShaderCache.h"
-#include "common/D3D11/ShaderCompiler.h"
+#include "PrecompiledHeader.h"
+
+#include "GS/Renderers/DX11/D3D11ShaderCache.h"
+#include "GS/GS.h"
+
+#include "Config.h"
+#include "ShaderCacheVersion.h"
+
#include "common/FileSystem.h"
#include "common/Console.h"
#include "common/MD5Digest.h"
+#include "common/Path.h"
+
#include
#pragma pack(push, 1)
@@ -37,14 +44,14 @@ struct CacheIndexEntry
};
#pragma pack(pop)
-D3D11::ShaderCache::ShaderCache() = default;
+D3D11ShaderCache::D3D11ShaderCache() = default;
-D3D11::ShaderCache::~ShaderCache()
+D3D11ShaderCache::~D3D11ShaderCache()
{
Close();
}
-bool D3D11::ShaderCache::CacheIndexKey::operator==(const CacheIndexKey& key) const
+bool D3D11ShaderCache::CacheIndexKey::operator==(const CacheIndexKey& key) const
{
return (source_hash_low == key.source_hash_low && source_hash_high == key.source_hash_high &&
macro_hash_low == key.macro_hash_low && macro_hash_high == key.macro_hash_high &&
@@ -52,7 +59,7 @@ bool D3D11::ShaderCache::CacheIndexKey::operator==(const CacheIndexKey& key) con
shader_type == key.shader_type && source_length == key.source_length);
}
-bool D3D11::ShaderCache::CacheIndexKey::operator!=(const CacheIndexKey& key) const
+bool D3D11ShaderCache::CacheIndexKey::operator!=(const CacheIndexKey& key) const
{
return (source_hash_low != key.source_hash_low || source_hash_high != key.source_hash_high ||
macro_hash_low != key.macro_hash_low || macro_hash_high != key.macro_hash_high ||
@@ -60,15 +67,14 @@ bool D3D11::ShaderCache::CacheIndexKey::operator!=(const CacheIndexKey& key) con
shader_type != key.shader_type || source_length != key.source_length);
}
-bool D3D11::ShaderCache::Open(std::string_view base_path, D3D_FEATURE_LEVEL feature_level, u32 version, bool debug)
+bool D3D11ShaderCache::Open(D3D_FEATURE_LEVEL feature_level, bool debug)
{
m_feature_level = feature_level;
- m_version = version;
m_debug = debug;
- if (!base_path.empty())
+ if (!GSConfig.DisableShaderCache)
{
- const std::string base_filename = GetCacheBaseFileName(base_path, feature_level, debug);
+ const std::string base_filename = GetCacheBaseFileName(feature_level, debug);
const std::string index_filename = base_filename + ".idx";
const std::string blob_filename = base_filename + ".bin";
@@ -79,7 +85,7 @@ bool D3D11::ShaderCache::Open(std::string_view base_path, D3D_FEATURE_LEVEL feat
return true;
}
-void D3D11::ShaderCache::Close()
+void D3D11ShaderCache::Close()
{
if (m_index_file)
{
@@ -93,7 +99,7 @@ void D3D11::ShaderCache::Close()
}
}
-bool D3D11::ShaderCache::CreateNew(const std::string& index_filename, const std::string& blob_filename)
+bool D3D11ShaderCache::CreateNew(const std::string& index_filename, const std::string& blob_filename)
{
if (FileSystem::FileExists(index_filename.c_str()))
{
@@ -113,9 +119,8 @@ bool D3D11::ShaderCache::CreateNew(const std::string& index_filename, const std:
return false;
}
- const u32 index_version = FILE_VERSION;
- if (std::fwrite(&index_version, sizeof(index_version), 1, m_index_file) != 1 ||
- std::fwrite(&m_version, sizeof(m_version), 1, m_index_file) != 1)
+ const u32 file_version = SHADER_CACHE_VERSION;
+ if (std::fwrite(&file_version, sizeof(file_version), 1, m_index_file) != 1)
{
Console.Error("Failed to write version to index file '%s'", index_filename.c_str());
std::fclose(m_index_file);
@@ -137,7 +142,7 @@ bool D3D11::ShaderCache::CreateNew(const std::string& index_filename, const std:
return true;
}
-bool D3D11::ShaderCache::ReadExisting(const std::string& index_filename, const std::string& blob_filename)
+bool D3D11ShaderCache::ReadExisting(const std::string& index_filename, const std::string& blob_filename)
{
m_index_file = FileSystem::OpenCFile(index_filename.c_str(), "r+b");
if (!m_index_file)
@@ -154,9 +159,7 @@ bool D3D11::ShaderCache::ReadExisting(const std::string& index_filename, const s
}
u32 file_version = 0;
- u32 data_version = 0;
- if (std::fread(&file_version, sizeof(file_version), 1, m_index_file) != 1 || file_version != FILE_VERSION ||
- std::fread(&data_version, sizeof(data_version), 1, m_index_file) != 1 || data_version != m_version)
+ if (std::fread(&file_version, sizeof(file_version), 1, m_index_file) != 1 || file_version != SHADER_CACHE_VERSION)
{
Console.Error("Bad file/data version in '%s'", index_filename.c_str());
std::fclose(m_index_file);
@@ -194,11 +197,9 @@ bool D3D11::ShaderCache::ReadExisting(const std::string& index_filename, const s
return false;
}
- const CacheIndexKey key{
- entry.source_hash_low, entry.source_hash_high,
- entry.macro_hash_low, entry.macro_hash_high,
- entry.entry_point_low, entry.entry_point_high,
- entry.source_length, static_cast(entry.shader_type)};
+ const CacheIndexKey key{entry.source_hash_low, entry.source_hash_high, entry.macro_hash_low,
+ entry.macro_hash_high, entry.entry_point_low, entry.entry_point_high, entry.source_length,
+ static_cast(entry.shader_type)};
const CacheIndexData data{entry.file_offset, entry.blob_size};
m_index.emplace(key, data);
}
@@ -210,11 +211,9 @@ bool D3D11::ShaderCache::ReadExisting(const std::string& index_filename, const s
return true;
}
-std::string D3D11::ShaderCache::GetCacheBaseFileName(const std::string_view& base_path, D3D_FEATURE_LEVEL feature_level,
- bool debug)
+std::string D3D11ShaderCache::GetCacheBaseFileName(D3D_FEATURE_LEVEL feature_level, bool debug)
{
- std::string base_filename(base_path);
- base_filename += FS_OSPATH_SEPARATOR_STR "d3d_shaders_";
+ std::string base_filename = "d3d_shaders_";
switch (feature_level)
{
@@ -235,11 +234,11 @@ std::string D3D11::ShaderCache::GetCacheBaseFileName(const std::string_view& bas
if (debug)
base_filename += "_debug";
- return base_filename;
+ return Path::Combine(EmuFolders::Cache, base_filename);
}
-D3D11::ShaderCache::CacheIndexKey D3D11::ShaderCache::GetCacheKey(ShaderCompiler::Type type, const std::string_view& shader_code,
- const D3D_SHADER_MACRO* macros, const char* entry_point)
+D3D11ShaderCache::CacheIndexKey D3D11ShaderCache::GetCacheKey(
+ D3D::ShaderType type, const std::string_view& shader_code, const D3D_SHADER_MACRO* macros, const char* entry_point)
{
union
{
@@ -283,8 +282,9 @@ D3D11::ShaderCache::CacheIndexKey D3D11::ShaderCache::GetCacheKey(ShaderCompiler
return key;
}
-wil::com_ptr_nothrow D3D11::ShaderCache::GetShaderBlob(ShaderCompiler::Type type, const std::string_view& shader_code,
- const D3D_SHADER_MACRO* macros /* = nullptr */, const char* entry_point /* = "main" */)
+wil::com_ptr_nothrow D3D11ShaderCache::GetShaderBlob(D3D::ShaderType type,
+ const std::string_view& shader_code, const D3D_SHADER_MACRO* macros /* = nullptr */,
+ const char* entry_point /* = "main" */)
{
const auto key = GetCacheKey(type, shader_code, macros, entry_point);
auto iter = m_index.find(key);
@@ -296,37 +296,51 @@ wil::com_ptr_nothrow D3D11::ShaderCache::GetShaderBlob(ShaderCompiler:
if (FAILED(hr) || std::fseek(m_blob_file, iter->second.file_offset, SEEK_SET) != 0 ||
std::fread(blob->GetBufferPointer(), 1, iter->second.blob_size, m_blob_file) != iter->second.blob_size)
{
- Console.Error("(D3D11::ShaderCache::GetShaderBlob): Read blob from file failed");
+ Console.Error("(GSShaderCache11::GetShaderBlob): Read blob from file failed");
return {};
}
return blob;
}
-wil::com_ptr_nothrow D3D11::ShaderCache::GetVertexShader(ID3D11Device* device,
- const std::string_view& shader_code, const D3D_SHADER_MACRO* macros /* = nullptr */, const char* entry_point /* = "main" */)
+wil::com_ptr_nothrow D3D11ShaderCache::GetVertexShader(ID3D11Device* device,
+ const std::string_view& shader_code, const D3D_SHADER_MACRO* macros /* = nullptr */,
+ const char* entry_point /* = "main" */)
{
- wil::com_ptr_nothrow blob = GetShaderBlob(ShaderCompiler::Type::Vertex, shader_code, macros, entry_point);
+ wil::com_ptr_nothrow blob = GetShaderBlob(D3D::ShaderType::Vertex, shader_code, macros, entry_point);
if (!blob)
return {};
- return D3D11::ShaderCompiler::CreateVertexShader(device, blob.get());
+ wil::com_ptr_nothrow shader;
+ const HRESULT hr =
+ device->CreateVertexShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, shader.put());
+ if (FAILED(hr))
+ {
+ Console.Error("Failed to create vertex shader: 0x%08X", hr);
+ return {};
+ }
+
+ return shader;
}
-bool D3D11::ShaderCache::GetVertexShaderAndInputLayout(ID3D11Device* device,
- ID3D11VertexShader** vs, ID3D11InputLayout** il,
- const D3D11_INPUT_ELEMENT_DESC* layout, size_t layout_size, const std::string_view& shader_code,
- const D3D_SHADER_MACRO* macros /* = nullptr */, const char* entry_point /* = "main" */)
+bool D3D11ShaderCache::GetVertexShaderAndInputLayout(ID3D11Device* device, ID3D11VertexShader** vs,
+ ID3D11InputLayout** il, const D3D11_INPUT_ELEMENT_DESC* layout, size_t layout_size,
+ const std::string_view& shader_code, const D3D_SHADER_MACRO* macros /* = nullptr */,
+ const char* entry_point /* = "main" */)
{
- wil::com_ptr_nothrow blob = GetShaderBlob(ShaderCompiler::Type::Vertex, shader_code, macros, entry_point);
+ wil::com_ptr_nothrow blob = GetShaderBlob(D3D::ShaderType::Vertex, shader_code, macros, entry_point);
if (!blob)
return false;
- wil::com_ptr_nothrow actual_vs = D3D11::ShaderCompiler::CreateVertexShader(device, blob.get());
- if (!actual_vs)
- return false;
+ wil::com_ptr_nothrow actual_vs;
+ HRESULT hr = device->CreateVertexShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, actual_vs.put());
+ if (FAILED(hr))
+ {
+ Console.Error("Failed to create vertex shader: 0x%08X", hr);
+ return {};
+ }
- HRESULT hr = device->CreateInputLayout(layout, layout_size, blob->GetBufferPointer(), blob->GetBufferSize(), il);
+ hr = device->CreateInputLayout(layout, layout_size, blob->GetBufferPointer(), blob->GetBufferSize(), il);
if (FAILED(hr))
{
Console.Error("(GetVertexShaderAndInputLayout) Failed to create input layout: %08X", hr);
@@ -337,30 +351,51 @@ bool D3D11::ShaderCache::GetVertexShaderAndInputLayout(ID3D11Device* device,
return true;
}
-wil::com_ptr_nothrow D3D11::ShaderCache::GetPixelShader(ID3D11Device* device,
- const std::string_view& shader_code, const D3D_SHADER_MACRO* macros /* = nullptr */, const char* entry_point /* = "main" */)
+wil::com_ptr_nothrow D3D11ShaderCache::GetPixelShader(ID3D11Device* device,
+ const std::string_view& shader_code, const D3D_SHADER_MACRO* macros /* = nullptr */,
+ const char* entry_point /* = "main" */)
{
- wil::com_ptr_nothrow blob = GetShaderBlob(ShaderCompiler::Type::Pixel, shader_code, macros, entry_point);
+ wil::com_ptr_nothrow blob = GetShaderBlob(D3D::ShaderType::Pixel, shader_code, macros, entry_point);
if (!blob)
return {};
- return D3D11::ShaderCompiler::CreatePixelShader(device, blob.get());
+ wil::com_ptr_nothrow shader;
+ const HRESULT hr =
+ device->CreatePixelShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, shader.put());
+ if (FAILED(hr))
+ {
+ Console.Error("Failed to create pixel shader: 0x%08X", hr);
+ return {};
+ }
+
+ return shader;
}
-wil::com_ptr_nothrow D3D11::ShaderCache::GetComputeShader(ID3D11Device* device,
- const std::string_view& shader_code, const D3D_SHADER_MACRO* macros /* = nullptr */, const char* entry_point /* = "main" */)
+wil::com_ptr_nothrow D3D11ShaderCache::GetComputeShader(ID3D11Device* device,
+ const std::string_view& shader_code, const D3D_SHADER_MACRO* macros /* = nullptr */,
+ const char* entry_point /* = "main" */)
{
- wil::com_ptr_nothrow blob = GetShaderBlob(ShaderCompiler::Type::Compute, shader_code, macros, entry_point);
+ wil::com_ptr_nothrow blob = GetShaderBlob(D3D::ShaderType::Compute, shader_code, macros, entry_point);
if (!blob)
return {};
- return D3D11::ShaderCompiler::CreateComputeShader(device, blob.get());
+ wil::com_ptr_nothrow shader;
+ const HRESULT hr =
+ device->CreateComputeShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, shader.put());
+ if (FAILED(hr))
+ {
+ Console.Error("Failed to create compute shader: 0x%08X", hr);
+ return {};
+ }
+
+ return shader;
}
-wil::com_ptr_nothrow D3D11::ShaderCache::CompileAndAddShaderBlob(const CacheIndexKey& key,
+wil::com_ptr_nothrow D3D11ShaderCache::CompileAndAddShaderBlob(const CacheIndexKey& key,
const std::string_view& shader_code, const D3D_SHADER_MACRO* macros, const char* entry_point)
{
- wil::com_ptr_nothrow blob = ShaderCompiler::CompileShader(key.shader_type, m_feature_level, m_debug, shader_code, macros, entry_point);
+ wil::com_ptr_nothrow blob =
+ D3D::CompileShader(key.shader_type, m_feature_level, m_debug, shader_code, macros, entry_point);
if (!blob)
return {};
@@ -387,7 +422,7 @@ wil::com_ptr_nothrow D3D11::ShaderCache::CompileAndAddShaderBlob(const
std::fflush(m_blob_file) != 0 || std::fwrite(&entry, sizeof(entry), 1, m_index_file) != 1 ||
std::fflush(m_index_file) != 0)
{
- Console.Error("(D3D11::ShaderCache::CompileAndAddShaderBlob) Failed to write shader blob to file");
+ Console.Error("(GSShaderCache11::CompileAndAddShaderBlob) Failed to write shader blob to file");
return blob;
}
diff --git a/pcsx2/GS/Renderers/DX11/D3D11ShaderCache.h b/pcsx2/GS/Renderers/DX11/D3D11ShaderCache.h
new file mode 100644
index 0000000000..825fd91356
--- /dev/null
+++ b/pcsx2/GS/Renderers/DX11/D3D11ShaderCache.h
@@ -0,0 +1,106 @@
+/* PCSX2 - PS2 Emulator for PCs
+ * Copyright (C) 2002-2023 PCSX2 Dev Team
+ *
+ * PCSX2 is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU Lesser General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with PCSX2.
+ * If not, see .
+ */
+
+#pragma once
+#include "GS/Renderers/DX11/D3D.h"
+
+#include "common/HashCombine.h"
+
+#include
+#include
+#include
+
+class D3D11ShaderCache
+{
+public:
+ D3D11ShaderCache();
+ ~D3D11ShaderCache();
+
+ D3D_FEATURE_LEVEL GetFeatureLevel() const { return m_feature_level; }
+ bool UsingDebugShaders() const { return m_debug; }
+
+ bool Open(D3D_FEATURE_LEVEL feature_level, bool debug);
+ void Close();
+
+ wil::com_ptr_nothrow GetShaderBlob(D3D::ShaderType type, const std::string_view& shader_code,
+ const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
+
+ wil::com_ptr_nothrow GetVertexShader(ID3D11Device* device, const std::string_view& shader_code,
+ const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
+
+ bool GetVertexShaderAndInputLayout(ID3D11Device* device, ID3D11VertexShader** vs, ID3D11InputLayout** il,
+ const D3D11_INPUT_ELEMENT_DESC* layout, size_t layout_size, const std::string_view& shader_code,
+ const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
+
+ wil::com_ptr_nothrow GetPixelShader(ID3D11Device* device, const std::string_view& shader_code,
+ const D3D_SHADER_MACRO* macros = nullptr, const char* entry_point = "main");
+
+ wil::com_ptr_nothrow GetComputeShader(ID3D11Device* device,
+ const std::string_view& shader_code, const D3D_SHADER_MACRO* macros = nullptr,
+ const char* entry_point = "main");
+
+private:
+ struct CacheIndexKey
+ {
+ u64 source_hash_low;
+ u64 source_hash_high;
+ u64 macro_hash_low;
+ u64 macro_hash_high;
+ u64 entry_point_low;
+ u64 entry_point_high;
+ u32 source_length;
+ D3D::ShaderType shader_type;
+
+ bool operator==(const CacheIndexKey& key) const;
+ bool operator!=(const CacheIndexKey& key) const;
+ };
+
+ struct CacheIndexEntryHasher
+ {
+ std::size_t operator()(const CacheIndexKey& e) const noexcept
+ {
+ std::size_t h = 0;
+ HashCombine(h, e.entry_point_low, e.entry_point_high, e.macro_hash_low, e.macro_hash_high,
+ e.source_hash_low, e.source_hash_high, e.source_length, e.shader_type);
+ return h;
+ }
+ };
+
+ struct CacheIndexData
+ {
+ u32 file_offset;
+ u32 blob_size;
+ };
+
+ using CacheIndex = std::unordered_map;
+
+ static std::string GetCacheBaseFileName(D3D_FEATURE_LEVEL feature_level, bool debug);
+ static CacheIndexKey GetCacheKey(D3D::ShaderType type, const std::string_view& shader_code,
+ const D3D_SHADER_MACRO* macros, const char* entry_point);
+
+ bool CreateNew(const std::string& index_filename, const std::string& blob_filename);
+ bool ReadExisting(const std::string& index_filename, const std::string& blob_filename);
+
+ wil::com_ptr_nothrow CompileAndAddShaderBlob(const CacheIndexKey& key,
+ const std::string_view& shader_code, const D3D_SHADER_MACRO* macros, const char* entry_point);
+
+ std::FILE* m_index_file = nullptr;
+ std::FILE* m_blob_file = nullptr;
+
+ CacheIndex m_index;
+
+ D3D_FEATURE_LEVEL m_feature_level = D3D_FEATURE_LEVEL_11_0;
+ bool m_debug = false;
+};
diff --git a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp
index 3ecd5cedde..1c6a90b061 100644
--- a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp
+++ b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp
@@ -21,7 +21,6 @@
#include "GS/GSPerfMon.h"
#include "GS/GSUtil.h"
#include "Host.h"
-#include "ShaderCacheVersion.h"
#include "common/Align.h"
#include "common/Path.h"
@@ -168,18 +167,8 @@ bool GSDevice11::Create()
level = m_dev->GetFeatureLevel();
const bool support_feature_level_11_0 = (level >= D3D_FEATURE_LEVEL_11_0);
- if (!GSConfig.DisableShaderCache)
- {
- if (!m_shader_cache.Open(EmuFolders::Cache, m_dev->GetFeatureLevel(), SHADER_CACHE_VERSION, GSConfig.UseDebugDevice))
- {
- Console.Warning("Shader cache failed to open.");
- }
- }
- else
- {
- m_shader_cache.Open({}, m_dev->GetFeatureLevel(), SHADER_CACHE_VERSION, GSConfig.UseDebugDevice);
- Console.WriteLn("Not using shader cache.");
- }
+ if (!m_shader_cache.Open(m_dev->GetFeatureLevel(), GSConfig.UseDebugDevice))
+ Console.Warning("Shader cache failed to open.");
// Set maximum texture size limit based on supported feature level.
if (support_feature_level_11_0)
diff --git a/pcsx2/GS/Renderers/DX11/GSDevice11.h b/pcsx2/GS/Renderers/DX11/GSDevice11.h
index 78561ee4de..bcd9ee57e4 100644
--- a/pcsx2/GS/Renderers/DX11/GSDevice11.h
+++ b/pcsx2/GS/Renderers/DX11/GSDevice11.h
@@ -18,7 +18,7 @@
#include "GSTexture11.h"
#include "GS/GSVector.h"
#include "GS/Renderers/Common/GSDevice.h"
-#include "common/D3D11/ShaderCache.h"
+#include "GS/Renderers/DX11/D3D11ShaderCache.h"
#include
#include
#include
@@ -272,7 +272,7 @@ private:
GSHWDrawConfig::VSConstantBuffer m_vs_cb_cache;
GSHWDrawConfig::PSConstantBuffer m_ps_cb_cache;
- D3D11::ShaderCache m_shader_cache;
+ D3D11ShaderCache m_shader_cache;
std::string m_tfx_source;
public:
diff --git a/common/D3D12/Builders.cpp b/pcsx2/GS/Renderers/DX12/D3D12Builders.cpp
similarity index 64%
rename from common/D3D12/Builders.cpp
rename to pcsx2/GS/Renderers/DX12/D3D12Builders.cpp
index 7e0431f5f4..0eee7a6eef 100644
--- a/common/D3D12/Builders.cpp
+++ b/pcsx2/GS/Renderers/DX12/D3D12Builders.cpp
@@ -1,5 +1,5 @@
/* PCSX2 - PS2 Emulator for PCs
- * Copyright (C) 2002-2022 PCSX2 Dev Team
+ * Copyright (C) 2002-2023 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
@@ -13,24 +13,22 @@
* If not, see .
*/
-#include "common/PrecompiledHeader.h"
+#include "PrecompiledHeader.h"
-#include "common/D3D12/Builders.h"
-#include "common/D3D12/Context.h"
-#include "common/D3D12/ShaderCache.h"
+#include "GS/Renderers/DX12/D3D12Builders.h"
+#include "GS/Renderers/DX12/D3D12Context.h"
+#include "GS/Renderers/DX12/D3D12ShaderCache.h"
#include "common/Console.h"
#include
#include
-using namespace D3D12;
-
-GraphicsPipelineBuilder::GraphicsPipelineBuilder()
+D3D12::GraphicsPipelineBuilder::GraphicsPipelineBuilder()
{
Clear();
}
-void GraphicsPipelineBuilder::Clear()
+void D3D12::GraphicsPipelineBuilder::Clear()
{
std::memset(&m_desc, 0, sizeof(m_desc));
std::memset(m_input_elements.data(), 0, sizeof(D3D12_INPUT_ELEMENT_DESC) * m_input_elements.size());
@@ -39,7 +37,8 @@ void GraphicsPipelineBuilder::Clear()
m_desc.SampleDesc.Count = 1;
}
-wil::com_ptr_nothrow GraphicsPipelineBuilder::Create(ID3D12Device* device, bool clear /*= true*/)
+wil::com_ptr_nothrow D3D12::GraphicsPipelineBuilder::Create(
+ ID3D12Device* device, bool clear /*= true*/)
{
wil::com_ptr_nothrow ps;
HRESULT hr = device->CreateGraphicsPipelineState(&m_desc, IID_PPV_ARGS(ps.put()));
@@ -55,8 +54,8 @@ wil::com_ptr_nothrow GraphicsPipelineBuilder::Create(ID3D12
return ps;
}
-wil::com_ptr_nothrow GraphicsPipelineBuilder::Create(ID3D12Device* device, ShaderCache& cache,
- bool clear /*= true*/)
+wil::com_ptr_nothrow D3D12::GraphicsPipelineBuilder::Create(
+ ID3D12Device* device, D3D12ShaderCache& cache, bool clear /*= true*/)
{
wil::com_ptr_nothrow pso = cache.GetPipelineState(device, m_desc);
if (!pso)
@@ -68,46 +67,49 @@ wil::com_ptr_nothrow GraphicsPipelineBuilder::Create(ID3D12
return pso;
}
-void GraphicsPipelineBuilder::SetRootSignature(ID3D12RootSignature* rs)
+void D3D12::GraphicsPipelineBuilder::SetRootSignature(ID3D12RootSignature* rs)
{
m_desc.pRootSignature = rs;
}
-void GraphicsPipelineBuilder::SetVertexShader(const ID3DBlob* blob)
+void D3D12::GraphicsPipelineBuilder::SetVertexShader(const ID3DBlob* blob)
{
- SetVertexShader(const_cast(blob)->GetBufferPointer(), static_cast(const_cast(blob)->GetBufferSize()));
+ SetVertexShader(const_cast(blob)->GetBufferPointer(),
+ static_cast(const_cast(blob)->GetBufferSize()));
}
-void GraphicsPipelineBuilder::SetVertexShader(const void* data, u32 data_size)
+void D3D12::GraphicsPipelineBuilder::SetVertexShader(const void* data, u32 data_size)
{
m_desc.VS.pShaderBytecode = data;
m_desc.VS.BytecodeLength = data_size;
}
-void GraphicsPipelineBuilder::SetGeometryShader(const ID3DBlob* blob)
+void D3D12::GraphicsPipelineBuilder::SetGeometryShader(const ID3DBlob* blob)
{
- SetGeometryShader(const_cast(blob)->GetBufferPointer(), static_cast(const_cast(blob)->GetBufferSize()));
+ SetGeometryShader(const_cast(blob)->GetBufferPointer(),
+ static_cast(const_cast(blob)->GetBufferSize()));
}
-void GraphicsPipelineBuilder::SetGeometryShader(const void* data, u32 data_size)
+void D3D12::GraphicsPipelineBuilder::SetGeometryShader(const void* data, u32 data_size)
{
m_desc.GS.pShaderBytecode = data;
m_desc.GS.BytecodeLength = data_size;
}
-void GraphicsPipelineBuilder::SetPixelShader(const ID3DBlob* blob)
+void D3D12::GraphicsPipelineBuilder::SetPixelShader(const ID3DBlob* blob)
{
- SetPixelShader(const_cast(blob)->GetBufferPointer(), static_cast(const_cast(blob)->GetBufferSize()));
+ SetPixelShader(const_cast(blob)->GetBufferPointer(),
+ static_cast(const_cast(blob)->GetBufferSize()));
}
-void GraphicsPipelineBuilder::SetPixelShader(const void* data, u32 data_size)
+void D3D12::GraphicsPipelineBuilder::SetPixelShader(const void* data, u32 data_size)
{
m_desc.PS.pShaderBytecode = data;
m_desc.PS.BytecodeLength = data_size;
}
-void GraphicsPipelineBuilder::AddVertexAttribute(const char* semantic_name, u32 semantic_index, DXGI_FORMAT format,
- u32 buffer, u32 offset)
+void D3D12::GraphicsPipelineBuilder::AddVertexAttribute(
+ const char* semantic_name, u32 semantic_index, DXGI_FORMAT format, u32 buffer, u32 offset)
{
const u32 index = m_desc.InputLayout.NumElements;
m_input_elements[index].SemanticIndex = semantic_index;
@@ -122,38 +124,38 @@ void GraphicsPipelineBuilder::AddVertexAttribute(const char* semantic_name, u32
m_desc.InputLayout.NumElements++;
}
-void GraphicsPipelineBuilder::SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE type)
+void D3D12::GraphicsPipelineBuilder::SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE type)
{
m_desc.PrimitiveTopologyType = type;
}
-void GraphicsPipelineBuilder::SetRasterizationState(D3D12_FILL_MODE polygon_mode, D3D12_CULL_MODE cull_mode,
- bool front_face_ccw)
+void D3D12::GraphicsPipelineBuilder::SetRasterizationState(
+ D3D12_FILL_MODE polygon_mode, D3D12_CULL_MODE cull_mode, bool front_face_ccw)
{
m_desc.RasterizerState.FillMode = polygon_mode;
m_desc.RasterizerState.CullMode = cull_mode;
m_desc.RasterizerState.FrontCounterClockwise = front_face_ccw;
}
-void GraphicsPipelineBuilder::SetMultisamples(u32 multisamples)
+void D3D12::GraphicsPipelineBuilder::SetMultisamples(u32 multisamples)
{
m_desc.RasterizerState.MultisampleEnable = multisamples > 1;
m_desc.SampleDesc.Count = multisamples;
}
-void GraphicsPipelineBuilder::SetNoCullRasterizationState()
+void D3D12::GraphicsPipelineBuilder::SetNoCullRasterizationState()
{
SetRasterizationState(D3D12_FILL_MODE_SOLID, D3D12_CULL_MODE_NONE, false);
}
-void GraphicsPipelineBuilder::SetDepthState(bool depth_test, bool depth_write, D3D12_COMPARISON_FUNC compare_op)
+void D3D12::GraphicsPipelineBuilder::SetDepthState(bool depth_test, bool depth_write, D3D12_COMPARISON_FUNC compare_op)
{
m_desc.DepthStencilState.DepthEnable = depth_test;
m_desc.DepthStencilState.DepthWriteMask = depth_write ? D3D12_DEPTH_WRITE_MASK_ALL : D3D12_DEPTH_WRITE_MASK_ZERO;
m_desc.DepthStencilState.DepthFunc = compare_op;
}
-void GraphicsPipelineBuilder::SetStencilState(bool stencil_test, u8 read_mask, u8 write_mask,
+void D3D12::GraphicsPipelineBuilder::SetStencilState(bool stencil_test, u8 read_mask, u8 write_mask,
const D3D12_DEPTH_STENCILOP_DESC& front, const D3D12_DEPTH_STENCILOP_DESC& back)
{
m_desc.DepthStencilState.StencilEnable = stencil_test;
@@ -163,21 +165,20 @@ void GraphicsPipelineBuilder::SetStencilState(bool stencil_test, u8 read_mask, u
m_desc.DepthStencilState.BackFace = back;
}
-void GraphicsPipelineBuilder::SetNoDepthTestState()
+void D3D12::GraphicsPipelineBuilder::SetNoDepthTestState()
{
SetDepthState(false, false, D3D12_COMPARISON_FUNC_ALWAYS);
}
-void GraphicsPipelineBuilder::SetNoStencilState()
+void D3D12::GraphicsPipelineBuilder::SetNoStencilState()
{
D3D12_DEPTH_STENCILOP_DESC empty = {};
SetStencilState(false, 0, 0, empty, empty);
}
-void GraphicsPipelineBuilder::SetBlendState(u32 rt, bool blend_enable, D3D12_BLEND src_factor, D3D12_BLEND dst_factor,
- D3D12_BLEND_OP op, D3D12_BLEND alpha_src_factor,
- D3D12_BLEND alpha_dst_factor, D3D12_BLEND_OP alpha_op,
- u8 write_mask /*= 0xFF*/)
+void D3D12::GraphicsPipelineBuilder::SetBlendState(u32 rt, bool blend_enable, D3D12_BLEND src_factor,
+ D3D12_BLEND dst_factor, D3D12_BLEND_OP op, D3D12_BLEND alpha_src_factor, D3D12_BLEND alpha_dst_factor,
+ D3D12_BLEND_OP alpha_op, u8 write_mask /*= 0xFF*/)
{
m_desc.BlendState.RenderTarget[rt].BlendEnable = blend_enable;
m_desc.BlendState.RenderTarget[rt].SrcBlend = src_factor;
@@ -192,49 +193,49 @@ void GraphicsPipelineBuilder::SetBlendState(u32 rt, bool blend_enable, D3D12_BLE
m_desc.BlendState.IndependentBlendEnable = TRUE;
}
-void GraphicsPipelineBuilder::SetNoBlendingState()
+void D3D12::GraphicsPipelineBuilder::SetNoBlendingState()
{
SetBlendState(0, false, D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD, D3D12_BLEND_ONE, D3D12_BLEND_ZERO,
D3D12_BLEND_OP_ADD, D3D12_COLOR_WRITE_ENABLE_ALL);
m_desc.BlendState.IndependentBlendEnable = FALSE;
}
-void GraphicsPipelineBuilder::ClearRenderTargets()
+void D3D12::GraphicsPipelineBuilder::ClearRenderTargets()
{
m_desc.NumRenderTargets = 0;
for (u32 i = 0; i < sizeof(m_desc.RTVFormats) / sizeof(m_desc.RTVFormats[0]); i++)
m_desc.RTVFormats[i] = DXGI_FORMAT_UNKNOWN;
}
-void GraphicsPipelineBuilder::SetRenderTarget(u32 rt, DXGI_FORMAT format)
+void D3D12::GraphicsPipelineBuilder::SetRenderTarget(u32 rt, DXGI_FORMAT format)
{
m_desc.RTVFormats[rt] = format;
if (rt >= m_desc.NumRenderTargets)
m_desc.NumRenderTargets = rt + 1;
}
-void GraphicsPipelineBuilder::ClearDepthStencilFormat()
+void D3D12::GraphicsPipelineBuilder::ClearDepthStencilFormat()
{
m_desc.DSVFormat = DXGI_FORMAT_UNKNOWN;
}
-void GraphicsPipelineBuilder::SetDepthStencilFormat(DXGI_FORMAT format)
+void D3D12::GraphicsPipelineBuilder::SetDepthStencilFormat(DXGI_FORMAT format)
{
m_desc.DSVFormat = format;
}
-
-ComputePipelineBuilder::ComputePipelineBuilder()
+D3D12::ComputePipelineBuilder::ComputePipelineBuilder()
{
Clear();
}
-void ComputePipelineBuilder::Clear()
+void D3D12::ComputePipelineBuilder::Clear()
{
std::memset(&m_desc, 0, sizeof(m_desc));
}
-wil::com_ptr_nothrow ComputePipelineBuilder::Create(ID3D12Device* device, bool clear /*= true*/)
+wil::com_ptr_nothrow D3D12::ComputePipelineBuilder::Create(
+ ID3D12Device* device, bool clear /*= true*/)
{
wil::com_ptr_nothrow ps;
HRESULT hr = device->CreateComputePipelineState(&m_desc, IID_PPV_ARGS(ps.put()));
@@ -250,7 +251,8 @@ wil::com_ptr_nothrow ComputePipelineBuilder::Create(ID3D12D
return ps;
}
-wil::com_ptr_nothrow