From a7ff065adc9240b006cfd5df804f152f66971cb7 Mon Sep 17 00:00:00 2001 From: Vladislav Sytchenko Date: Wed, 18 Mar 2020 12:23:11 -0400 Subject: [PATCH] Start the lifetime of the texture reference reinterpret_cast<> doesn't create an object, so the texref is actually unitiliazed. This may lead to garbage data in some of its struct members. Initialize it by performing a placement new. The constructer should set all of its members to default values. There's no way currently to extract the channel type, so use single channel char for now. Change-Id: I41b305a75bb3f30130324de785099f55b3e130c7 [ROCm/hip commit: 292d008a6467ab9e7dd3ffec90aa7195b2e89113] --- projects/hip/vdi/hip_module.cpp | 4 ++++ projects/hip/vdi/hip_platform.cpp | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/projects/hip/vdi/hip_module.cpp b/projects/hip/vdi/hip_module.cpp index 66955fcf3d..b92155e518 100644 --- a/projects/hip/vdi/hip_module.cpp +++ b/projects/hip/vdi/hip_module.cpp @@ -528,6 +528,10 @@ hipError_t hipModuleGetTexRef(textureReference** texRef, hipModule_t hmod, const HIP_RETURN(hipErrorNotFound); } + // Texture references created by HIP driver API + // have the default read mode set to normalized float. + (*texRef)->readMode = hipReadModeNormalizedFloat; + HIP_RETURN(hipSuccess); } diff --git a/projects/hip/vdi/hip_platform.cpp b/projects/hip/vdi/hip_platform.cpp index 57a37b02a5..4b0db00b1a 100644 --- a/projects/hip/vdi/hip_platform.cpp +++ b/projects/hip/vdi/hip_platform.cpp @@ -361,7 +361,8 @@ bool PlatformState::getTexRef(const char* hostVar, hipModule_t hmod, textureRefe return false; } - *texRef = reinterpret_cast(dvar->shadowVptr); + *texRef = new (dvar->shadowVptr) texture{}; + return true; }