Added initial D3D12 code.
This commit is contained in:
parent
089104f677
commit
22d5bdd053
|
|
@ -797,7 +797,49 @@ static void deinit_vulkan_library() {
|
||||||
|
|
||||||
VkPipeline create_pipeline(const Vk_Pipeline_Def&);
|
VkPipeline create_pipeline(const Vk_Pipeline_Def&);
|
||||||
|
|
||||||
|
// Helper function for acquiring the first available hardware adapter that supports Direct3D 12.
|
||||||
|
// If no such adapter can be found, *ppAdapter will be set to nullptr.
|
||||||
|
void get_hardware_adapter(IDXGIFactory4* p_factory, IDXGIAdapter1** pp_adapter) {
|
||||||
|
ComPtr<IDXGIAdapter1> adapter;
|
||||||
|
*pp_adapter = nullptr;
|
||||||
|
|
||||||
|
for (UINT adapter_index = 0; DXGI_ERROR_NOT_FOUND != p_factory->EnumAdapters1(adapter_index, &adapter); ++adapter_index) {
|
||||||
|
DXGI_ADAPTER_DESC1 desc;
|
||||||
|
adapter->GetDesc1(&desc);
|
||||||
|
|
||||||
|
if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) {
|
||||||
|
// Don't select the Basic Render Driver adapter.
|
||||||
|
// If you want a software adapter, pass in "/warp" on the command line.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check to see if the adapter supports Direct3D 12, but don't create the
|
||||||
|
// actual device yet.
|
||||||
|
if (SUCCEEDED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr))) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*pp_adapter = adapter.Detach();
|
||||||
|
}
|
||||||
|
|
||||||
void vk_initialize() {
|
void vk_initialize() {
|
||||||
|
#if defined(_DEBUG)
|
||||||
|
// Enable the D3D12 debug layer
|
||||||
|
{
|
||||||
|
ComPtr<ID3D12Debug> debug_controller;
|
||||||
|
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debug_controller)))) {
|
||||||
|
debug_controller->EnableDebugLayer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ComPtr<IDXGIFactory4> factory;
|
||||||
|
DX_CHECK(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
|
||||||
|
|
||||||
|
ComPtr<IDXGIAdapter1> hardware_adapter;
|
||||||
|
get_hardware_adapter(factory.Get(), &hardware_adapter);
|
||||||
|
DX_CHECK(D3D12CreateDevice(hardware_adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&vk.dx_device)));
|
||||||
|
|
||||||
init_vulkan_library();
|
init_vulkan_library();
|
||||||
|
|
||||||
VkPhysicalDeviceFeatures features;
|
VkPhysicalDeviceFeatures features;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,13 @@
|
||||||
#define VK_NO_PROTOTYPES
|
#define VK_NO_PROTOTYPES
|
||||||
#include "vulkan/vulkan.h"
|
#include "vulkan/vulkan.h"
|
||||||
|
|
||||||
|
#include "D3d12.h"
|
||||||
|
#include "D3d12SDKLayers.h"
|
||||||
|
#include "DXGI1_4.h"
|
||||||
|
#include "wrl.h"
|
||||||
|
|
||||||
|
using Microsoft::WRL::ComPtr;
|
||||||
|
|
||||||
const int MAX_SWAPCHAIN_IMAGES = 8;
|
const int MAX_SWAPCHAIN_IMAGES = 8;
|
||||||
const int MAX_VK_SAMPLERS = 32;
|
const int MAX_VK_SAMPLERS = 32;
|
||||||
const int MAX_VK_PIPELINES = 1024;
|
const int MAX_VK_PIPELINES = 1024;
|
||||||
|
|
@ -22,6 +29,12 @@ const int MAX_IMAGE_CHUNKS = 16;
|
||||||
ri.Error(ERR_FATAL, "Vulkan: error code %d returned by %s", result, #function_call); \
|
ri.Error(ERR_FATAL, "Vulkan: error code %d returned by %s", result, #function_call); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DX_CHECK(function_call) { \
|
||||||
|
HRESULT hr = function_call; \
|
||||||
|
if (FAILED(hr)) \
|
||||||
|
ri.Error(ERR_FATAL, "Direct3D: error returned by %s", #function_call); \
|
||||||
|
}
|
||||||
|
|
||||||
enum class Vk_Shader_Type {
|
enum class Vk_Shader_Type {
|
||||||
single_texture,
|
single_texture,
|
||||||
multi_texture_mul,
|
multi_texture_mul,
|
||||||
|
|
@ -107,6 +120,9 @@ void vk_read_pixels(byte* buffer); // screenshots
|
||||||
// This structure is initialized/deinitialized by vk_initialize/vk_shutdown functions correspondingly.
|
// This structure is initialized/deinitialized by vk_initialize/vk_shutdown functions correspondingly.
|
||||||
struct Vk_Instance {
|
struct Vk_Instance {
|
||||||
bool active = false;
|
bool active = false;
|
||||||
|
|
||||||
|
ComPtr<ID3D12Device> dx_device;
|
||||||
|
|
||||||
VkInstance instance = VK_NULL_HANDLE;
|
VkInstance instance = VK_NULL_HANDLE;
|
||||||
VkPhysicalDevice physical_device = VK_NULL_HANDLE;
|
VkPhysicalDevice physical_device = VK_NULL_HANDLE;
|
||||||
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@
|
||||||
<Culture>0x0409</Culture>
|
<Culture>0x0409</Culture>
|
||||||
</ResourceCompile>
|
</ResourceCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>winmm.lib;wsock32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>winmm.lib;wsock32.lib;D3d12.lib;DXGI.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|
@ -120,7 +120,7 @@
|
||||||
<Culture>0x0409</Culture>
|
<Culture>0x0409</Culture>
|
||||||
</ResourceCompile>
|
</ResourceCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>winmm.lib;wsock32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>winmm.lib;wsock32.lib;D3d12.lib;DXGI.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
<StackReserveSize>8388608</StackReserveSize>
|
<StackReserveSize>8388608</StackReserveSize>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user