Skip to content

Commit

Permalink
Add unit-tests for RHI ViewState
Browse files Browse the repository at this point in the history
  • Loading branch information
egorodet committed Jul 15, 2023
1 parent 4299e05 commit e36e7d2
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 4 deletions.
1 change: 1 addition & 0 deletions Tests/Graphics/RHI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_executable(${TARGET}
ProgramBindingsTest.cpp
ComputeContextTest.cpp
ComputeStateTest.cpp
ViewStateTest.cpp
CommandQueueTest.cpp
FenceTest.cpp
TransferCommandListTest.cpp
Expand Down
8 changes: 4 additions & 4 deletions Tests/Graphics/RHI/ComputeStateTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
*******************************************************************************
FILE: Tests/Graphics/RHI/ComputeStateTest.cpp
Unit-tests of the RHI ComputeContext
Unit-tests of the RHI ComputeState
******************************************************************************/

Expand All @@ -40,15 +40,15 @@ static tf::Executor g_parallel_executor;

TEST_CASE("RHI Compute State Functions", "[rhi][compute][state]")
{
const Rhi::ComputeContext compute_context = Rhi::ComputeContext(GetTestDevice(), g_parallel_executor, {});
const Rhi::ComputeStateSettingsImpl& compute_state_settings{
const Rhi::ComputeContext compute_context(GetTestDevice(), g_parallel_executor, {});
const Rhi::ComputeStateSettingsImpl compute_state_settings{
compute_context.CreateProgram({
{ { Rhi::ShaderType::Compute, { Data::ShaderProvider::Get(), { "Shader", "Main" } } } },
}),
Rhi::ThreadGroupSize(16, 16, 1)
};

SECTION("Context Construction")
SECTION("Compute State Construction")
{
Rhi::ComputeState compute_state;
REQUIRE_NOTHROW(compute_state = compute_context.CreateComputeState(compute_state_settings));
Expand Down
87 changes: 87 additions & 0 deletions Tests/Graphics/RHI/ViewStateTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/******************************************************************************
Copyright 2023 Evgeny Gorodetskiy
Licensed under the Apache License, Version 2.0 (the "License"),
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*******************************************************************************
FILE: Tests/Graphics/RHI/ViewStateTest.cpp
Unit-tests of the RHI ViewState
******************************************************************************/

#include <Methane/Graphics/RHI/ViewState.h>

#include <memory>
#include <catch2/catch_test_macros.hpp>

using namespace Methane;
using namespace Methane::Graphics;

TEST_CASE("RHI View State Functions", "[rhi][view][state]")
{
const Rhi::ViewSettings view_state_settings{
{
Viewport(1.2, 2.3, 3.4, 5.1, 6.2, 7.3),
Viewport(2.4, 3.5, 4.6, 6.3, 7.4, 8.5),
Viewport(3.6, 4.7, 5.8, 7.5, 8.6, 9.7)
},
{
ScissorRect(0U, 1U, 2U, 3U),
ScissorRect(1U, 2U, 3U, 4U),
ScissorRect(2U, 3U, 4U, 5U)
}
};

SECTION("Context Construction")
{
Rhi::ViewState view_state;
REQUIRE_NOTHROW(view_state = Rhi::ViewState(view_state_settings));
REQUIRE(view_state.IsInitialized());
CHECK(view_state.GetInterfacePtr());
CHECK(view_state.GetSettings().viewports == view_state_settings.viewports);
CHECK(view_state.GetSettings().scissor_rects == view_state_settings.scissor_rects);
}

Rhi::ViewState view_state(view_state_settings);
const Rhi::ViewSettings new_settings{
{
Viewport(9.1, 8.2, 7.3, 6.2, 5.1, 4.0)
},
{
ScissorRect(5U, 6U, 8U, 7U)
}
};

SECTION("Reset with Settings")
{
REQUIRE_NOTHROW(view_state.Reset(new_settings));
REQUIRE(view_state.GetSettings().viewports == new_settings.viewports);
REQUIRE(view_state.GetSettings().scissor_rects == new_settings.scissor_rects);
}

SECTION("Set Viewports")
{
REQUIRE_NOTHROW(view_state.SetViewports(new_settings.viewports));
REQUIRE(view_state.GetSettings().viewports == new_settings.viewports);
REQUIRE(view_state.GetSettings().scissor_rects == view_state_settings.scissor_rects);
}

SECTION("Set Scissor Rects")
{
REQUIRE_NOTHROW(view_state.SetScissorRects(new_settings.scissor_rects));
REQUIRE(view_state.GetSettings().viewports == view_state_settings.viewports);
REQUIRE(view_state.GetSettings().scissor_rects == new_settings.scissor_rects);
}
}

9 comments on commit e36e7d2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Win32_DX_Release Test Results

  • ✅ 3129 tests passed
  • ❌ 0 tests failed
  • ⚠️ 0 tests skipped
  • ⏱️ 962 ms. run duration

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Win64_VK_Release Test Results

  • ✅ 3129 tests passed
  • ❌ 0 tests failed
  • ⚠️ 0 tests skipped
  • ⏱️ 1035 ms. run duration

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ubuntu_VK_Release Test Results

  • ✅ 3130 tests passed
  • ❌ 0 tests failed
  • ⚠️ 0 tests skipped
  • ⏱️ 13346 ms. run duration

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Win32_VK_Release Test Results

  • ✅ 3129 tests passed
  • ❌ 0 tests failed
  • ⚠️ 0 tests skipped
  • ⏱️ 1000 ms. run duration

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MacOS_MTL_Release Test Results

  • ✅ 3129 tests passed
  • ❌ 0 tests failed
  • ⚠️ 0 tests skipped
  • ⏱️ 1031 ms. run duration

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Win64_DX_Release Test Results

  • ✅ 3129 tests passed
  • ❌ 0 tests failed
  • ⚠️ 0 tests skipped
  • ⏱️ 1028 ms. run duration

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ubuntu_VK_SonarScan Tests Code Coverage

Code Coverage

Package Line Rate Branch Rate Health
Default 39% 100%
Summary 39% (7760 / 20115) 100% (0 / 0)

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Win64_DX_SonarScan Tests Code Coverage

Code Coverage

Package Line Rate Branch Rate Health
D:\a\MethaneKit\MethaneKit\Build\Output\Ninja-Win-DX-Scan\Install\Tests\MethaneDataEventsTest.exe 95% 100%
D:\a\MethaneKit\MethaneKit\Build\Output\Ninja-Win-DX-Scan\Install\Tests\MethaneDataRangeSetTest.exe 91% 100%
D:\a\MethaneKit\MethaneKit\Build\Output\Ninja-Win-DX-Scan\Install\Tests\MethaneDataTypesTest.exe 98% 100%
D:\a\MethaneKit\MethaneKit\Build\Output\Ninja-Win-DX-Scan\Install\Tests\MethaneGraphicsCameraTest.exe 61% 100%
D:\a\MethaneKit\MethaneKit\Build\Output\Ninja-Win-DX-Scan\Install\Tests\MethaneGraphicsRhiTest.exe 44% 100%
D:\a\MethaneKit\MethaneKit\Build\Output\Ninja-Win-DX-Scan\Install\Tests\MethaneGraphicsTypesTest.exe 98% 100%
D:\a\MethaneKit\MethaneKit\Build\Output\Ninja-Win-DX-Scan\Install\Tests\MethanePlatformInputTest.exe 43% 100%
D:\a\MethaneKit\MethaneKit\Build\Output\Ninja-Win-DX-Scan\Install\Tests\MethaneUserInterfaceTypesTest.exe 9% 100%
Summary 34% (4573 / 13283) 100% (0 / 0)

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MacOS_MTL_SonarScan Tests Code Coverage

Code Coverage

Package Line Rate Branch Rate Health
Default 51% 21%
Summary 51% (12767 / 25014) 21% (3621 / 17188)

Please sign in to comment.