bf0d3996a9
* dx12 async compute * compute queue can't do PIXEL_SHADER_RESOURCE barrier, so adding new resource states for SHADER_RESOURCE_COMPUTE * rtshadow layout fix * acceleration structure build moved earlier into the frame, and synced implicitly * vulkan async compute * temp button to switch between async on/off * documentation update * vulkan async compute on separate queue family * vulkan: enable concurrent sharing mode for resources if queue families differ * version bump, revert async compute debug button
160 lines
8.1 KiB
C++
160 lines
8.1 KiB
C++
#pragma once
|
|
#include "CommonInclude.h"
|
|
|
|
#if __has_include("d3d11_3.h")
|
|
#define WICKEDENGINE_BUILD_DX11
|
|
#endif // HAS DX11
|
|
|
|
#ifdef WICKEDENGINE_BUILD_DX11
|
|
#include "wiGraphicsDevice.h"
|
|
|
|
#include <d3d11_3.h>
|
|
#include <DXGI1_3.h>
|
|
#include <wrl/client.h> // ComPtr
|
|
|
|
#include <atomic>
|
|
|
|
namespace wiGraphics
|
|
{
|
|
|
|
class GraphicsDevice_DX11 : public GraphicsDevice
|
|
{
|
|
protected:
|
|
D3D_DRIVER_TYPE driverType;
|
|
D3D_FEATURE_LEVEL featureLevel;
|
|
Microsoft::WRL::ComPtr<IDXGIFactory2> DXGIFactory;
|
|
Microsoft::WRL::ComPtr<ID3D11Device> device;
|
|
Microsoft::WRL::ComPtr<ID3D11DeviceContext> immediateContext;
|
|
Microsoft::WRL::ComPtr<ID3D11DeviceContext> deviceContexts[COMMANDLIST_COUNT];
|
|
Microsoft::WRL::ComPtr<ID3D11CommandList> commandLists[COMMANDLIST_COUNT];
|
|
Microsoft::WRL::ComPtr<ID3DUserDefinedAnnotation> userDefinedAnnotations[COMMANDLIST_COUNT];
|
|
|
|
Microsoft::WRL::ComPtr<ID3D11Query> disjointQueries[BUFFERCOUNT + 3];
|
|
|
|
uint32_t stencilRef[COMMANDLIST_COUNT];
|
|
XMFLOAT4 blendFactor[COMMANDLIST_COUNT];
|
|
|
|
ID3D11VertexShader* prev_vs[COMMANDLIST_COUNT] = {};
|
|
ID3D11PixelShader* prev_ps[COMMANDLIST_COUNT] = {};
|
|
ID3D11HullShader* prev_hs[COMMANDLIST_COUNT] = {};
|
|
ID3D11DomainShader* prev_ds[COMMANDLIST_COUNT] = {};
|
|
ID3D11GeometryShader* prev_gs[COMMANDLIST_COUNT] = {};
|
|
ID3D11ComputeShader* prev_cs[COMMANDLIST_COUNT] = {};
|
|
XMFLOAT4 prev_blendfactor[COMMANDLIST_COUNT] = {};
|
|
uint32_t prev_samplemask[COMMANDLIST_COUNT] = {};
|
|
const BlendState* prev_bs[COMMANDLIST_COUNT] = {};
|
|
const RasterizerState* prev_rs[COMMANDLIST_COUNT] = {};
|
|
uint32_t prev_stencilRef[COMMANDLIST_COUNT] = {};
|
|
const DepthStencilState* prev_dss[COMMANDLIST_COUNT] = {};
|
|
const InputLayout* prev_il[COMMANDLIST_COUNT] = {};
|
|
PRIMITIVETOPOLOGY prev_pt[COMMANDLIST_COUNT] = {};
|
|
std::vector<const SwapChain*> swapchains[COMMANDLIST_COUNT];
|
|
|
|
const PipelineState* active_pso[COMMANDLIST_COUNT] = {};
|
|
bool dirty_pso[COMMANDLIST_COUNT] = {};
|
|
void pso_validate(CommandList cmd);
|
|
|
|
const RenderPass* active_renderpass[COMMANDLIST_COUNT] = {};
|
|
RenderPass dummyrenderpass;
|
|
|
|
ID3D11UnorderedAccessView* raster_uavs[COMMANDLIST_COUNT][8] = {};
|
|
uint8_t raster_uavs_slot[COMMANDLIST_COUNT] = {};
|
|
uint8_t raster_uavs_count[COMMANDLIST_COUNT] = {};
|
|
void validate_raster_uavs(CommandList cmd);
|
|
|
|
struct GPUAllocator
|
|
{
|
|
GPUBuffer buffer;
|
|
size_t byteOffset = 0;
|
|
uint64_t residentFrame = 0;
|
|
bool dirty = false;
|
|
} frame_allocators[COMMANDLIST_COUNT];
|
|
void commit_allocations(CommandList cmd);
|
|
|
|
void CreateBackBufferResources();
|
|
|
|
std::atomic<CommandList> cmd_count{ 0 };
|
|
|
|
std::vector<StaticSampler> common_samplers;
|
|
|
|
struct EmptyResourceHandle {}; // only care about control-block
|
|
std::shared_ptr<EmptyResourceHandle> emptyresource;
|
|
|
|
public:
|
|
GraphicsDevice_DX11(bool debuglayer = false);
|
|
|
|
bool CreateSwapChain(const SwapChainDesc* pDesc, wiPlatform::window_type window, SwapChain* swapChain) const override;
|
|
bool CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) const override;
|
|
bool CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) const override;
|
|
bool CreateShader(SHADERSTAGE stage, const void *pShaderBytecode, size_t BytecodeLength, Shader *pShader) const override;
|
|
bool CreateSampler(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) const override;
|
|
bool CreateQueryHeap(const GPUQueryHeapDesc *pDesc, GPUQueryHeap *pQueryHeap) const override;
|
|
bool CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) const override;
|
|
bool CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) const override;
|
|
|
|
int CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount) const override;
|
|
int CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size = ~0) const override;
|
|
|
|
void Map(const GPUResource* resource, Mapping* mapping) const override;
|
|
void Unmap(const GPUResource* resource) const override;
|
|
void QueryRead(const GPUQueryHeap* resource, uint32_t index, uint32_t count, uint64_t* results) const override;
|
|
|
|
void SetCommonSampler(const StaticSampler* sam) override;
|
|
|
|
void SetName(GPUResource* pResource, const char* name) override;
|
|
|
|
void WaitForGPU() const override;
|
|
|
|
CommandList BeginCommandList(QUEUE_TYPE queue = QUEUE_GRAPHICS) override;
|
|
void SubmitCommandLists() override;
|
|
|
|
SHADERFORMAT GetShaderFormat() const override { return SHADERFORMAT_HLSL5; }
|
|
|
|
Texture GetBackBuffer(const SwapChain* swapchain) const override;
|
|
|
|
///////////////Thread-sensitive////////////////////////
|
|
|
|
void RenderPassBegin(const SwapChain* swapchain, CommandList cmd) override;
|
|
void RenderPassBegin(const RenderPass* renderpass, CommandList cmd) override;
|
|
void RenderPassEnd(CommandList cmd) override;
|
|
void BindScissorRects(uint32_t numRects, const Rect* rects, CommandList cmd) override;
|
|
void BindViewports(uint32_t NumViewports, const Viewport* pViewports, CommandList cmd) override;
|
|
void BindResource(SHADERSTAGE stage, const GPUResource* resource, uint32_t slot, CommandList cmd, int subresource = -1) override;
|
|
void BindResources(SHADERSTAGE stage, const GPUResource *const* resources, uint32_t slot, uint32_t count, CommandList cmd) override;
|
|
void BindUAV(SHADERSTAGE stage, const GPUResource* resource, uint32_t slot, CommandList cmd, int subresource = -1) override;
|
|
void BindUAVs(SHADERSTAGE stage, const GPUResource *const* resources, uint32_t slot, uint32_t count, CommandList cmd) override;
|
|
void UnbindResources(uint32_t slot, uint32_t num, CommandList cmd) override;
|
|
void UnbindUAVs(uint32_t slot, uint32_t num, CommandList cmd) override;
|
|
void BindSampler(SHADERSTAGE stage, const Sampler* sampler, uint32_t slot, CommandList cmd) override;
|
|
void BindConstantBuffer(SHADERSTAGE stage, const GPUBuffer* buffer, uint32_t slot, CommandList cmd) override;
|
|
void BindVertexBuffers(const GPUBuffer *const* vertexBuffers, uint32_t slot, uint32_t count, const uint32_t* strides, const uint32_t* offsets, CommandList cmd) override;
|
|
void BindIndexBuffer(const GPUBuffer* indexBuffer, const INDEXBUFFER_FORMAT format, uint32_t offset, CommandList cmd) override;
|
|
void BindStencilRef(uint32_t value, CommandList cmd) override;
|
|
void BindBlendFactor(float r, float g, float b, float a, CommandList cmd) override;
|
|
void BindPipelineState(const PipelineState* pso, CommandList cmd) override;
|
|
void BindComputeShader(const Shader* cs, CommandList cmd) override;
|
|
void Draw(uint32_t vertexCount, uint32_t startVertexLocation, CommandList cmd) override;
|
|
void DrawIndexed(uint32_t indexCount, uint32_t startIndexLocation, uint32_t baseVertexLocation, CommandList cmd) override;
|
|
void DrawInstanced(uint32_t vertexCount, uint32_t instanceCount, uint32_t startVertexLocation, uint32_t startInstanceLocation, CommandList cmd) override;
|
|
void DrawIndexedInstanced(uint32_t indexCount, uint32_t instanceCount, uint32_t startIndexLocation, uint32_t baseVertexLocation, uint32_t startInstanceLocation, CommandList cmd) override;
|
|
void DrawInstancedIndirect(const GPUBuffer* args, uint32_t args_offset, CommandList cmd) override;
|
|
void DrawIndexedInstancedIndirect(const GPUBuffer* args, uint32_t args_offset, CommandList cmd) override;
|
|
void Dispatch(uint32_t threadGroupCountX, uint32_t threadGroupCountY, uint32_t threadGroupCountZ, CommandList cmd) override;
|
|
void DispatchIndirect(const GPUBuffer* args, uint32_t args_offset, CommandList cmd) override;
|
|
void CopyResource(const GPUResource* pDst, const GPUResource* pSrc, CommandList cmd) override;
|
|
void UpdateBuffer(const GPUBuffer* buffer, const void* data, CommandList cmd, int dataSize = -1) override;
|
|
void QueryBegin(const GPUQueryHeap* heap, uint32_t index, CommandList cmd) override;
|
|
void QueryEnd(const GPUQueryHeap* heap, uint32_t index, CommandList cmd) override;
|
|
void Barrier(const GPUBarrier* barriers, uint32_t numBarriers, CommandList cmd) override {}
|
|
|
|
GPUAllocation AllocateGPU(size_t dataSize, CommandList cmd) override;
|
|
|
|
void EventBegin(const char* name, CommandList cmd) override;
|
|
void EventEnd(CommandList cmd) override;
|
|
void SetMarker(const char* name, CommandList cmd) override;
|
|
};
|
|
|
|
}
|
|
|
|
#endif // WICKEDENGINE_BUILD_DX11
|