EXSWHTEC-318 - Implement tests for 2D texture device functions #367
Change-Id: I5404eae219d23dc058aa6ef150a0764b06ab6de1
This commit is contained in:
committed by
Rakesh Roy
parent
da67d77a0c
commit
37d8529a9b
@@ -42,6 +42,8 @@ set(TEST_SRC
|
||||
hipTextureObj3DCheckModes.cc
|
||||
hipTextureObj1DCheckSRGBModes.cc
|
||||
hipTextureObj2DCheckSRGBModes.cc
|
||||
tex2D.cc
|
||||
tex2DLayered.cc
|
||||
hipTexObjectTests.cc
|
||||
hipTextureObjectTests.cc
|
||||
hipBindTextureToMipmappedArray.cc
|
||||
|
||||
@@ -126,7 +126,8 @@ template <typename TestType, bool normalized_read = false> struct TextureTestFix
|
||||
SetVec4<TestType>(host_alloc.ptr()[i], i + test_value_offset);
|
||||
}
|
||||
|
||||
hipMemcpy3DParms memcpy_params = {};
|
||||
hipMemcpy3DParms memcpy_params;
|
||||
memset(&memcpy_params, 0 sizeof(hipMemcpy3DParms));
|
||||
memcpy_params.dstArray = tex_alloc_d.ptr();
|
||||
memcpy_params.extent = params.LayeredExtent();
|
||||
memcpy_params.extent.height = memcpy_params.extent.height ?: 1;
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
Copyright (c) 2023 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 <hip_test_common.hh>
|
||||
|
||||
#include "kernels.hh"
|
||||
#include "test_fixture.hh"
|
||||
|
||||
/**
|
||||
* @addtogroup tex2D tex2D
|
||||
* @{
|
||||
* @ingroup TextureTest
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Test texture fetching with `tex2D` and read mode set to `hipReadModeElementType`. The
|
||||
* test is performed with:
|
||||
* - normalized coordinates
|
||||
* - non-normalized coordinates
|
||||
* - Nearest-point sampling
|
||||
* - Linear filtering
|
||||
* - All combinations of different addressing modes.
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - unit/texture/tex2D.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.2
|
||||
*/
|
||||
TEMPLATE_TEST_CASE("Unit_tex2D_Positive_ReadModeElementType", "", char, unsigned char, short,
|
||||
unsigned short, int, unsigned int, float) {
|
||||
TextureTestParams<TestType> params = {0};
|
||||
params.extent = make_hipExtent(16, 4, 0);
|
||||
params.num_subdivisions = 4;
|
||||
params.GenerateTextureDesc();
|
||||
|
||||
TextureTestFixture<TestType> fixture{params};
|
||||
|
||||
const auto [num_threads_x, num_blocks_x] = GetLaunchConfig(32, params.NumItersX());
|
||||
const auto [num_threads_y, num_blocks_y] = GetLaunchConfig(32, params.NumItersY());
|
||||
|
||||
dim3 dim_grid;
|
||||
dim_grid.x = num_blocks_x;
|
||||
dim_grid.y = num_blocks_y;
|
||||
|
||||
dim3 dim_block;
|
||||
dim_block.x = num_threads_x;
|
||||
dim_block.y = num_threads_y;
|
||||
|
||||
tex2DKernel<vec4<TestType>><<<dim_grid, dim_block>>>(
|
||||
fixture.out_alloc_d.ptr(), params.NumItersX(), params.NumItersY(), fixture.tex.object(),
|
||||
params.Width(), params.Height(), params.num_subdivisions, params.tex_desc.normalizedCoords);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
|
||||
fixture.LoadOutput();
|
||||
|
||||
for (auto j = 0u; j < params.NumItersY(); ++j) {
|
||||
for (auto i = 0u; i < params.NumItersX(); ++i) {
|
||||
float x = GetCoordinate(i, params.NumItersX(), params.Width(), params.num_subdivisions,
|
||||
params.tex_desc.normalizedCoords);
|
||||
float y = GetCoordinate(j, params.NumItersY(), params.Height(), params.num_subdivisions,
|
||||
params.tex_desc.normalizedCoords);
|
||||
|
||||
INFO("i: " << i);
|
||||
INFO("j: " << j);
|
||||
INFO("Normalized coordinates: " << std::boolalpha << params.tex_desc.normalizedCoords);
|
||||
INFO("Address mode X: " << AddressModeToString(params.tex_desc.addressMode[0]));
|
||||
INFO("Address mode Y: " << AddressModeToString(params.tex_desc.addressMode[1]));
|
||||
INFO("x: " << std::fixed << std::setprecision(16) << x);
|
||||
INFO("y: " << std::fixed << std::setprecision(16) << y);
|
||||
|
||||
auto index = j * params.NumItersX() + i;
|
||||
|
||||
const auto ref_val = fixture.tex_h.Tex2D(x, y, params.tex_desc);
|
||||
REQUIRE(ref_val.x == fixture.out_alloc_h[index].x);
|
||||
REQUIRE(ref_val.y == fixture.out_alloc_h[index].y);
|
||||
REQUIRE(ref_val.z == fixture.out_alloc_h[index].z);
|
||||
REQUIRE(ref_val.w == fixture.out_alloc_h[index].w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Test texture fetching with `tex2D` and read mode set to `hipReadModeNormalizedFloat`. The
|
||||
* test is performed with:
|
||||
* - normalized coordinates
|
||||
* - non-normalized coordinates
|
||||
* - Nearest-point sampling
|
||||
* - Linear filtering
|
||||
* - All combinations of different addressing modes.
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - unit/texture/tex2D.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.2
|
||||
*/
|
||||
TEMPLATE_TEST_CASE("Unit_tex2D_Positive_ReadModeNormalizedFloat", "", char, unsigned char, short,
|
||||
unsigned short) {
|
||||
TextureTestParams<TestType> params = {0};
|
||||
params.extent = make_hipExtent(16, 4, 0);
|
||||
params.num_subdivisions = 4;
|
||||
params.GenerateTextureDesc(hipReadModeNormalizedFloat);
|
||||
|
||||
TextureTestFixture<TestType, true> fixture{params};
|
||||
|
||||
const auto [num_threads_x, num_blocks_x] = GetLaunchConfig(32, params.NumItersX());
|
||||
const auto [num_threads_y, num_blocks_y] = GetLaunchConfig(32, params.NumItersY());
|
||||
|
||||
dim3 dim_grid;
|
||||
dim_grid.x = num_blocks_x;
|
||||
dim_grid.y = num_blocks_y;
|
||||
|
||||
dim3 dim_block;
|
||||
dim_block.x = num_threads_x;
|
||||
dim_block.y = num_threads_y;
|
||||
|
||||
tex2DKernel<vec4<float>><<<dim_grid, dim_block>>>(
|
||||
fixture.out_alloc_d.ptr(), params.NumItersX(), params.NumItersY(), fixture.tex.object(),
|
||||
params.Width(), params.Height(), params.num_subdivisions, params.tex_desc.normalizedCoords);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
|
||||
fixture.LoadOutput();
|
||||
|
||||
for (auto j = 0u; j < params.NumItersY(); ++j) {
|
||||
for (auto i = 0u; i < params.NumItersX(); ++i) {
|
||||
float x = GetCoordinate(i, params.NumItersX(), params.Width(), params.num_subdivisions,
|
||||
params.tex_desc.normalizedCoords);
|
||||
float y = GetCoordinate(j, params.NumItersY(), params.Height(), params.num_subdivisions,
|
||||
params.tex_desc.normalizedCoords);
|
||||
|
||||
INFO("i: " << i);
|
||||
INFO("j: " << j);
|
||||
INFO("Filtering mode: " << FilteringModeToString(params.tex_desc.filterMode));
|
||||
INFO("Normalized coordinates: " << std::boolalpha << params.tex_desc.normalizedCoords);
|
||||
INFO("Address mode X: " << AddressModeToString(params.tex_desc.addressMode[0]));
|
||||
INFO("Address mode Y: " << AddressModeToString(params.tex_desc.addressMode[1]));
|
||||
INFO("x: " << std::fixed << std::setprecision(16) << x);
|
||||
INFO("y: " << std::fixed << std::setprecision(16) << y);
|
||||
|
||||
auto index = j * params.NumItersX() + i;
|
||||
|
||||
auto ref_val =
|
||||
Vec4Map<TestType>(fixture.tex_h.Tex2D(x, y, params.tex_desc), NormalizeInteger<TestType>);
|
||||
REQUIRE(ref_val.x == fixture.out_alloc_h[index].x);
|
||||
REQUIRE(ref_val.y == fixture.out_alloc_h[index].y);
|
||||
REQUIRE(ref_val.z == fixture.out_alloc_h[index].z);
|
||||
REQUIRE(ref_val.w == fixture.out_alloc_h[index].w);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
Copyright (c) 2023 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 <hip_test_common.hh>
|
||||
|
||||
#include "kernels.hh"
|
||||
#include "test_fixture.hh"
|
||||
|
||||
/**
|
||||
* @addtogroup tex2DLayered tex2DLayered
|
||||
* @{
|
||||
* @ingroup TextureTest
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Test texture fetching with `tex2DLayered` and read mode set to `hipReadModeElementType`. The
|
||||
* test is performed with:
|
||||
* - normalized coordinates
|
||||
* - non-normalized coordinates
|
||||
* - Nearest-point sampling
|
||||
* - Linear filtering
|
||||
* - All combinations of different addressing modes.
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - unit/texture/tex2DLayered.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.2
|
||||
*/
|
||||
TEMPLATE_TEST_CASE("Unit_tex2DLayered_Positive_ReadModeElementType", "", char, unsigned char, short,
|
||||
unsigned short, int, unsigned int, float) {
|
||||
TextureTestParams<TestType> params = {0};
|
||||
params.extent = make_hipExtent(16, 4, 0);
|
||||
params.layers = 2;
|
||||
params.num_subdivisions = 4;
|
||||
params.GenerateTextureDesc();
|
||||
|
||||
TextureTestFixture<TestType> fixture{params};
|
||||
|
||||
const auto [num_threads_x, num_blocks_x] = GetLaunchConfig(32, params.NumItersX());
|
||||
const auto [num_threads_y, num_blocks_y] = GetLaunchConfig(32, params.NumItersY());
|
||||
|
||||
dim3 dim_grid;
|
||||
dim_grid.x = num_blocks_x;
|
||||
dim_grid.y = num_blocks_y;
|
||||
|
||||
dim3 dim_block;
|
||||
dim_block.x = num_threads_x;
|
||||
dim_block.y = num_threads_y;
|
||||
|
||||
for (auto layer = 0u; layer < params.layers; ++layer) {
|
||||
tex2DLayeredKernel<vec4<TestType>>
|
||||
<<<dim_grid, dim_block>>>(fixture.out_alloc_d.ptr(), params.NumItersX(), params.NumItersY(),
|
||||
fixture.tex.object(), params.Width(), params.Height(),
|
||||
params.num_subdivisions, params.tex_desc.normalizedCoords, layer);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
|
||||
fixture.LoadOutput();
|
||||
|
||||
for (auto j = 0u; j < params.NumItersY(); ++j) {
|
||||
for (auto i = 0u; i < params.NumItersX(); ++i) {
|
||||
float x = GetCoordinate(i, params.NumItersX(), params.Width(), params.num_subdivisions,
|
||||
params.tex_desc.normalizedCoords);
|
||||
float y = GetCoordinate(j, params.NumItersY(), params.Height(), params.num_subdivisions,
|
||||
params.tex_desc.normalizedCoords);
|
||||
|
||||
INFO("Layer: " << layer);
|
||||
INFO("i: " << i);
|
||||
INFO("j: " << j);
|
||||
INFO("Normalized coordinates: " << std::boolalpha << params.tex_desc.normalizedCoords);
|
||||
INFO("Address mode X: " << AddressModeToString(params.tex_desc.addressMode[0]));
|
||||
INFO("Address mode Y: " << AddressModeToString(params.tex_desc.addressMode[1]));
|
||||
INFO("x: " << std::fixed << std::setprecision(16) << x);
|
||||
INFO("y: " << std::fixed << std::setprecision(16) << y);
|
||||
|
||||
auto index = j * params.NumItersX() + i;
|
||||
|
||||
const auto ref_val = fixture.tex_h.Tex2DLayered(x, y, layer, params.tex_desc);
|
||||
REQUIRE(ref_val.x == fixture.out_alloc_h[index].x);
|
||||
REQUIRE(ref_val.y == fixture.out_alloc_h[index].y);
|
||||
REQUIRE(ref_val.z == fixture.out_alloc_h[index].z);
|
||||
REQUIRE(ref_val.w == fixture.out_alloc_h[index].w);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Test texture fetching with `tex2DLayered` and read mode set to `hipReadModeNormalizedFloat`.
|
||||
* The test is performed with:
|
||||
* - normalized coordinates
|
||||
* - non-normalized coordinates
|
||||
* - Nearest-point sampling
|
||||
* - Linear filtering
|
||||
* - All combinations of different addressing modes.
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - unit/texture/tex2DLayered.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.2
|
||||
*/
|
||||
TEMPLATE_TEST_CASE("Unit_tex2DLayered_Positive_ReadModeNormalizedFloat", "", char, unsigned char,
|
||||
short, unsigned short) {
|
||||
TextureTestParams<TestType> params = {0};
|
||||
params.extent = make_hipExtent(16, 4, 0);
|
||||
params.layers = 2;
|
||||
params.num_subdivisions = 4;
|
||||
params.GenerateTextureDesc(hipReadModeNormalizedFloat);
|
||||
|
||||
TextureTestFixture<TestType, true> fixture{params};
|
||||
|
||||
const auto [num_threads_x, num_blocks_x] = GetLaunchConfig(32, params.NumItersX());
|
||||
const auto [num_threads_y, num_blocks_y] = GetLaunchConfig(32, params.NumItersY());
|
||||
|
||||
dim3 dim_grid;
|
||||
dim_grid.x = num_blocks_x;
|
||||
dim_grid.y = num_blocks_y;
|
||||
|
||||
dim3 dim_block;
|
||||
dim_block.x = num_threads_x;
|
||||
dim_block.y = num_threads_y;
|
||||
|
||||
for (auto layer = 0u; layer < params.layers; ++layer) {
|
||||
tex2DLayeredKernel<vec4<float>>
|
||||
<<<dim_grid, dim_block>>>(fixture.out_alloc_d.ptr(), params.NumItersX(), params.NumItersY(),
|
||||
fixture.tex.object(), params.Width(), params.Height(),
|
||||
params.num_subdivisions, params.tex_desc.normalizedCoords, layer);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
|
||||
fixture.LoadOutput();
|
||||
|
||||
for (auto j = 0u; j < params.NumItersY(); ++j) {
|
||||
for (auto i = 0u; i < params.NumItersX(); ++i) {
|
||||
float x = GetCoordinate(i, params.NumItersX(), params.Width(), params.num_subdivisions,
|
||||
params.tex_desc.normalizedCoords);
|
||||
float y = GetCoordinate(j, params.NumItersY(), params.Height(), params.num_subdivisions,
|
||||
params.tex_desc.normalizedCoords);
|
||||
|
||||
INFO("Layer: " << layer);
|
||||
INFO("i: " << i);
|
||||
INFO("j: " << j);
|
||||
INFO("Normalized coordinates: " << std::boolalpha << params.tex_desc.normalizedCoords);
|
||||
INFO("Address mode X: " << AddressModeToString(params.tex_desc.addressMode[0]));
|
||||
INFO("Address mode Y: " << AddressModeToString(params.tex_desc.addressMode[1]));
|
||||
INFO("x: " << std::fixed << std::setprecision(16) << x);
|
||||
INFO("y: " << std::fixed << std::setprecision(16) << y);
|
||||
|
||||
auto index = j * params.NumItersX() + i;
|
||||
|
||||
auto ref_val = Vec4Map<TestType>(fixture.tex_h.Tex2DLayered(x, y, layer, params.tex_desc),
|
||||
NormalizeInteger<TestType>);
|
||||
REQUIRE(ref_val.x == fixture.out_alloc_h[index].x);
|
||||
REQUIRE(ref_val.y == fixture.out_alloc_h[index].y);
|
||||
REQUIRE(ref_val.z == fixture.out_alloc_h[index].z);
|
||||
REQUIRE(ref_val.w == fixture.out_alloc_h[index].w);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,17 +236,10 @@ template <typename TexelType> class TextureReference {
|
||||
return coord;
|
||||
}
|
||||
|
||||
template <size_t N> float FloatToNBitFractional(float x) const {
|
||||
constexpr size_t mult = 1 << N;
|
||||
const auto x_trunc = std::trunc(x);
|
||||
const auto x_frac = std::round((x - x_trunc) * mult) / mult;
|
||||
return x_trunc + x_frac;
|
||||
}
|
||||
|
||||
std::tuple<float, float> GetLinearFilteringParams(float coord) const {
|
||||
const auto coordB = FloatToNBitFractional<8>(coord - 0.5f);
|
||||
const auto coordB = coord - 0.5f;
|
||||
const auto index = floorf(coordB);
|
||||
const auto coeff = coordB - index;
|
||||
const FixedPoint<8> coeff = coordB - index;
|
||||
|
||||
return {index, coeff};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user