From 73e09677dc2a78da3d5dbcfc8039532c2327ef2c Mon Sep 17 00:00:00 2001 From: Mirza Halilcevic Date: Wed, 28 Jun 2023 06:21:03 +0000 Subject: [PATCH] EXSWHTEC-136 - Implement tests for hipGraphicsGLRegisterImage (#64) Change-Id: Ida0cdfcf2b4fb7da397fdbc3881f3358935d9364 [ROCm/hip-tests commit: 00964ba66ce0ccdebbc31f9c148e6ec8a8c82858] --- .../catch/unit/gl_interop/CMakeLists.txt | 1 + .../gl_interop/hipGraphicsGLRegisterImage.cc | 101 ++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 projects/hip-tests/catch/unit/gl_interop/hipGraphicsGLRegisterImage.cc diff --git a/projects/hip-tests/catch/unit/gl_interop/CMakeLists.txt b/projects/hip-tests/catch/unit/gl_interop/CMakeLists.txt index 8faa7e9c2d..5dae1160f4 100644 --- a/projects/hip-tests/catch/unit/gl_interop/CMakeLists.txt +++ b/projects/hip-tests/catch/unit/gl_interop/CMakeLists.txt @@ -1,6 +1,7 @@ set(TEST_SRC hipGLGetDevices.cc hipGraphicsGLRegisterBuffer.cc + hipGraphicsGLRegisterImage.cc ) hip_add_exe_to_target(NAME GLInteropTest diff --git a/projects/hip-tests/catch/unit/gl_interop/hipGraphicsGLRegisterImage.cc b/projects/hip-tests/catch/unit/gl_interop/hipGraphicsGLRegisterImage.cc new file mode 100644 index 0000000000..f27498ab5f --- /dev/null +++ b/projects/hip-tests/catch/unit/gl_interop/hipGraphicsGLRegisterImage.cc @@ -0,0 +1,101 @@ +/* +Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include +#include + +#include "gl_interop_common.hh" + +namespace { +constexpr std::array kFlags{ + hipGraphicsRegisterFlagsNone, hipGraphicsRegisterFlagsReadOnly, + hipGraphicsRegisterFlagsWriteDiscard, hipGraphicsRegisterFlagsSurfaceLoadStore, + hipGraphicsRegisterFlagsTextureGather}; +} // anonymous namespace + +TEST_CASE("Unit_hipGraphicsGLRegisterImage_Positive_Basic") { + GLContextScopeGuard gl_context; + + const auto flags = GENERATE(from_range(begin(kFlags), end(kFlags))); + + GLImageObject tex; + + hipGraphicsResource* tex_resource; + + HIP_CHECK(hipGraphicsGLRegisterImage(&tex_resource, tex, GL_TEXTURE_2D, flags)); + + HIP_CHECK(hipGraphicsUnregisterResource(tex_resource)); +} + +TEST_CASE("Unit_hipGraphicsGLRegisterImage_Positive_Register_Twice") { + GLContextScopeGuard gl_context; + + GLImageObject tex; + + hipGraphicsResource *tex_resource_1, *tex_resource_2; + + HIP_CHECK(hipGraphicsGLRegisterImage(&tex_resource_1, tex, GL_TEXTURE_2D, + hipGraphicsRegisterFlagsNone)); + HIP_CHECK(hipGraphicsGLRegisterImage(&tex_resource_2, tex, GL_TEXTURE_2D, + hipGraphicsRegisterFlagsNone)); + + HIP_CHECK(hipGraphicsUnregisterResource(tex_resource_1)); + HIP_CHECK(hipGraphicsUnregisterResource(tex_resource_2)); +} + +TEST_CASE("Unit_hipGraphicsGLRegisterImage_Negative_Parameters") { + GLContextScopeGuard gl_context; + + GLImageObject tex; + + hipGraphicsResource* tex_resource; + + SECTION("resource == nullptr") { + HIP_CHECK_ERROR( + hipGraphicsGLRegisterImage(nullptr, tex, GL_TEXTURE_2D, hipGraphicsRegisterFlagsNone), + hipErrorInvalidValue); + } + + SECTION("invalid image") { + HIP_CHECK_ERROR(hipGraphicsGLRegisterImage(&tex_resource, GLuint{}, GL_TEXTURE_2D, + hipGraphicsRegisterFlagsNone), + hipErrorInvalidValue); + } + + SECTION("invalid target") { + HIP_CHECK_ERROR( + hipGraphicsGLRegisterImage(&tex_resource, tex, GL_BUFFER, hipGraphicsRegisterFlagsNone), + hipErrorInvalidValue); + } + + SECTION("target does not match the object") { + HIP_CHECK_ERROR(hipGraphicsGLRegisterImage(&tex_resource, tex, GL_RENDERBUFFER, + hipGraphicsRegisterFlagsNone), + hipErrorInvalidValue); + } + + SECTION("invalid flags") { + HIP_CHECK_ERROR(hipGraphicsGLRegisterImage(&tex_resource, tex, GL_TEXTURE_2D, + std::numeric_limits::max()), + hipErrorInvalidValue); + } +} \ No newline at end of file