Skip to content

Commit

Permalink
[D3D11] Refactored secondary command buffers in D3D11 backend.
Browse files Browse the repository at this point in the history
- Added virtual command encoding for D3D11 secondary command buffers (similar to GL and Metal backends).
- Moved some commands into D3D11CommandContext class.
- Added restriction to definition of CopyTextureFromFramebuffer() function: Must only be used inside render pass.
- Fixed CommandBufferSecondary test for D3D11.
  • Loading branch information
LukasBanana committed Jun 1, 2024
1 parent 3bb9c69 commit f2b153b
Show file tree
Hide file tree
Showing 24 changed files with 2,145 additions and 712 deletions.
2 changes: 2 additions & 0 deletions include/LLGL/CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ class LLGL_EXPORT CommandBuffer : public RenderSystemChild
\param[in] srcOffset Specifies the source offset at which the framebuffer is to be read from.
If the source offset plus the destination dimension is larger the framebuffer's resolution, the behavior is undefined.
\remarks This command must only be used inside a render pass.
\remarks For performance reasons, it is recommended to render a scene into a RenderTarget instead of copying the framebuffer into a texture.
This command merely simplifies the process of capturing the framebuffer mid-scene without having to interrupt a render pass or creating an intermediate render target.
Expand Down
2 changes: 1 addition & 1 deletion include/LLGL/InterfaceID.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace LLGL
\remarks The ID for a base class must always have a smaller value than the ID of its sub classes.
Therefore, all base classes must be declared before their sub classes in this enumeration.
\see Interface::IsInstanceOf
\see Interface::AsInstanceOf
\see CastTo
*/
struct InterfaceID
{
Expand Down
1 change: 1 addition & 0 deletions sources/Renderer/DebugLayer/DbgCommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ void DbgCommandBuffer::CopyTextureFromFramebuffer(
LLGL_DBG_SOURCE();
AssertRecording();
AssertPrimaryCommandBuffer();
AssertInsideRenderPass();
ValidateBindTextureFlags(dstTextureDbg, BindFlags::CopyDst);
ValidateTextureRegion(dstTextureDbg, dstRegion);
if (dstRegion.subresource.numArrayLayers > 1)
Expand Down
3 changes: 3 additions & 0 deletions sources/Renderer/Direct3D11/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ endif()
# Direct3D11 renderer files
find_source_files(FilesRendererD3D11 CXX ${PROJECT_SOURCE_DIR})
find_source_files(FilesRendererD3D11Buffer CXX ${PROJECT_SOURCE_DIR}/Buffer)
find_source_files(FilesRendererD3D11Command CXX ${PROJECT_SOURCE_DIR}/Command)
find_source_files(FilesRendererD3D11RenderState CXX ${PROJECT_SOURCE_DIR}/RenderState)
find_source_files(FilesRendererD3D11Shader CXX ${PROJECT_SOURCE_DIR}/Shader)
find_source_files(FilesRendererD3D11Texture CXX ${PROJECT_SOURCE_DIR}/Texture)
Expand All @@ -42,6 +43,7 @@ set(
FilesD3D11
${FilesRendererD3D11}
${FilesRendererD3D11Buffer}
${FilesRendererD3D11Command}
${FilesRendererD3D11Shader}
${FilesRendererD3D11ShaderBuiltin}
${FilesRendererD3D11RenderState}
Expand All @@ -54,6 +56,7 @@ set(

source_group("Direct3D11" FILES ${FilesRendererD3D11})
source_group("Direct3D11\\Buffer" FILES ${FilesRendererD3D11Buffer})
source_group("Direct3D11\\Command" FILES ${FilesRendererD3D11Command})
source_group("Direct3D11\\RenderState" FILES ${FilesRendererD3D11RenderState})
source_group("Direct3D11\\Shader" FILES ${FilesRendererD3D11Shader})
source_group("Direct3D11\\Shader\\Builtin" FILES ${FilesRendererD3D11ShaderBuiltin})
Expand Down
139 changes: 139 additions & 0 deletions sources/Renderer/Direct3D11/Command/D3D11Command.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* D3D11Command.h
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#ifndef LLGL_D3D11_COMMAND_H
#define LLGL_D3D11_COMMAND_H


#include "../Direct3D11.h"
#include <cstdint>


namespace LLGL
{


class Resource;
class ResourceHeap;
class D3D11Buffer;
class D3D11BufferArray;
class D3D11ResourceHeap;
class D3D11PipelineState;

struct D3D11CmdSetVertexBuffer
{
D3D11Buffer* buffer;
};

struct D3D11CmdSetVertexBufferArray
{
D3D11BufferArray* bufferArray;
};

struct D3D11CmdSetIndexBuffer
{
D3D11Buffer* buffer;
DXGI_FORMAT format;
UINT offset;
};

struct D3D11CmdSetResourceHeap
{
D3D11ResourceHeap* resourceHeap;
std::uint32_t descriptorSet;
};

struct D3D11CmdSetResource
{
std::uint32_t descriptor;
Resource* resource;
};

struct D3D11CmdSetPipelineState
{
D3D11PipelineState* pipelineState;
};

struct D3D11CmdSetBlendFactor
{
FLOAT color[4];
};

struct D3D11CmdSetStencilRef
{
UINT stencilRef;
};

struct D3D11CmdSetUniforms
{
std::uint32_t first;
std::uint16_t dataSize;
// char data[dataSize];
};

struct D3D11CmdDraw
{
UINT vertexCount;
UINT startVertexLocation;
};

struct D3D11CmdDrawIndexed
{
UINT indexCount;
UINT startIndexLocation;
INT baseVertexLocation;
};

struct D3D11CmdDrawInstanced
{
UINT vertexCountPerInstance;
UINT instanceCount;
UINT startVertexLocation;
UINT startInstanceLocation;
};

struct D3D11CmdDrawIndexedInstanced
{
UINT indexCountPerInstance;
UINT instanceCount;
UINT startIndexLocation;
INT baseVertexLocation;
UINT startInstanceLocation;
};

struct D3D11CmdDrawInstancedIndirect
{
ID3D11Buffer* bufferForArgs;
UINT alignedByteOffsetForArgs;
UINT numCommands;
UINT stride;
};

//D3D11CmdDrawIndexedInstancedIndirect = D3D11CmdDrawInstancedIndirect

struct D3D11CmdDispatch
{
UINT threadGroupCountX;
UINT threadGroupCountY;
UINT threadGroupCountZ;
};

struct D3D11CmdDispatchIndirect
{
ID3D11Buffer* bufferForArgs;
UINT alignedByteOffsetForArgs;
};


} // /namespace LLGL


#endif



// ================================================================================
25 changes: 25 additions & 0 deletions sources/Renderer/Direct3D11/Command/D3D11CommandBuffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* D3D11CommandBuffer.cpp
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#include "D3D11CommandBuffer.h"


namespace LLGL
{


D3D11CommandBuffer::D3D11CommandBuffer(bool isSecondaryCmdBuffer) :
isSecondaryCmdBuffer_ { isSecondaryCmdBuffer }
{
}


} // /namespace LLGL



// ================================================================================
65 changes: 65 additions & 0 deletions sources/Renderer/Direct3D11/Command/D3D11CommandBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* D3D11CommandBuffer.h
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#ifndef LLGL_D3D11_COMMAND_BUFFER_H
#define LLGL_D3D11_COMMAND_BUFFER_H


#include <LLGL/CommandBuffer.h>
#include "../../DXCommon/ComPtr.h"
#include "../../DXCommon/DXCore.h"
#include "../Direct3D11.h"
#include <dxgi.h>
#include <vector>
#include <cstddef>


namespace LLGL
{


class D3D11Buffer;
class D3D11StateManager;
class D3D11BindingTable;
class D3D11RenderTarget;
class D3D11SwapChain;
class D3D11RenderPass;
class D3D11PipelineState;
class D3D11PipelineLayout;
class D3D11ConstantsCache;
class D3D11RenderTargetHandles;

class D3D11CommandBuffer : public CommandBuffer
{

public:

D3D11CommandBuffer(bool isSecondaryCmdBuffer);

public:

// Returns true if this is a secondary command buffer that can be executed within a primary command buffer.
inline bool IsSecondaryCmdBuffer() const
{
return isSecondaryCmdBuffer_;
}

private:

const bool isSecondaryCmdBuffer_ = false;

};


} // /namespace LLGL


#endif



// ================================================================================
Loading

0 comments on commit f2b153b

Please sign in to comment.