Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/texture/hipTextureObjectTests.cc
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

355 lines
10 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include <hip_test_common.hh>
class TextureObjectTestWrapper {
private:
float* host_data_;
bool ommit_destroy_;
public:
hipTextureObject_t texture_object = 0;
hipResourceDesc res_desc;
hipTextureDesc tex_desc;
hipChannelFormatDesc channel_desc;
hipResourceViewDesc res_vew_desc;
hipArray_t array_member;
size_t size; /* size in bytes*/
int width; /* width in elements */
TextureObjectTestWrapper(bool useResourceViewDescriptor, bool ommitDestroy = false)
: ommit_destroy_(ommitDestroy), width(128) {
int i;
size = width * sizeof(float);
host_data_ = (float*)malloc(size);
memset(host_data_, 0, size);
for (i = 0; i < width; i++) {
host_data_[i] = i;
}
channel_desc = hipCreateChannelDesc(32, 0, 0, 0, hipChannelFormatKindFloat);
HIP_CHECK(hipMallocArray(&array_member, &channel_desc, width));
HIP_CHECK(
hipMemcpy2DToArray(array_member, 0, 0, host_data_, size, size, 1, hipMemcpyHostToDevice));
memset(&res_desc, 0, sizeof(res_desc));
res_desc.resType = hipResourceTypeArray;
res_desc.res.array.array = array_member;
memset(&tex_desc, 0, sizeof(tex_desc));
tex_desc.addressMode[0] = hipAddressModeClamp;
tex_desc.filterMode = hipFilterModePoint;
tex_desc.readMode = hipReadModeElementType;
tex_desc.normalizedCoords = false;
memset(&res_vew_desc, 0, sizeof(res_vew_desc));
if (useResourceViewDescriptor) {
#if HT_AMD
res_vew_desc.format = hipResViewFormatFloat1;
res_vew_desc.width = size;
#else
std::cout << "Resource View Descriptors are not supported on NVIDIA currently" << std::endl;
useResourceViewDescriptor = false;
#endif
}
HIP_CHECK(hipCreateTextureObject(&texture_object, &res_desc, &tex_desc,
useResourceViewDescriptor ? &res_vew_desc : nullptr));
}
~TextureObjectTestWrapper() {
if (!ommit_destroy_) {
HIP_CHECK(hipDestroyTextureObject(texture_object));
}
HIP_CHECK(hipFreeArray(array_member));
free(host_data_);
}
};
/**
* @addtogroup hipGetTextureObjectResourceDesc hipGetTextureObjectResourceDesc
* @{
* @ingroup TextureTest
* `hipError_t hipGetTextureObjectResourceDesc(hipResourceDesc* pResDesc,
* hipTextureObject_t textureObject)` -
* Gets resource descriptor for the texture object.
*/
/**
* Test Description
* ------------------------
* - Creates new texture object and an empty resource descriptor.
* - Gets resource descriptor from the texture.
* - Compares it to the empty created one.
* Test source
* ------------------------
* - unit/texture/hipTextureObjectTests.cc
* Test requirements
* ------------------------
* - Textures supported on device
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_hipGetTextureObjectResourceDesc_positive) {
CHECK_IMAGE_SUPPORT;
TextureObjectTestWrapper tex_obj_wrapper(false);
hipResourceDesc check_desc;
memset(&check_desc, 0, sizeof(check_desc));
HIP_CHECK(hipGetTextureObjectResourceDesc(&check_desc, tex_obj_wrapper.texture_object));
REQUIRE(check_desc.resType == tex_obj_wrapper.res_desc.resType);
REQUIRE(check_desc.res.array.array == tex_obj_wrapper.res_desc.res.array.array);
}
/**
* Test Description
* ------------------------
* - Validates handling of invalid arguments:
* -# When output pointer to the resource descriptor is `nullptr`
* - Expected output: return `hipErrorInvalidValue`
* -# When the texture is not valid (0)
* - Expected output: return `hipErrorInvalidValue`
* Test source
* ------------------------
* - unit/texture/hipTextureObjectTests.cc
* Test requirements
* ------------------------
* - Textures supported on device
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_hipGetTextureObjectResourceDesc_Negative_Parameters) {
CHECK_IMAGE_SUPPORT;
TextureObjectTestWrapper tex_obj_wrapper(false);
hipResourceDesc check_desc;
memset(&check_desc, 0, sizeof(check_desc));
SECTION("desc is nullptr") {
HIP_CHECK_ERROR(hipGetTextureObjectResourceDesc(nullptr, tex_obj_wrapper.texture_object),
hipErrorInvalidValue);
}
SECTION("texture is invalid") {
HIP_CHECK_ERROR(
hipGetTextureObjectResourceDesc(&check_desc, static_cast<hipTextureObject_t>(0)),
hipErrorInvalidValue);
}
}
/**
* End doxygen group hipGetTextureObjectResourceDesc.
* @}
*/
/**
* @addtogroup hipGetTextureObjectResourceViewDesc hipGetTextureObjectResourceViewDesc
* @{
* @ingroup TextureTest
* `hipGetTextureObjectResourceViewDesc(struct hipResourceViewDesc* pResViewDesc,
* hipTextureObject_t textureObject)` -
* Gets resource view descriptor for the texture object.
*/
/**
* Test Description
* ------------------------
* - Creates new texture object and an empty resource view descriptor.
* - Gets resource view descriptor from the texture.
* - Compares it to the empty created one.
* Test source
* ------------------------
* - unit/texture/hipTextureObjectTests.cc
* Test requirements
* ------------------------
* - Textures supported on device
* - Platform specific (AMD)
* - HIP_VERSION >= 5.2
*/
#if HT_AMD
HIP_TEST_CASE(Unit_hipGetTextureObjectResourceViewDesc_positive) {
CHECK_IMAGE_SUPPORT;
TextureObjectTestWrapper tex_obj_wrapper(true);
hipResourceViewDesc check_desc;
memset(&check_desc, 0, sizeof(check_desc));
HIP_CHECK(hipGetTextureObjectResourceViewDesc(&check_desc, tex_obj_wrapper.texture_object));
REQUIRE(check_desc.format == tex_obj_wrapper.res_vew_desc.format);
REQUIRE(check_desc.width == tex_obj_wrapper.res_vew_desc.width);
}
#endif
/**
* Test Description
* ------------------------
* - Validates handling of invalid arguments:
* -# When output pointer to the resource view descriptor is `nullptr`
* - Expected output: return `hipErrorInvalidValue`
* -# When the texture is not valid (0)
* - Expected output: return `hipErrorInvalidValue`
* Test source
* ------------------------
* - unit/texture/hipTextureObjectTests.cc
* Test requirements
* ------------------------
* - Textures supported on device
* - Platform specific (AMD)
* - HIP_VERSION >= 5.2
*/
#if HT_AMD
HIP_TEST_CASE(Unit_hipGetTextureObjectResourceViewDesc_Negative_Parameters) {
CHECK_IMAGE_SUPPORT;
TextureObjectTestWrapper tex_obj_wrapper(true);
hipResourceViewDesc check_desc;
memset(&check_desc, 0, sizeof(check_desc));
SECTION("desc is nullptr") {
HIP_CHECK_ERROR(hipGetTextureObjectResourceViewDesc(nullptr, tex_obj_wrapper.texture_object),
hipErrorInvalidValue);
}
SECTION("texture is invalid") {
HIP_CHECK_ERROR(
hipGetTextureObjectResourceViewDesc(&check_desc, static_cast<hipTextureObject_t>(0)),
hipErrorInvalidValue);
}
}
#endif
/**
* End doxygen group hipGetTextureObjectResourceViewDesc.
* @}
*/
/**
* @addtogroup hipGetTextureObjectTextureDesc hipGetTextureObjectTextureDesc
* @{
* @ingroup TextureTest
* `hipGetTextureObjectTextureDesc(hipTextureDesc* pTexDesc,
* hipTextureObject_t textureObject)` -
* Gets texture descriptor for the texture object.
*/
/**
* Test Description
* ------------------------
* - Creates new texture object and an empty texture descriptor.
* - Gets texture descriptor from the texture.
* - Compares it to the empty created one.
* Test source
* ------------------------
* - unit/texture/hipTextureObjectTests.cc
* Test requirements
* ------------------------
* - Textures supported on device
* - Platform specific (AMD)
* - HIP_VERSION >= 5.2
*/
#if HT_AMD
HIP_TEST_CASE(Unit_hipGetTextureObjectTextureDesc_positive) {
CHECK_IMAGE_SUPPORT;
TextureObjectTestWrapper tex_obj_wrapper(false);
hipTextureDesc check_desc;
memset(&check_desc, 0, sizeof(check_desc));
HIP_CHECK(hipGetTextureObjectTextureDesc(&check_desc, tex_obj_wrapper.texture_object));
REQUIRE(check_desc.addressMode[0] == tex_obj_wrapper.tex_desc.addressMode[0]);
REQUIRE(check_desc.filterMode == tex_obj_wrapper.tex_desc.filterMode);
REQUIRE(check_desc.readMode == tex_obj_wrapper.tex_desc.readMode);
REQUIRE(check_desc.normalizedCoords == tex_obj_wrapper.tex_desc.normalizedCoords);
}
#endif
/**
* Test Description
* ------------------------
* - Validates handling of invalid arguments:
* -# When output pointer to the texture descriptor is `nullptr`
* - Expected output: return `hipErrorInvalidValue`
* -# When the texture is not valid (0)
* - Expected output: return `hipErrorInvalidValue`
* Test source
* ------------------------
* - unit/texture/hipTextureObjectTests.cc
* Test requirements
* ------------------------
* - Textures supported on device
* - Platform specific (AMD)
* - HIP_VERSION >= 5.2
*/
#if HT_AMD
HIP_TEST_CASE(Unit_hipGetTextureObjectTextureDesc_Negative_Parameters) {
CHECK_IMAGE_SUPPORT;
TextureObjectTestWrapper tex_obj_wrapper(false);
hipTextureDesc check_desc;
memset(&check_desc, 0, sizeof(check_desc));
SECTION("desc is nullptr") {
HIP_CHECK_ERROR(hipGetTextureObjectTextureDesc(nullptr, tex_obj_wrapper.texture_object),
hipErrorInvalidValue);
}
SECTION("texture is invalid") {
HIP_CHECK_ERROR(hipGetTextureObjectTextureDesc(&check_desc, static_cast<hipTextureObject_t>(0)),
hipErrorInvalidValue);
}
}
#endif
/**
* End doxygen group hipGetTextureObjectTextureDesc.
* @}
*/
/**
* @addtogroup hipDestroyTextureObject hipDestroyTextureObject
* @{
* @ingroup TextureTest
* `hipDestroyTextureObject(hipTextureObject_t textureObject)` -
* Destroys a texture object.
* ________________________
* Test cases from other modules:
* - @ref Unit_hipCreateTextureObject_ArgValidation
*/
/**
* Test Description
* ------------------------
* - Successfully destroys regular texture object.
* Test source
* ------------------------
* - unit/texture/hipTextureObjectTests.cc
* Test requirements
* ------------------------
* - Textures supported on device
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_hipDestroyTextureObject_positive) {
CHECK_IMAGE_SUPPORT;
TextureObjectTestWrapper tex_obj_wrapper(false, true);
REQUIRE(hipDestroyTextureObject(tex_obj_wrapper.texture_object) == hipSuccess);
}