diff --git a/Juliet/Juliet.vcxproj b/Juliet/Juliet.vcxproj index 6e4dc40..2b134ec 100644 --- a/Juliet/Juliet.vcxproj +++ b/Juliet/Juliet.vcxproj @@ -123,50 +123,51 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + - - + + MultiThreadedDebugDll Disabled @@ -221,32 +222,32 @@ Default --target=amd64-pc-windows-msvc - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + MultiThreadedDebugDll Disabled @@ -307,8 +308,8 @@ - - + + diff --git a/Juliet/include/Core/Math/Shape.h b/Juliet/include/Core/Math/Shape.h new file mode 100644 index 0000000..05cfe9f --- /dev/null +++ b/Juliet/include/Core/Math/Shape.h @@ -0,0 +1,12 @@ +#pragma once + +namespace Juliet +{ + struct Rectangle + { + int32 X; + int32 Y; + int32 Width; + int32 Height; + }; +} \ No newline at end of file diff --git a/Juliet/include/Graphics/Graphics.h b/Juliet/include/Graphics/Graphics.h index 7333222..2a78f7a 100644 --- a/Juliet/include/Graphics/Graphics.h +++ b/Juliet/include/Graphics/Graphics.h @@ -1,7 +1,8 @@ #pragma once -#include +#include #include +#include #include #include #include @@ -67,6 +68,16 @@ namespace Juliet Immediate }; + struct GraphicsViewPort + { + float X; + float Y; + float Width; + float Height; + float MinDepth; + float MaxDepth; + }; + extern JULIET_API GraphicsDevice* CreateGraphicsDevice(GraphicsConfig config); extern JULIET_API void DestroyGraphicsDevice(NonNullPtr device); @@ -86,4 +97,9 @@ namespace Juliet extern JULIET_API RenderPass* BeginRenderPass(NonNullPtr commandList, ColorTargetInfo& colorTargetInfo); extern JULIET_API RenderPass* BeginRenderPass(NonNullPtr commandList, NonNullPtr colorTargetInfos, uint32 colorTargetInfoCount); + + extern JULIET_API void SetGraphicsViewPort(NonNullPtr renderPass, const GraphicsViewPort& viewPort); + extern JULIET_API void SetScissorRect(NonNullPtr renderPass, const Rectangle& rectangle); + extern JULIET_API void SetBlendConstants(NonNullPtr renderPass, FColor blendConstants); + extern JULIET_API void SetStencilReference(NonNullPtr renderPass, uint8 reference); } // namespace Juliet diff --git a/Juliet/include/Graphics/RenderPass.h b/Juliet/include/Graphics/RenderPass.h index fd433bb..358e6f7 100644 --- a/Juliet/include/Graphics/RenderPass.h +++ b/Juliet/include/Graphics/RenderPass.h @@ -22,17 +22,23 @@ namespace Juliet struct ColorTargetInfo { - Texture* Texture; - uint32 MipLevel; + Texture* TargetTexture; + uint32 MipLevel; union { uint32 DepthPlane; - uint32 LayerCount; + uint32 LayerIndex; }; + bool CycleTexture; // Whether the texture should be cycled if already bound (and load operation != LOAD) + + Texture* ResolveTexture; + uint32 ResolveMipLevel; + uint32 ResolveLayerIndex; + bool CycleResolveTexture; + FColor ClearColor; LoadOperation LoadOperation; StoreOperation StoreOperation; - bool Cycle; // Whether the texture should be cycled if already bound (and load operation != LOAD) }; // Opaque Type diff --git a/Juliet/src/Graphics/D3D12/D3D12RenderPass.cpp b/Juliet/src/Graphics/D3D12/D3D12RenderPass.cpp index a091dc9..06d4251 100644 --- a/Juliet/src/Graphics/D3D12/D3D12RenderPass.cpp +++ b/Juliet/src/Graphics/D3D12/D3D12RenderPass.cpp @@ -9,14 +9,14 @@ namespace Juliet::D3D12 { void BeginRenderPass(NonNullPtr commandList, NonNullPtr colorTargetInfos, uint32 colorTargetInfoCount) { - auto d3d12CommandList = reinterpret_cast(commandList.Get()); + auto* d3d12CommandList = reinterpret_cast(commandList.Get()); uint32 frameBufferWidth = uint32Max; uint32 frameBufferHeight = uint32Max; for (uint32 idx = 0; idx < colorTargetInfoCount; ++idx) { - auto* container = reinterpret_cast(colorTargetInfos[idx].Texture); + auto* container = reinterpret_cast(colorTargetInfos[idx].TargetTexture); uint32 width = container->Header.CreateInfo.Width >> colorTargetInfos[idx].MipLevel; uint32 height = container->Header.CreateInfo.Height >> colorTargetInfos[idx].MipLevel; @@ -30,11 +30,11 @@ namespace Juliet::D3D12 D3D12_CPU_DESCRIPTOR_HANDLE RTVs[GPUDriver::kMaxColorTargetInfo]; for (uint32 idx = 0; idx < colorTargetInfoCount; ++idx) { - auto* container = reinterpret_cast(colorTargetInfos[idx].Texture); + auto* container = reinterpret_cast(colorTargetInfos[idx].TargetTexture); D3D12TextureSubresource* subresource = PrepareTextureSubresourceForWrite( d3d12CommandList, container, - container->Header.CreateInfo.Type == TextureType::Texture_3D ? 0 : colorTargetInfos[idx].LayerCount, - colorTargetInfos[idx].MipLevel, colorTargetInfos[idx].Cycle, D3D12_RESOURCE_STATE_RENDER_TARGET); + container->Header.CreateInfo.Type == TextureType::Texture_3D ? 0 : colorTargetInfos[idx].LayerIndex, + colorTargetInfos[idx].MipLevel, colorTargetInfos[idx].CycleTexture, D3D12_RESOURCE_STATE_RENDER_TARGET); uint32 RTVIndex = container->Header.CreateInfo.Type == TextureType::Texture_3D ? colorTargetInfos[idx].DepthPlane : 0; D3D12_CPU_DESCRIPTOR_HANDLE rtv = subresource->RTVHandles[RTVIndex].CpuHandle; @@ -47,11 +47,64 @@ namespace Juliet::D3D12 clearColor[2] = colorTargetInfos[idx].ClearColor.B; clearColor[3] = colorTargetInfos[idx].ClearColor.A; - ID3D12GraphicsCommandList6_ClearRenderTargetView(d3d12CommandList->GraphicsCommandList.CommandList, rtv, clearColor, 0, nullptr); + ID3D12GraphicsCommandList6_ClearRenderTargetView(d3d12CommandList->GraphicsCommandList.CommandList, rtv, + clearColor, 0, nullptr); } - RTVs[idx] = rtv; - // d3d12CommandList->ColorTargetSubresources[idx] = subresource; + RTVs[idx] = rtv; + d3d12CommandList->ColorTargetSubresources[idx] = subresource; + + // TODO: TrackTexture + + if (colorTargetInfos[idx].StoreOperation == StoreOperation::Resolve || + colorTargetInfos[idx].StoreOperation == StoreOperation::ResolveAndStore) + { + auto resolveContainer = reinterpret_cast(colorTargetInfos[idx].ResolveTexture); + D3D12TextureSubresource* resolveSubresource = + PrepareTextureSubresourceForWrite(d3d12CommandList, resolveContainer, colorTargetInfos[idx].ResolveLayerIndex, + colorTargetInfos[idx].ResolveMipLevel, colorTargetInfos[idx].CycleResolveTexture, + D3D12_RESOURCE_STATE_RESOLVE_DEST); + + d3d12CommandList->ColorResolveSubresources[idx] = resolveSubresource; + + // TODO: TrackTexture Resolve + } } + + // TODO DSV + + ID3D12GraphicsCommandList_OMSetRenderTargets(d3d12CommandList->GraphicsCommandList.CommandList, + colorTargetInfoCount, RTVs, false, nullptr); + + // Set defaults graphics states + GraphicsViewPort defaultViewport; + defaultViewport.X = 0.f; + defaultViewport.Y = 0.f; + defaultViewport.Width = static_cast(frameBufferWidth); + defaultViewport.Height = static_cast(frameBufferHeight); + defaultViewport.MinDepth = 0.f; + defaultViewport.MaxDepth = 1.f; + SetViewPort(commandList, defaultViewport); + + Rectangle defaultScissor; + defaultScissor.X = 0; + defaultScissor.Y = 0; + defaultScissor.Width = static_cast(frameBufferWidth); + defaultScissor.Height = static_cast(frameBufferHeight); + SetScissorRect(commandList, defaultScissor); + + SetStencilReference(commandList, 0); + + FColor blendConstants; + blendConstants.R = 1.0f; + blendConstants.G = 1.0f; + blendConstants.B = 1.0f; + blendConstants.A = 1.0f; + SetBlendConstants(commandList, blendConstants); + } + + void EndRenderPass(NonNullPtr commandList) + { + auto* d3d12CommandList = reinterpret_cast(commandList.Get()); } } // namespace Juliet::D3D12 diff --git a/Juliet/src/Graphics/D3D12/D3D12RenderPass.h b/Juliet/src/Graphics/D3D12/D3D12RenderPass.h index 97784db..86c4021 100644 --- a/Juliet/src/Graphics/D3D12/D3D12RenderPass.h +++ b/Juliet/src/Graphics/D3D12/D3D12RenderPass.h @@ -8,4 +8,5 @@ namespace Juliet::D3D12 { extern void BeginRenderPass(NonNullPtr commandList, NonNullPtr colorTargetInfos, uint32 colorTargetInfoCount); -} + extern void EndRenderPass(NonNullPtr commandList); +} // namespace Juliet::D3D12 diff --git a/Juliet/src/Graphics/D3D12/D3D12Texture.cpp b/Juliet/src/Graphics/D3D12/D3D12Texture.cpp index c3ef383..f91388a 100644 --- a/Juliet/src/Graphics/D3D12/D3D12Texture.cpp +++ b/Juliet/src/Graphics/D3D12/D3D12Texture.cpp @@ -1,5 +1,6 @@ #include +#include #include #include #include diff --git a/Juliet/src/Graphics/D3D12/DX12CommandList.cpp b/Juliet/src/Graphics/D3D12/DX12CommandList.cpp index 2e6ab14..dfd389b 100644 --- a/Juliet/src/Graphics/D3D12/DX12CommandList.cpp +++ b/Juliet/src/Graphics/D3D12/DX12CommandList.cpp @@ -3,8 +3,7 @@ #include #include #include -#define IID_PPV_ARGS(ppType) __uuidof(decltype(**(ppType))), reinterpret_cast(ppType) -#define PPV_ARGS(x) IID_PPV_ARGS(&x) + namespace Juliet::D3D12 { namespace @@ -215,4 +214,42 @@ namespace Juliet::D3D12 return success; } + void SetViewPort(NonNullPtr commandList, const GraphicsViewPort& viewPort) + { + auto* d3d12CommandList = reinterpret_cast(commandList.Get()); + + D3D12_VIEWPORT d3d12Viewport; + d3d12Viewport.TopLeftX = viewPort.X; + d3d12Viewport.TopLeftY = viewPort.Y; + d3d12Viewport.Width = viewPort.Width; + d3d12Viewport.Height = viewPort.Height; + d3d12Viewport.MinDepth = viewPort.MinDepth; + d3d12Viewport.MaxDepth = viewPort.MaxDepth; + ID3D12GraphicsCommandList_RSSetViewports(d3d12CommandList->GraphicsCommandList.CommandList, 1, &d3d12Viewport); + } + + void SetScissorRect(NonNullPtr commandList, const Rectangle& rectangle) + { + auto* d3d12CommandList = reinterpret_cast(commandList.Get()); + D3D12_RECT scissorRect; + scissorRect.left = rectangle.X; + scissorRect.top = rectangle.Y; + scissorRect.right = rectangle.X + rectangle.Width; + scissorRect.bottom = rectangle.Y + rectangle.Height; + ID3D12GraphicsCommandList_RSSetScissorRects(d3d12CommandList->GraphicsCommandList.CommandList, 1, &scissorRect); + } + + void SetBlendConstants(NonNullPtr commandList, FColor blendConstants) + { + auto* d3d12CommandList = reinterpret_cast(commandList.Get()); + FLOAT blendFactor[4] = { blendConstants.R, blendConstants.G, blendConstants.B, blendConstants.A }; + ID3D12GraphicsCommandList_OMSetBlendFactor(d3d12CommandList->GraphicsCommandList.CommandList, blendFactor); + } + + void SetStencilReference(NonNullPtr commandList, uint8 reference) + { + auto* d3d12CommandList = reinterpret_cast(commandList.Get()); + ID3D12GraphicsCommandList_OMSetStencilRef(d3d12CommandList->GraphicsCommandList.CommandList, reference); + } + } // namespace Juliet::D3D12 diff --git a/Juliet/src/Graphics/D3D12/DX12CommandList.h b/Juliet/src/Graphics/D3D12/DX12CommandList.h index 4ae90ef..97609a3 100644 --- a/Juliet/src/Graphics/D3D12/DX12CommandList.h +++ b/Juliet/src/Graphics/D3D12/DX12CommandList.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include #include @@ -10,6 +10,7 @@ namespace Juliet::D3D12 // Forward Declare struct D3D12Driver; struct D3D12WindowData; + struct D3D12TextureSubresource; struct D3D12CommandListBaseData { @@ -46,8 +47,15 @@ namespace Juliet::D3D12 D3D12GraphicsCommandListData GraphicsCommandList; D3D12GraphicsCommandListData ComputeCommandList; D3D12CopyCommandListData CopyCommandList; + + D3D12TextureSubresource* ColorTargetSubresources[GPUDriver::kMaxColorTargetInfo]; + D3D12TextureSubresource* ColorResolveSubresources[GPUDriver::kMaxColorTargetInfo]; }; extern CommandList* AcquireCommandList(NonNullPtr driver, QueueType queueType); extern bool SubmitCommandLists(NonNullPtr driver); + extern void SetViewPort(NonNullPtr commandList, const GraphicsViewPort& viewPort); + extern void SetScissorRect(NonNullPtr commandList, const Rectangle& rectangle); + extern void SetBlendConstants(NonNullPtr commandList, FColor blendConstants); + extern void SetStencilReference(NonNullPtr commandList, uint8 reference); } // namespace Juliet::D3D12 diff --git a/Juliet/src/Graphics/D3D12/DX12GraphicsDevice.cpp b/Juliet/src/Graphics/D3D12/DX12GraphicsDevice.cpp index eca3fb8..9f01f94 100644 --- a/Juliet/src/Graphics/D3D12/DX12GraphicsDevice.cpp +++ b/Juliet/src/Graphics/D3D12/DX12GraphicsDevice.cpp @@ -552,6 +552,11 @@ namespace Juliet::D3D12 device->BeginRenderPass = BeginRenderPass; + device->SetViewPort = SetViewPort; + device->SetScissorRect = SetScissorRect; + device->SetBlendConstants = SetBlendConstants; + device->SetStencilReference = SetStencilReference; + device->Driver = driver; driver->GraphicsDevice = device; diff --git a/Juliet/src/Graphics/Graphics.cpp b/Juliet/src/Graphics/Graphics.cpp index 7ba48c6..db172dd 100644 --- a/Juliet/src/Graphics/Graphics.cpp +++ b/Juliet/src/Graphics/Graphics.cpp @@ -130,4 +130,36 @@ namespace Juliet return reinterpret_cast(&header->RenderPass); } + void SetGraphicsViewPort(NonNullPtr renderPass, const GraphicsViewPort& viewPort) + { + auto* commandList = reinterpret_cast(renderPass.Get())->CommandList; + auto* commandListHeader = reinterpret_cast(commandList); + + commandListHeader->Device->SetViewPort(commandList, viewPort); + } + + void SetScissorRect(NonNullPtr renderPass, const Rectangle& rectangle) + { + auto* commandList = reinterpret_cast(renderPass.Get())->CommandList; + auto* commandListHeader = reinterpret_cast(commandList); + + commandListHeader->Device->SetScissorRect(commandList, rectangle); + } + + void SetBlendConstants(NonNullPtr renderPass, FColor blendConstants) + { + auto* commandList = reinterpret_cast(renderPass.Get())->CommandList; + auto* commandListHeader = reinterpret_cast(commandList); + + commandListHeader->Device->SetBlendConstants(commandList, blendConstants); + } + + void SetStencilReference(NonNullPtr renderPass, uint8 reference) + { + auto* commandList = reinterpret_cast(renderPass.Get())->CommandList; + auto* commandListHeader = reinterpret_cast(commandList); + + commandListHeader->Device->SetStencilReference(commandList, reference); + } + } // namespace Juliet diff --git a/Juliet/src/Graphics/GraphicsDevice.h b/Juliet/src/Graphics/GraphicsDevice.h index 9a5ff3a..5513843 100644 --- a/Juliet/src/Graphics/GraphicsDevice.h +++ b/Juliet/src/Graphics/GraphicsDevice.h @@ -52,6 +52,11 @@ namespace Juliet void (*BeginRenderPass)(NonNullPtr commandList, NonNullPtr colorTargetInfos, uint32 colorTargetInfoCount); + void (*SetViewPort)(NonNullPtr commandList, const GraphicsViewPort& viewPort); + void (*SetScissorRect)(NonNullPtr commandList, const Rectangle& viewPort); + void (*SetBlendConstants)(NonNullPtr commandList, FColor blendConstants); + void (*SetStencilReference)(NonNullPtr commandList, uint8 reference); + const char* Name = "Unknown"; GPUDriver* Driver = nullptr; };