SWDEV-547291 - Interop for OpenGL (#2350)

Updated to convert flags correctly

Added ObjectRegistry to track registered and mapped resources and incorporated it into hip_gl.

Added mip level check

Made functions static in-line

Reworked validation to be more clear.
This commit is contained in:
Sam Ruscica
2026-01-21 12:08:55 -05:00
committed by GitHub
parent c563286f96
commit 5daeb14582
13 changed files with 315 additions and 57 deletions
@@ -96,4 +96,4 @@ TEST_CASE("Unit_hipGLGetDevices_Negative_Parameters") {
REQUIRE(gl_device_count == 0);
REQUIRE(gl_devices.at(0) == -1);
}
}
}
@@ -113,4 +113,4 @@ TEST_CASE("Unit_hipGraphicsGLRegisterBuffer_Negative_Parameters") {
hipGraphicsGLRegisterBuffer(&vbo_resource, vbo, hipGraphicsRegisterFlagsTextureGather),
hipErrorInvalidValue);
}
}
}
@@ -116,4 +116,4 @@ TEST_CASE("Unit_hipGraphicsGLRegisterImage_Negative_Parameters") {
std::numeric_limits<unsigned int>::max()),
hipErrorInvalidValue);
}
}
}
@@ -108,4 +108,4 @@ TEST_CASE("Unit_hipGraphicsMapResources_Negative_Parameters") {
}
HIP_CHECK(hipGraphicsUnregisterResource(vbo_resource));
}
}
@@ -60,7 +60,7 @@ TEST_CASE("Unit_hipGraphicsResourceGetMappedPointer_Positive_Basic") {
HIP_CHECK(hipGraphicsUnregisterResource(vbo_resource));
}
TEST_CASE("Unit_hipGraphicsResourceGetMappedPointer_Positive_Parameters") {
TEST_CASE("Unit_hipGraphicsResourceGetMappedPointer_Null_Parameters") {
GLContextScopeGuard gl_context;
const int device_count = HipTest::getDeviceCount();
@@ -84,14 +84,23 @@ TEST_CASE("Unit_hipGraphicsResourceGetMappedPointer_Positive_Parameters") {
size_t size = 0;
SECTION("devPtr == nullptr") {
HIP_CHECK(hipGraphicsResourceGetMappedPointer(nullptr, &size, vbo_resource));
REQUIRE(size == vbo.kSize);
HIP_CHECK_ERROR(hipGraphicsResourceGetMappedPointer(nullptr, &size, vbo_resource), hipErrorInvalidValue);
}
SECTION("size == nullptr") {
HIP_CHECK(hipGraphicsResourceGetMappedPointer(reinterpret_cast<void**>(&buffer_devptr), nullptr,
vbo_resource));
REQUIRE(buffer_devptr != nullptr);
HIP_CHECK_ERROR(hipGraphicsResourceGetMappedPointer(reinterpret_cast<void**>(&buffer_devptr), nullptr,
vbo_resource), hipErrorInvalidValue);
}
SECTION("resource == nullptr") {
hipGraphicsResource* null_resource = nullptr;
HIP_CHECK_ERROR(hipGraphicsResourceGetMappedPointer(reinterpret_cast<void**>(&buffer_devptr), &size,
null_resource), hipErrorInvalidValue);
}
SECTION("devPtr == nullptr && size == nullptr") {
HIP_CHECK_ERROR(hipGraphicsResourceGetMappedPointer(nullptr, nullptr,
vbo_resource), hipErrorInvalidValue);
}
HIP_CHECK(hipGraphicsUnmapResources(1, &vbo_resource, 0));
@@ -145,7 +154,7 @@ TEST_CASE("Unit_hipGraphicsResourceGetMappedPointer_Negative_Parameters") {
HIP_CHECK(hipGraphicsUnregisterResource(unregistered_resource));
HIP_CHECK_ERROR(hipGraphicsResourceGetMappedPointer(reinterpret_cast<void**>(&buffer_devptr),
&size, unregistered_resource),
hipErrorContextIsDestroyed);
hipErrorInvalidHandle);
}
SECTION("not mapped resource") {
@@ -175,4 +184,4 @@ TEST_CASE("Unit_hipGraphicsResourceGetMappedPointer_Negative_Parameters") {
HIP_CHECK(hipGraphicsUnmapResources(1, &vbo_resource, 0));
HIP_CHECK(hipGraphicsUnregisterResource(vbo_resource));
}
}
@@ -81,7 +81,7 @@ TEST_CASE("Unit_hipGraphicsSubResourceGetMappedArray_Negative_Parameters") {
hipArray_t image_devptr = nullptr;
SECTION("array == nullptr") {
HIP_CHECK(hipGraphicsSubResourceGetMappedArray(nullptr, tex_resource, 0, 0));
HIP_CHECK_ERROR(hipGraphicsSubResourceGetMappedArray(nullptr, tex_resource, 0, 0), hipErrorInvalidValue);
}
SECTION("non-texture resource") {
@@ -105,7 +105,7 @@ TEST_CASE("Unit_hipGraphicsSubResourceGetMappedArray_Negative_Parameters") {
HIP_CHECK(hipGraphicsUnregisterResource(unregistered_resource));
HIP_CHECK_ERROR(
hipGraphicsSubResourceGetMappedArray(&image_devptr, unregistered_resource, 0, 0),
hipErrorContextIsDestroyed);
hipErrorInvalidHandle);
}
SECTION("not mapped resource") {
@@ -147,4 +147,4 @@ TEST_CASE("Unit_hipGraphicsSubResourceGetMappedArray_Negative_Parameters") {
HIP_CHECK(hipGraphicsUnmapResources(1, &tex_resource, 0));
HIP_CHECK(hipGraphicsUnregisterResource(tex_resource));
}
}
@@ -51,7 +51,7 @@ TEST_CASE("Unit_hipGraphicsUnmapResources_Negative_Parameters") {
}
SECTION("resources == nullptr") {
HIP_CHECK_ERROR(hipGraphicsUnmapResources(1, nullptr, 0), hipErrorUnknown);
HIP_CHECK_ERROR(hipGraphicsUnmapResources(1, nullptr, 0), hipErrorInvalidValue);
}
SECTION("not mapped resource") {
@@ -72,4 +72,4 @@ TEST_CASE("Unit_hipGraphicsUnmapResources_Negative_Parameters") {
HIP_CHECK(hipGraphicsUnmapResources(1, &vbo_resource, 0));
HIP_CHECK(hipGraphicsUnregisterResource(vbo_resource));
}
}
@@ -40,18 +40,23 @@ TEST_CASE("Unit_hipGraphicsUnregisterResource_Negative_Parameters") {
GLBufferObject vbo;
SECTION("already unregistered resource") {
SECTION("null resource") {
hipGraphicsResource* null_resource = nullptr;
HIP_CHECK_ERROR(hipGraphicsUnregisterResource(null_resource), hipErrorInvalidValue);
}
SECTION("already unregistered resource") {
hipGraphicsResource* unregistered_resource;
HIP_CHECK(
hipGraphicsGLRegisterBuffer(&unregistered_resource, vbo, hipGraphicsRegisterFlagsNone));
HIP_CHECK(hipGraphicsUnregisterResource(unregistered_resource));
HIP_CHECK_ERROR(hipGraphicsUnregisterResource(unregistered_resource), hipErrorInvalidContext);
HIP_CHECK_ERROR(hipGraphicsUnregisterResource(unregistered_resource), hipErrorInvalidHandle);
}
SECTION("mapped resource") {
hipGraphicsResource* mapped_resource;
HIP_CHECK(hipGraphicsGLRegisterBuffer(&mapped_resource, vbo, hipGraphicsRegisterFlagsNone));
HIP_CHECK(hipGraphicsMapResources(1, &mapped_resource, 0));
HIP_CHECK_ERROR(hipGraphicsUnregisterResource(mapped_resource), hipErrorAlreadyMapped);
HIP_CHECK_ERROR(hipGraphicsUnregisterResource(mapped_resource), hipErrorArrayIsMapped);
}
}
}