From 05d9bfb4dd6d94d4ef80f582305aa383da295483 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 15 Dec 2019 21:31:46 -0800 Subject: Added testing framework for rendering commands. Added initial draw command test in D3D11 and D3D12 --- .../src/DeviceContextD3D12Impl.cpp | 26 +++++++++++----------- .../src/PipelineStateD3D12Impl.cpp | 8 +++++-- .../GraphicsEngineD3D12/src/TextureD3D12Impl.cpp | 21 ++++++++++------- 3 files changed, 32 insertions(+), 23 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 5e3b9bd1..5b5b10cb 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -1350,31 +1350,31 @@ void DeviceContextD3D12Impl::CopyTextureRegion(ID3D12Resource* pd D3D12_TEXTURE_COPY_LOCATION SrcLocation; SrcLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; SrcLocation.pResource = pd3d12Buffer; - D3D12_PLACED_SUBRESOURCE_FOOTPRINT& Footpring = SrcLocation.PlacedFootprint; - Footpring.Offset = SrcOffset; - Footpring.Footprint.Width = static_cast(DstBox.MaxX - DstBox.MinX); - Footpring.Footprint.Height = static_cast(DstBox.MaxY - DstBox.MinY); - Footpring.Footprint.Depth = static_cast(DstBox.MaxZ - DstBox.MinZ); // Depth cannot be 0 - Footpring.Footprint.Format = TexFormatToDXGI_Format(TexDesc.Format); + D3D12_PLACED_SUBRESOURCE_FOOTPRINT& Footprint = SrcLocation.PlacedFootprint; + Footprint.Offset = SrcOffset; + Footprint.Footprint.Width = static_cast(DstBox.MaxX - DstBox.MinX); + Footprint.Footprint.Height = static_cast(DstBox.MaxY - DstBox.MinY); + Footprint.Footprint.Depth = static_cast(DstBox.MaxZ - DstBox.MinZ); // Depth cannot be 0 + Footprint.Footprint.Format = TexFormatToDXGI_Format(TexDesc.Format); - Footpring.Footprint.RowPitch = static_cast(SrcStride); + Footprint.Footprint.RowPitch = static_cast(SrcStride); #ifdef _DEBUG { const auto& FmtAttribs = GetTextureFormatAttribs(TexDesc.Format); - const Uint32 RowCount = std::max((Footpring.Footprint.Height / FmtAttribs.BlockHeight), 1u); - VERIFY(BufferSize >= Footpring.Footprint.RowPitch * RowCount * Footpring.Footprint.Depth, "Buffer is not large enough"); - VERIFY(Footpring.Footprint.Depth == 1 || static_cast(SrcDepthStride) == Footpring.Footprint.RowPitch * RowCount, "Depth stride must be equal to the size of 2D plane"); + const Uint32 RowCount = std::max((Footprint.Footprint.Height / FmtAttribs.BlockHeight), 1u); + VERIFY(BufferSize >= Footprint.Footprint.RowPitch * RowCount * Footprint.Footprint.Depth, "Buffer is not large enough"); + VERIFY(Footprint.Footprint.Depth == 1 || static_cast(SrcDepthStride) == Footprint.Footprint.RowPitch * RowCount, "Depth stride must be equal to the size of 2D plane"); } #endif D3D12_BOX D3D12SrcBox; D3D12SrcBox.left = 0; - D3D12SrcBox.right = Footpring.Footprint.Width; + D3D12SrcBox.right = Footprint.Footprint.Width; D3D12SrcBox.top = 0; - D3D12SrcBox.bottom = Footpring.Footprint.Height; + D3D12SrcBox.bottom = Footprint.Footprint.Height; D3D12SrcBox.front = 0; - D3D12SrcBox.back = Footpring.Footprint.Depth; + D3D12SrcBox.back = Footprint.Footprint.Depth; CmdCtx.GetCommandList()->CopyTextureRegion(&DstLocation, static_cast(DstBox.MinX), static_cast(DstBox.MinY), diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index be8e06b9..ef997858 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -282,8 +282,12 @@ PipelineStateD3D12Impl ::PipelineStateD3D12Impl(IReferenceCounters* pRefCou std::array ShaderVarMgrDataSizes = {}; for (Uint32 s = 0; s < m_NumShaders; ++s) { - std::array AllowedVarTypes = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC}; - Uint32 NumVariablesUnused = 0; + std::array AllowedVarTypes = + { + SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, + SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC // + }; + Uint32 NumVariablesUnused = 0; ShaderVarMgrDataSizes[s] = ShaderVariableManagerD3D12::GetRequiredMemorySize(m_pShaderResourceLayouts[s], AllowedVarTypes.data(), static_cast(AllowedVarTypes.size()), NumVariablesUnused); } diff --git a/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp index 433608fc..b5159a3f 100644 --- a/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp @@ -147,7 +147,7 @@ TextureD3D12Impl ::TextureD3D12Impl(IReferenceCounters* pRefCounters, auto* pd3d12Device = pRenderDeviceD3D12->GetD3D12Device(); if (m_Desc.Usage == USAGE_STATIC || m_Desc.Usage == USAGE_DEFAULT || m_Desc.Usage == USAGE_DYNAMIC) { - D3D12_CLEAR_VALUE ClearValue; + D3D12_CLEAR_VALUE ClearValue = {}; D3D12_CLEAR_VALUE* pClearValue = nullptr; if (Desc.Flags & (D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)) { @@ -172,7 +172,8 @@ TextureD3D12Impl ::TextureD3D12Impl(IReferenceCounters* pRefCounters, pClearValue = &ClearValue; } - D3D12_HEAP_PROPERTIES HeapProps; + D3D12_HEAP_PROPERTIES HeapProps = {}; + HeapProps.Type = D3D12_HEAP_TYPE_DEFAULT; HeapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN; HeapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN; @@ -183,8 +184,9 @@ TextureD3D12Impl ::TextureD3D12Impl(IReferenceCounters* pRefCounters, auto InitialState = bInitializeTexture ? RESOURCE_STATE_COPY_DEST : RESOURCE_STATE_UNDEFINED; SetState(InitialState); auto D3D12State = ResourceStateFlagsToD3D12ResourceStates(InitialState); - auto hr = pd3d12Device->CreateCommittedResource(&HeapProps, D3D12_HEAP_FLAG_NONE, - &Desc, D3D12State, pClearValue, __uuidof(m_pd3d12Resource), reinterpret_cast(static_cast(&m_pd3d12Resource))); + auto hr = + pd3d12Device->CreateCommittedResource(&HeapProps, D3D12_HEAP_FLAG_NONE, &Desc, D3D12State, pClearValue, __uuidof(m_pd3d12Resource), + reinterpret_cast(static_cast(&m_pd3d12Resource))); if (FAILED(hr)) LOG_ERROR_AND_THROW("Failed to create D3D12 texture"); @@ -200,14 +202,16 @@ TextureD3D12Impl ::TextureD3D12Impl(IReferenceCounters* pRefCounters, UINT64 uploadBufferSize = 0; pd3d12Device->GetCopyableFootprints(&Desc, 0, pInitData->NumSubresources, 0, nullptr, nullptr, nullptr, &uploadBufferSize); - D3D12_HEAP_PROPERTIES UploadHeapProps; + D3D12_HEAP_PROPERTIES UploadHeapProps = {}; + UploadHeapProps.Type = D3D12_HEAP_TYPE_UPLOAD; UploadHeapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN; UploadHeapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN; UploadHeapProps.CreationNodeMask = 1; UploadHeapProps.VisibleNodeMask = 1; - D3D12_RESOURCE_DESC BufferDesc; + D3D12_RESOURCE_DESC BufferDesc = {}; + BufferDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; BufferDesc.Alignment = 0; BufferDesc.Width = uploadBufferSize; @@ -273,7 +277,7 @@ TextureD3D12Impl ::TextureD3D12Impl(IReferenceCounters* pRefCounters, else if (m_Desc.Usage == USAGE_STAGING) { // Create staging buffer - D3D12_HEAP_PROPERTIES StaginHeapProps; + D3D12_HEAP_PROPERTIES StaginHeapProps = {}; DEV_CHECK_ERR((m_Desc.CPUAccessFlags & (CPU_ACCESS_READ | CPU_ACCESS_WRITE)) == CPU_ACCESS_READ || (m_Desc.CPUAccessFlags & (CPU_ACCESS_READ | CPU_ACCESS_WRITE)) == CPU_ACCESS_WRITE, "Exactly one of CPU_ACCESS_READ or CPU_ACCESS_WRITE flags must be specified"); @@ -306,7 +310,8 @@ TextureD3D12Impl ::TextureD3D12Impl(IReferenceCounters* pRefCounters, pd3d12Device->GetCopyableFootprints(&Desc, 0, NumSubresources, 0, m_StagingFootprints, nullptr, nullptr, &stagingBufferSize); m_StagingFootprints[NumSubresources] = D3D12_PLACED_SUBRESOURCE_FOOTPRINT{stagingBufferSize}; - D3D12_RESOURCE_DESC BufferDesc; + D3D12_RESOURCE_DESC BufferDesc = {}; + BufferDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; BufferDesc.Alignment = 0; BufferDesc.Width = stagingBufferSize; -- cgit v1.2.3