Skip to content

Commit

Permalink
Merge pull request #2851 from erikaharrison-adsk/feature-hgi-vulkan-u…
Browse files Browse the repository at this point in the history
…nit-test

Autodesk: Feature hgi vulkan unit test

(Internal change: 2311664)
(Internal change: 2311695)
  • Loading branch information
pixar-oss committed Jan 22, 2024
2 parents 41ef4f3 + 407b851 commit ab7c953
Show file tree
Hide file tree
Showing 8 changed files with 817 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pxr/imaging/hgi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pxr_library(hgi
gf
plug
tf
hio

PUBLIC_CLASSES
attachmentDesc
Expand All @@ -32,10 +33,35 @@ pxr_library(hgi
texture
tokens
types
unitTestHelper

PUBLIC_HEADERS
api.h
blitCmdsOps.h
enums.h
handle.h
)

if (${PXR_HEADLESS_TEST_MODE})
message(STATUS "Skipping ${PXR_PACKAGE} tests because PXR_HEADLESS_TEST_MODE is ON")
return()
endif()

if (APPLE)
message(STATUS "Skipping ${PXR_PACKAGE} tests because they are currently unsupported on macOS")
return()
endif()

if (WIN32)
message(STATUS "Skipping ${PXR_PACKAGE} tests because they are currently unsupported on Windows")
return()
endif()

pxr_build_test(testHgiCommand
LIBRARIES
hgi
garch
tf
CPPFILES
testenv/testHgiCommand.cpp
)
132 changes: 132 additions & 0 deletions pxr/imaging/hgi/testenv/testHgiCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
//
// Copyright 2023 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//

#include "pxr/imaging/hgi/unitTestHelper.h"

#include "pxr/imaging/garch/glApi.h"
#include "pxr/imaging/garch/glDebugWindow.h"

#include "pxr/base/tf/errorMark.h"
#include "pxr/base/tf/envSetting.h"

#include <iostream>

PXR_NAMESPACE_USING_DIRECTIVE

static bool
HgiBasicTest()
{
HgiInitializationTestDriver driver;

if (driver.GetHgi() == nullptr) {
return false;
}

return true;
}

static bool
HgiPipelineCreateTest()
{
HgiPipelineCreationTestDriver driver;

if (!driver.CreateTestPipeline()) {
return false;
}

return true;
}

static bool
HgiExecuteGfxCmdBfrTest(std::string fileName)
{
HgiGfxCmdBfrExecutionTestDriver driver;

if (!driver.CreateTestPipeline()) {
return false;
}

if (!driver.ExecuteTestGfxCmdBfr()) {
return false;
}

if (!fileName.empty()) {
if (!driver.WriteToFile(fileName)) {
return false;
}
}

return true;
}

class HgiUnitTestWindow : public GarchGLDebugWindow {
public:
HgiUnitTestWindow(const char *title, int width, int height)
: GarchGLDebugWindow(title, width, height)
{}

~HgiUnitTestWindow() {}

void OnInitializeGL() override {
GarchGLApiLoad();
}
};

/// Entrypoint to this unit test
/// Valid command line options for this unit test are :
/// --write <filename> // writes render output to disk
int
main(int argc, char **argv)
{
std::string fileName;
for (int i = 0; i < argc; ++i) {
std::string arg(argv[i]);
if (arg == "--write") {
if (i+1 < argc) {
fileName = std::string(argv[++i]);
}
break;
}
}

TfErrorMark mark;

// Setup OpenGL context, needed for HgiGL version of test.
HgiUnitTestWindow unitTestWindow("hgi", 256, 256);
unitTestWindow.Init();

bool success = HgiBasicTest();
success = success && HgiPipelineCreateTest();
success = success && HgiExecuteGfxCmdBfrTest(fileName);

TF_VERIFY(mark.IsClean());

if (success && mark.IsClean()) {
std::cout << "OK" << std::endl;
return EXIT_SUCCESS;
} else {
std::cout << "FAILED" << std::endl;
return EXIT_FAILURE;
}
}
Loading

0 comments on commit ab7c953

Please sign in to comment.