From a5a45152bf3da9d1f9bc32fcd175b2bb4aac109d Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 9 Oct 2023 21:46:28 -0700 Subject: [PATCH] Draw command test: added separate position/color buffers test --- .../src/DrawCommandTest.cpp | 78 ++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/Tests/DiligentCoreAPITest/src/DrawCommandTest.cpp b/Tests/DiligentCoreAPITest/src/DrawCommandTest.cpp index 8886091a70..17ac986689 100644 --- a/Tests/DiligentCoreAPITest/src/DrawCommandTest.cpp +++ b/Tests/DiligentCoreAPITest/src/DrawCommandTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Diligent Graphics LLC + * Copyright 2019-2023 Diligent Graphics LLC * Copyright 2015-2019 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -581,6 +581,14 @@ class DrawCommandTest : public ::testing::Test pDevice->CreateGraphicsPipelineState(PSOCreateInfo, &sm_pDraw_2xStride_PSO); ASSERT_NE(sm_pDraw_2xStride_PSO, nullptr); + PSODesc.Name = "Draw command test - Buffer 2"; + + Elems[0] = {0, 1, 4, VT_FLOAT32}; + Elems[1] = {1, 3, 3, VT_FLOAT32}; + pDevice->CreateGraphicsPipelineState(PSOCreateInfo, &sm_pDraw_2VBs_PSO); + ASSERT_NE(sm_pDraw_2VBs_PSO, nullptr); + + PSODesc.Name = "Instanced draw command test"; // clang-format off LayoutElement InstancedElems[] = @@ -604,6 +612,7 @@ class DrawCommandTest : public ::testing::Test sm_pDrawProceduralPSO.Release(); sm_pDrawPSO.Release(); sm_pDraw_2xStride_PSO.Release(); + sm_pDraw_2VBs_PSO.Release(); sm_pDrawInstancedPSO.Release(); sm_pDrawStripPSO.Release(); @@ -730,6 +739,7 @@ class DrawCommandTest : public ::testing::Test static RefCntAutoPtr sm_pDrawProceduralPSO; static RefCntAutoPtr sm_pDrawPSO; static RefCntAutoPtr sm_pDraw_2xStride_PSO; + static RefCntAutoPtr sm_pDraw_2VBs_PSO; static RefCntAutoPtr sm_pDrawInstancedPSO; static RefCntAutoPtr sm_pDrawStripPSO; static FastRandFloat sm_Rnd; @@ -738,6 +748,7 @@ class DrawCommandTest : public ::testing::Test RefCntAutoPtr DrawCommandTest::sm_pDrawProceduralPSO; RefCntAutoPtr DrawCommandTest::sm_pDrawPSO; RefCntAutoPtr DrawCommandTest::sm_pDraw_2xStride_PSO; +RefCntAutoPtr DrawCommandTest::sm_pDraw_2VBs_PSO; RefCntAutoPtr DrawCommandTest::sm_pDrawInstancedPSO; RefCntAutoPtr DrawCommandTest::sm_pDrawStripPSO; FastRandFloat DrawCommandTest::sm_Rnd{0, 0.f, 1.f}; @@ -897,6 +908,36 @@ TEST_F(DrawCommandTest, Draw_StartVertex_VBOffset_2xStride) Present(); } +TEST_F(DrawCommandTest, Draw_2VBs) +{ + auto* pEnv = GPUTestingEnvironment::GetInstance(); + auto* pContext = pEnv->GetDeviceContext(); + + SetRenderTargets(sm_pDraw_2VBs_PSO); + + // clang-format off + const float4 Positions[] = + { + Pos[0], Pos[1], Pos[2], + Pos[3], Pos[4], Pos[5] + }; + const float3 Colors[] = + { + Color[0], Color[1], Color[2], + Color[0], Color[1], Color[2], + }; + // clang-format on + + auto pPosVB = CreateVertexBuffer(Positions, sizeof(Positions)); + auto pColVB = CreateVertexBuffer(Colors, sizeof(Colors)); + IBuffer* pVBs[] = {nullptr, pPosVB, nullptr, pColVB}; + pContext->SetVertexBuffers(0, _countof(pVBs), pVBs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION, SET_VERTEX_BUFFERS_FLAG_RESET); + + DrawAttribs drawAttrs{6, DRAW_FLAG_VERIFY_ALL}; + pContext->Draw(drawAttrs); + + Present(); +} // Indexed draw calls (glDrawElements/DrawIndexed) @@ -1029,6 +1070,41 @@ TEST_F(DrawCommandTest, DrawIndexed_IBOffset_BaseVertex) Present(); } +TEST_F(DrawCommandTest, Draw_2VBs_Indexed) +{ + auto* pEnv = GPUTestingEnvironment::GetInstance(); + auto* pContext = pEnv->GetDeviceContext(); + + SetRenderTargets(sm_pDraw_2VBs_PSO); + + // clang-format off + const float4 Positions[] = + { + {}, Pos[0], {}, Pos[1], {}, Pos[2], + {}, {}, Pos[3], Pos[4], {}, {}, Pos[5] + }; + const float3 Colors[] = + { + {}, Color[0], {}, Color[1], {}, Color[2], + {}, {}, Color[0], Color[1], {}, {}, Color[2], + }; + const Uint32 Indices[] = {1,3,5, 8,9,12}; + // clang-format on + + auto pPosVB = CreateVertexBuffer(Positions, sizeof(Positions)); + auto pColVB = CreateVertexBuffer(Colors, sizeof(Colors)); + IBuffer* pVBs[] = {nullptr, pPosVB, nullptr, pColVB}; + pContext->SetVertexBuffers(0, _countof(pVBs), pVBs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION, SET_VERTEX_BUFFERS_FLAG_RESET); + + auto pIB = CreateIndexBuffer(Indices, _countof(Indices)); + pContext->SetIndexBuffer(pIB, 0, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + + DrawIndexedAttribs drawAttrs{6, VT_UINT32, DRAW_FLAG_VERIFY_ALL}; + pContext->DrawIndexed(drawAttrs); + + Present(); +} + // Instanced non-indexed draw calls (glDrawArraysInstanced/DrawInstanced)