Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
DirectX12GraphicsWrapper.hpp
1#pragma once
2
3#include "../GraphicsCommon/GraphicsWrapper.hpp"
4#include <d3d12.h>
5#include <dxgi1_6.h>
6
7#include <wrl.h>
8using namespace Microsoft::WRL;
9
10namespace Grindstone {
11 namespace GraphicsAPI {
12 const int num_buffers = 3;
13
14 class DirectX12GraphicsWrapper : public GraphicsWrapper {
15 public:
16 bool initialize(GraphicsWrapperCreateInfo ci);
18
19 static DirectX12GraphicsWrapper* graphics_wrapper_;
20 static DirectX12GraphicsWrapper& get();
21 public:
22 private:
23
24 public:
25 ID3D12Fence* fence_[num_buffers]; // an object that is locked while our command list is being executed by the gpu. We need as many
26 HANDLE fence_event_; // a handle to an event when our fence is unlocked by the gpu
27 UINT64 fence_value_[num_buffers]; // this value is incremented each frame. each fence will have its own value
28 int frame_index_;
29
30 ID3D12CommandQueue* direct_command_queue_;
31 ID3D12CommandQueue* compute_command_queue_;
32 ID3D12CommandQueue* copy_command_queue_;
33
34 ComPtr<IDXGIAdapter4> dxgi_adapter_;
35 ComPtr<ID3D12Device2> device_;
36 ComPtr<IDXGISwapChain4> swap_chain_;
37 ComPtr<ID3D12CommandQueue> command_queue_;
38 ID3D12CommandAllocator* graphics_command_allocator_;
39 uint32_t current_backbuffer_index_;
40
41 std::vector<RenderTarget *> swap_chain_targets_;
42 ComPtr<ID3D12DescriptorHeap> rt_descriptor_heap_;
43 private:
44 void setupDebugMessenger();
45 void createCommandQueues();
46 void pickPhysicalDevice();
47 void createLogicalDevice();
48 void createSwapChain();
49 void createCommandPool();
50 void createDescriptorPool();
51 void createSyncObjects();
52 private:
53
54 public:
55 virtual const char* getVendorName() override;
56 virtual const char* getAdapterName() override;
57 virtual const char* getAPIName() override;
58 virtual const char* getAPIVersion() override;
59
60 virtual void adjustPerspective(float* perspective) override;
61
62 void registerWindow(Window* window);
63
64 virtual void deleteRenderTarget(RenderTarget* ptr) override;
65 virtual void deleteDepthStencilTarget(DepthStencilTarget* ptr) override;
66 virtual void deleteFramebuffer(Framebuffer* ptr) override;
67 virtual void deleteVertexBuffer(VertexBuffer* ptr) override;
68 virtual void deleteIndexBuffer(IndexBuffer* ptr) override;
69 virtual void deleteUniformBuffer(UniformBuffer* ptr) override;
70 virtual void deleteUniformBufferBinding(UniformBufferBinding* ptr) override;
71 virtual void deleteGraphicsPipeline(GraphicsPipeline* ptr) override;
72 virtual void deleteRenderPass(RenderPass* ptr) override;
73 virtual void deleteTexture(Texture* ptr) override;
74 virtual void deleteTextureBinding(TextureBinding* ptr) override;
75 virtual void deleteTextureBindingLayout(TextureBindingLayout* ptr) override;
76 virtual void deleteCommandBuffer(CommandBuffer* ptr) override;
77 virtual void deleteVertexArrayObject(VertexArrayObject* ptr) override;
78
79 virtual Framebuffer* createFramebuffer(FramebufferCreateInfo ci) override;
80 virtual RenderPass* createRenderPass(RenderPassCreateInfo ci) override;
81 virtual GraphicsPipeline* createGraphicsPipeline(GraphicsPipelineCreateInfo ci) override;
82 virtual CommandBuffer* createCommandBuffer(CommandBufferCreateInfo ci) override;
83 virtual VertexArrayObject* createVertexArrayObject(VertexArrayObjectCreateInfo ci) override;
84 virtual VertexBuffer* createVertexBuffer(VertexBufferCreateInfo ci) override;
85 virtual IndexBuffer* createIndexBuffer(IndexBufferCreateInfo ci) override;
86 virtual UniformBuffer* createUniformBuffer(UniformBufferCreateInfo ci) override;
87 virtual UniformBufferBinding* createUniformBufferBinding(UniformBufferBindingCreateInfo ci) override;
88 virtual Texture* createCubemap(CubemapCreateInfo createInfo) override;
89 virtual Texture* createTexture(TextureCreateInfo createInfo) override;
90 virtual TextureBinding* createTextureBinding(TextureBindingCreateInfo ci) override;
91 virtual TextureBindingLayout* createTextureBindingLayout(TextureBindingLayoutCreateInfo createInfo) override;
92 virtual RenderTarget* createRenderTarget(RenderTargetCreateInfo* rt, uint32_t rc, bool cube = false) override;
93 virtual DepthStencilTarget* createDepthStencilTarget(DepthStencilTargetCreateInfo rt) override;
94
95 virtual inline const bool shouldUseImmediateMode() override;
96 virtual inline const bool supportsCommandBuffers() override;
97 virtual inline const bool supportsTesselation() override;
98 virtual inline const bool supportsGeometryShader() override;
99 virtual inline const bool supportsComputeShader() override;
100 virtual inline const bool supportsMultiDrawIndirect() override;
101
102 virtual void waitUntilIdle() override;
103
104 // Unused
105 virtual void clear(ClearMode mask, float clear_color[4], float clear_depth, uint32_t clear_stencil) override;
106 virtual void bindTextureBinding(TextureBinding*) override;
107 virtual void bindVertexArrayObject(VertexArrayObject*) override;
108 virtual void drawImmediateIndexed(GeometryType geom_type, bool largeBuffer, int32_t baseVertex, uint32_t indexOffsetPtr, uint32_t indexCount) override;
109 virtual void drawImmediateVertices(GeometryType geom_type, uint32_t base, uint32_t count) override;
110 virtual void setImmediateBlending(BlendMode) override;
111 virtual void enableDepth(bool state) override;
112 virtual void setColorMask(ColorMask mask) override;
113 virtual void copyToDepthBuffer(DepthStencilTarget* p) override;
114 virtual void bindDefaultFramebuffer(bool depth) override;
115 private:
116 std::string vendor_name_;
117 std::string adapter_name_;
118 std::string api_version_;
119 };
120 }
121}
Definition CommandBuffer.hpp:21
Definition DepthStencilTarget.hpp:15
Definition DirectX12GraphicsWrapper.hpp:14
Definition Framebuffer.hpp:19
Definition GraphicsPipeline.hpp:18
Definition IndexBuffer.hpp:11
Definition RenderPass.hpp:27
Definition RenderTarget.hpp:12
Definition Texture.hpp:40
Definition UniformBuffer.hpp:10
Definition VertexArrayObject.hpp:10
Definition VertexBuffer.hpp:130
Definition Window.cs:7