Draw triangle
This commit is contained in:
@@ -110,6 +110,11 @@ namespace Juliet
|
|||||||
extern JULIET_API void SetBlendConstants(NonNullPtr<RenderPass> renderPass, FColor blendConstants);
|
extern JULIET_API void SetBlendConstants(NonNullPtr<RenderPass> renderPass, FColor blendConstants);
|
||||||
extern JULIET_API void SetStencilReference(NonNullPtr<RenderPass> renderPass, uint8 reference);
|
extern JULIET_API void SetStencilReference(NonNullPtr<RenderPass> renderPass, uint8 reference);
|
||||||
|
|
||||||
|
extern JULIET_API void BindGraphicsPipeline(NonNullPtr<RenderPass> renderPass, NonNullPtr<GraphicsPipeline> graphicsPipeline);
|
||||||
|
|
||||||
|
extern JULIET_API void DrawPrimitives(NonNullPtr<RenderPass> renderPass, uint32 numVertices, uint32 numInstances,
|
||||||
|
uint32 firstVertex, uint32 firstInstance);
|
||||||
|
|
||||||
// Shaders
|
// Shaders
|
||||||
extern JULIET_API Shader* CreateShader(NonNullPtr<GraphicsDevice> device, String filename, ShaderCreateInfo& shaderCreateInfo);
|
extern JULIET_API Shader* CreateShader(NonNullPtr<GraphicsDevice> device, String filename, ShaderCreateInfo& shaderCreateInfo);
|
||||||
extern JULIET_API void DestroyShader(NonNullPtr<GraphicsDevice> device, NonNullPtr<Shader> shader);
|
extern JULIET_API void DestroyShader(NonNullPtr<GraphicsDevice> device, NonNullPtr<Shader> shader);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <Core/Common/NonNullPtr.h>
|
#include <Core/Common/NonNullPtr.h>
|
||||||
#include <Core/Math/Shape.h>
|
#include <Core/Math/Shape.h>
|
||||||
|
#include <D3D12GraphicsPipeline.h>
|
||||||
#include <Graphics/D3D12/D3D12Includes.h>
|
#include <Graphics/D3D12/D3D12Includes.h>
|
||||||
#include <Graphics/GraphicsDevice.h>
|
#include <Graphics/GraphicsDevice.h>
|
||||||
|
|
||||||
@@ -52,8 +53,25 @@ namespace Juliet::D3D12
|
|||||||
D3D12GraphicsCommandListData ComputeCommandList;
|
D3D12GraphicsCommandListData ComputeCommandList;
|
||||||
D3D12CopyCommandListData CopyCommandList;
|
D3D12CopyCommandListData CopyCommandList;
|
||||||
|
|
||||||
|
D3D12GraphicsPipeline* CurrentGraphicsPipeline;
|
||||||
|
|
||||||
D3D12TextureSubresource* ColorTargetSubresources[GPUDriver::kMaxColorTargetInfo];
|
D3D12TextureSubresource* ColorTargetSubresources[GPUDriver::kMaxColorTargetInfo];
|
||||||
D3D12TextureSubresource* ColorResolveSubresources[GPUDriver::kMaxColorTargetInfo];
|
D3D12TextureSubresource* ColorResolveSubresources[GPUDriver::kMaxColorTargetInfo];
|
||||||
|
|
||||||
|
bool NeedVertexBufferBind : 1;
|
||||||
|
bool NeedVertexSamplerBind : 1;
|
||||||
|
bool NeedVertexStorageTextureBind : 1;
|
||||||
|
bool NeedVertexStorageBufferBind : 1;
|
||||||
|
|
||||||
|
bool NeedFragmentSamplerBind : 1;
|
||||||
|
bool NeedFragmentStorageTextureBind : 1;
|
||||||
|
bool NeedFragmentStorageBufferBind : 1;
|
||||||
|
|
||||||
|
bool NeedVertexUniformBufferBind[GPUDriver::kMaxUniformBuffersPerStage];
|
||||||
|
bool NeedFragmentUniformBufferBind[GPUDriver::kMaxUniformBuffersPerStage];
|
||||||
|
|
||||||
|
//D3D12UniformBuffer *vertexUniformBuffers[GPUDriver::kMaxUniformBuffersPerStage];
|
||||||
|
//D3D12UniformBuffer *fragmentUniformBuffers[GPUDriver::kMaxUniformBuffersPerStage];
|
||||||
};
|
};
|
||||||
|
|
||||||
extern CommandList* AcquireCommandList(NonNullPtr<GPUDriver> driver, QueueType queueType);
|
extern CommandList* AcquireCommandList(NonNullPtr<GPUDriver> driver, QueueType queueType);
|
||||||
|
|||||||
@@ -262,7 +262,8 @@ namespace Juliet::D3D12
|
|||||||
{
|
{
|
||||||
// Only supported on Win 11 apparently
|
// Only supported on Win 11 apparently
|
||||||
ID3D12InfoQueue1* infoQueue = nullptr;
|
ID3D12InfoQueue1* infoQueue = nullptr;
|
||||||
HRESULT result = ID3D12Device5_QueryInterface(driver->D3D12Device, IID_ID3D12InfoQueue1, reinterpret_cast<void**>(&infoQueue));
|
HRESULT result =
|
||||||
|
ID3D12Device5_QueryInterface(driver->D3D12Device, IID_ID3D12InfoQueue1, reinterpret_cast<void**>(&infoQueue));
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -729,6 +730,8 @@ namespace Juliet::D3D12
|
|||||||
device->SetScissorRect = SetScissorRect;
|
device->SetScissorRect = SetScissorRect;
|
||||||
device->SetBlendConstants = SetBlendConstants;
|
device->SetBlendConstants = SetBlendConstants;
|
||||||
device->SetStencilReference = SetStencilReference;
|
device->SetStencilReference = SetStencilReference;
|
||||||
|
device->BindGraphicsPipeline = BindGraphicsPipeline;
|
||||||
|
device->DrawPrimitives = DrawPrimitives;
|
||||||
device->Wait = Wait;
|
device->Wait = Wait;
|
||||||
device->QueryFence = QueryFence;
|
device->QueryFence = QueryFence;
|
||||||
device->ReleaseFence = ReleaseFence;
|
device->ReleaseFence = ReleaseFence;
|
||||||
|
|||||||
@@ -705,7 +705,7 @@ namespace Juliet::D3D12
|
|||||||
return reinterpret_cast<GraphicsPipeline*>(pipeline);
|
return reinterpret_cast<GraphicsPipeline*>(pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void DestroyGraphicsPipeline(NonNullPtr<GPUDriver> driver, NonNullPtr<GraphicsPipeline> graphicsPipeline)
|
void DestroyGraphicsPipeline(NonNullPtr<GPUDriver> driver, NonNullPtr<GraphicsPipeline> graphicsPipeline)
|
||||||
{
|
{
|
||||||
auto d3d12Driver = static_cast<D3D12Driver*>(driver.Get());
|
auto d3d12Driver = static_cast<D3D12Driver*>(driver.Get());
|
||||||
auto d3d12GraphicsPipeline = reinterpret_cast<D3D12GraphicsPipeline*>(graphicsPipeline.Get());
|
auto d3d12GraphicsPipeline = reinterpret_cast<D3D12GraphicsPipeline*>(graphicsPipeline.Get());
|
||||||
|
|||||||
@@ -1,12 +1,28 @@
|
|||||||
#include <pch.h>
|
#include <pch.h>
|
||||||
|
|
||||||
|
#include <Core/Common/EnumUtils.h>
|
||||||
|
#include <Graphics/D3D12/D3D12GraphicsPipeline.h>
|
||||||
#include <Graphics/D3D12/D3D12RenderPass.h>
|
#include <Graphics/D3D12/D3D12RenderPass.h>
|
||||||
#include <Graphics/D3D12/D3D12Texture.h>
|
#include <Graphics/D3D12/D3D12Texture.h>
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
namespace Juliet::D3D12
|
namespace Juliet::D3D12
|
||||||
{
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
// clang-format off
|
||||||
|
D3D12_PRIMITIVE_TOPOLOGY JulietToD3D12_PrimitiveType[] =
|
||||||
|
{
|
||||||
|
D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
|
||||||
|
D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
|
||||||
|
D3D_PRIMITIVE_TOPOLOGY_LINELIST,
|
||||||
|
D3D_PRIMITIVE_TOPOLOGY_LINESTRIP,
|
||||||
|
D3D_PRIMITIVE_TOPOLOGY_POINTLIST
|
||||||
|
};
|
||||||
|
// clang-format on
|
||||||
|
static_assert(sizeof(JulietToD3D12_PrimitiveType) / sizeof(JulietToD3D12_PrimitiveType[0]) ==
|
||||||
|
ToUnderlying(PrimitiveType::Count));
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void BeginRenderPass(NonNullPtr<CommandList> commandList, NonNullPtr<const ColorTargetInfo> colorTargetInfos, uint32 colorTargetInfoCount)
|
void BeginRenderPass(NonNullPtr<CommandList> commandList, NonNullPtr<const ColorTargetInfo> colorTargetInfos, uint32 colorTargetInfoCount)
|
||||||
{
|
{
|
||||||
auto* d3d12CommandList = reinterpret_cast<D3D12CommandList*>(commandList.Get());
|
auto* d3d12CommandList = reinterpret_cast<D3D12CommandList*>(commandList.Get());
|
||||||
@@ -146,7 +162,7 @@ namespace Juliet::D3D12
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO : Write Depth stencil
|
// TODO : Write Depth stencil
|
||||||
// TODO : Reset graphics pipeline
|
d3d12CommandList->CurrentGraphicsPipeline = nullptr;
|
||||||
|
|
||||||
ID3D12GraphicsCommandList_OMSetRenderTargets(d3d12CommandList->GraphicsCommandList.CommandList, 0, NULL, false, NULL);
|
ID3D12GraphicsCommandList_OMSetRenderTargets(d3d12CommandList->GraphicsCommandList.CommandList, 0, NULL, false, NULL);
|
||||||
|
|
||||||
@@ -154,7 +170,78 @@ namespace Juliet::D3D12
|
|||||||
ZeroArray(d3d12CommandList->ColorTargetSubresources);
|
ZeroArray(d3d12CommandList->ColorTargetSubresources);
|
||||||
ZeroArray(d3d12CommandList->ColorResolveSubresources);
|
ZeroArray(d3d12CommandList->ColorResolveSubresources);
|
||||||
// TODO : reset depth stencil subresources
|
// TODO : reset depth stencil subresources
|
||||||
|
// d3d12CommandList->DepthStencilTextureSubresource = NULL;
|
||||||
|
|
||||||
// TODO : vertex buffer
|
// TODO : vertex buffer
|
||||||
// TODO :Vertex sampler and fragment sampler
|
// TODO :Vertex sampler and fragment sampler
|
||||||
|
|
||||||
|
// ZeroArray(d3d12CommandList->VertexBuffers);
|
||||||
|
// ZeroArray(d3d12CommandList->VertexBufferOffsets);
|
||||||
|
// d3d12CommandList->VertexBufferCount = 0;
|
||||||
|
//
|
||||||
|
// ZeroArray(d3d12CommandList->VertexSamplerTextures);
|
||||||
|
// ZeroArray(d3d12CommandList->VertexSamplers);
|
||||||
|
// ZeroArray(d3d12CommandList->VertexStorageTextures);
|
||||||
|
// ZeroArray(d3d12CommandList->VertexStorageBuffers);
|
||||||
|
//
|
||||||
|
// ZeroArray(d3d12CommandList->FragmentSamplerTextures);
|
||||||
|
// ZeroArray(d3d12CommandList->FragmentSamplers);
|
||||||
|
// ZeroArray(d3d12CommandList->FragmentStorageTextures);
|
||||||
|
// ZeroArray(d3d12CommandList->FragmentStorageBuffers);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BindGraphicsPipeline(NonNullPtr<CommandList> commandList, NonNullPtr<GraphicsPipeline> graphicsPipeline)
|
||||||
|
{
|
||||||
|
auto* d3d12CommandList = reinterpret_cast<D3D12CommandList*>(commandList.Get());
|
||||||
|
auto pipeline = reinterpret_cast<D3D12GraphicsPipeline*>(graphicsPipeline.Get());
|
||||||
|
|
||||||
|
d3d12CommandList->CurrentGraphicsPipeline = pipeline;
|
||||||
|
|
||||||
|
// Set the pipeline state
|
||||||
|
ID3D12GraphicsCommandList_SetPipelineState(d3d12CommandList->GraphicsCommandList.CommandList, pipeline->PipelineState);
|
||||||
|
ID3D12GraphicsCommandList_SetGraphicsRootSignature(d3d12CommandList->GraphicsCommandList.CommandList,
|
||||||
|
pipeline->RootSignature->Handle);
|
||||||
|
ID3D12GraphicsCommandList_IASetPrimitiveTopology(d3d12CommandList->GraphicsCommandList.CommandList,
|
||||||
|
JulietToD3D12_PrimitiveType[ToUnderlying(pipeline->PrimitiveType)]);
|
||||||
|
|
||||||
|
// Mark that bindings are needed
|
||||||
|
d3d12CommandList->NeedVertexSamplerBind = true;
|
||||||
|
d3d12CommandList->NeedVertexStorageTextureBind = true;
|
||||||
|
d3d12CommandList->NeedVertexStorageBufferBind = true;
|
||||||
|
d3d12CommandList->NeedFragmentSamplerBind = true;
|
||||||
|
d3d12CommandList->NeedFragmentStorageTextureBind = true;
|
||||||
|
d3d12CommandList->NeedFragmentStorageBufferBind = true;
|
||||||
|
|
||||||
|
for (uint32 idx = 0; idx < GPUDriver::kMaxUniformBuffersPerStage; ++idx)
|
||||||
|
{
|
||||||
|
d3d12CommandList->NeedVertexUniformBufferBind[idx] = true;
|
||||||
|
d3d12CommandList->NeedFragmentUniformBufferBind[idx] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32 idx = 0; idx < pipeline->VertexUniformBufferCount; ++idx)
|
||||||
|
{
|
||||||
|
// if (d3d12CommandList->VertexUniformBuffers[i] == NULL)
|
||||||
|
// {
|
||||||
|
// d3d12CommandList->VertexUniformBuffers[i] = D3D12_INTERNAL_AcquireUniformBufferFromPool(d3d12CommandBuffer);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32 idx = 0; idx < pipeline->FragmentUniformBufferCount; ++idx)
|
||||||
|
{
|
||||||
|
// if (d3d12CommandList->FragmentUniformBuffers[i] == NULL)
|
||||||
|
// {
|
||||||
|
// d3d12CommandList->FragmentUniformBuffers[i] = D3D12_INTERNAL_AcquireUniformBufferFromPool(d3d12CommandBuffer);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawPrimitives(NonNullPtr<CommandList> commandList, uint32 numVertices, uint32 numInstances, uint32 firstVertex, uint32 firstInstance)
|
||||||
|
{
|
||||||
|
auto* d3d12CommandList = reinterpret_cast<D3D12CommandList*>(commandList.Get());
|
||||||
|
// TODO : Last missing piece
|
||||||
|
// D3D12_INTERNAL_BindGraphicsResources(d3d12CommandBuffer);
|
||||||
|
|
||||||
|
ID3D12GraphicsCommandList_DrawInstanced(d3d12CommandList->GraphicsCommandList.CommandList, numVertices,
|
||||||
|
numInstances, firstVertex, firstInstance);
|
||||||
}
|
}
|
||||||
} // namespace Juliet::D3D12
|
} // namespace Juliet::D3D12
|
||||||
|
|||||||
@@ -9,4 +9,8 @@ namespace Juliet::D3D12
|
|||||||
extern void BeginRenderPass(NonNullPtr<CommandList> commandList, NonNullPtr<const ColorTargetInfo> colorTargetInfos,
|
extern void BeginRenderPass(NonNullPtr<CommandList> commandList, NonNullPtr<const ColorTargetInfo> colorTargetInfos,
|
||||||
uint32 colorTargetInfoCount);
|
uint32 colorTargetInfoCount);
|
||||||
extern void EndRenderPass(NonNullPtr<CommandList> commandList);
|
extern void EndRenderPass(NonNullPtr<CommandList> commandList);
|
||||||
|
|
||||||
|
extern void BindGraphicsPipeline(NonNullPtr<CommandList> commandList, NonNullPtr<GraphicsPipeline> graphicsPipeline);
|
||||||
|
extern void DrawPrimitives(NonNullPtr<CommandList> commandList, uint32 numVertices, uint32 numInstances,
|
||||||
|
uint32 firstVertex, uint32 firstInstance);
|
||||||
} // namespace Juliet::D3D12
|
} // namespace Juliet::D3D12
|
||||||
|
|||||||
@@ -181,6 +181,23 @@ namespace Juliet
|
|||||||
commandListHeader->Device->SetStencilReference(commandList, reference);
|
commandListHeader->Device->SetStencilReference(commandList, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BindGraphicsPipeline(NonNullPtr<RenderPass> renderPass, NonNullPtr<GraphicsPipeline> graphicsPipeline)
|
||||||
|
{
|
||||||
|
auto* commandList = reinterpret_cast<GPUPass*>(renderPass.Get())->CommandList;
|
||||||
|
auto* commandListHeader = reinterpret_cast<CommandListHeader*>(commandList);
|
||||||
|
|
||||||
|
commandListHeader->Device->BindGraphicsPipeline(commandList, graphicsPipeline);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawPrimitives(NonNullPtr<RenderPass> renderPass, uint32 numVertices, uint32 numInstances,
|
||||||
|
uint32 firstVertex, uint32 firstInstance)
|
||||||
|
{
|
||||||
|
auto* commandList = reinterpret_cast<GPUPass*>(renderPass.Get())->CommandList;
|
||||||
|
auto* commandListHeader = reinterpret_cast<CommandListHeader*>(commandList);
|
||||||
|
|
||||||
|
commandListHeader->Device->DrawPrimitives(commandList, numVertices, numInstances, firstVertex, firstInstance);
|
||||||
|
}
|
||||||
|
|
||||||
// Shaders
|
// Shaders
|
||||||
Shader* CreateShader(NonNullPtr<GraphicsDevice> device, String filename, ShaderCreateInfo& shaderCreateInfo)
|
Shader* CreateShader(NonNullPtr<GraphicsDevice> device, String filename, ShaderCreateInfo& shaderCreateInfo)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ namespace Juliet
|
|||||||
void (*SetBlendConstants)(NonNullPtr<CommandList> commandList, FColor blendConstants);
|
void (*SetBlendConstants)(NonNullPtr<CommandList> commandList, FColor blendConstants);
|
||||||
void (*SetStencilReference)(NonNullPtr<CommandList> commandList, uint8 reference);
|
void (*SetStencilReference)(NonNullPtr<CommandList> commandList, uint8 reference);
|
||||||
|
|
||||||
|
void (*BindGraphicsPipeline)(NonNullPtr<CommandList> commandList, NonNullPtr<GraphicsPipeline> graphicsPipeline);
|
||||||
|
void (*DrawPrimitives)(NonNullPtr<CommandList> commandList, uint32 numVertices, uint32 numInstances,
|
||||||
|
uint32 firstVertex, uint32 firstInstance);
|
||||||
|
|
||||||
// Fences
|
// Fences
|
||||||
bool (*Wait)(NonNullPtr<GPUDriver> driver);
|
bool (*Wait)(NonNullPtr<GPUDriver> driver);
|
||||||
bool (*QueryFence)(NonNullPtr<GPUDriver> driver, NonNullPtr<Fence> fence);
|
bool (*QueryFence)(NonNullPtr<GPUDriver> driver, NonNullPtr<Fence> fence);
|
||||||
|
|||||||
@@ -204,6 +204,8 @@ void JulietApplication::Update()
|
|||||||
colorTargetInfo.StoreOperation = StoreOperation::Store;
|
colorTargetInfo.StoreOperation = StoreOperation::Store;
|
||||||
|
|
||||||
RenderPass* renderPass = BeginRenderPass(cmdList, colorTargetInfo);
|
RenderPass* renderPass = BeginRenderPass(cmdList, colorTargetInfo);
|
||||||
|
BindGraphicsPipeline(renderPass, GraphicsPipeline);
|
||||||
|
DrawPrimitives(renderPass, 3, 1, 0, 0);
|
||||||
EndRenderPass(renderPass);
|
EndRenderPass(renderPass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user