mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-24 04:12:57 +08:00
Cleaned up files: level_zero/tools/source/debug/windows/debug_session.h level_zero/tools/source/sysman/memory/windows/os_memory_imp.h level_zero/tools/source/sysman/windows/kmd_sys_manager.h opencl/test/unit_test/aub_tests/command_stream/copy_engine_aub_tests_xehp_and shared/source/command_container/command_encoder.inl shared/source/command_stream/command_stream_receiver_hw_xehp_and_later.inl shared/source/helpers/blit_commands_helper_base.inl shared/test/unit_test/image/image_surface_state_fixture.h shared/test/unit_test/os_interface/windows/os_interface_win_tests.h Related-To: NEO-5548 Signed-off-by: Warchulski, Jaroslaw <jaroslaw.warchulski@intel.com>
97 lines
2.6 KiB
C++
97 lines
2.6 KiB
C++
/*
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
*/
|
|
|
|
#include "opencl/source/helpers/mipmap.h"
|
|
|
|
#include "opencl/source/mem_obj/image.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <limits>
|
|
|
|
namespace NEO {
|
|
|
|
uint32_t getMipLevelOriginIdx(cl_mem_object_type imageType) {
|
|
switch (imageType) {
|
|
case CL_MEM_OBJECT_IMAGE1D:
|
|
return 1;
|
|
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
|
|
case CL_MEM_OBJECT_IMAGE2D:
|
|
return 2;
|
|
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
|
|
case CL_MEM_OBJECT_IMAGE3D:
|
|
return 3;
|
|
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
|
|
return 0;
|
|
default:
|
|
DEBUG_BREAK_IF(true);
|
|
return std::numeric_limits<uint32_t>::max();
|
|
}
|
|
}
|
|
|
|
uint32_t findMipLevel(cl_mem_object_type imageType, const size_t *origin) {
|
|
size_t mipLevel = 0;
|
|
switch (imageType) {
|
|
case CL_MEM_OBJECT_IMAGE1D:
|
|
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
|
|
case CL_MEM_OBJECT_IMAGE2D:
|
|
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
|
|
case CL_MEM_OBJECT_IMAGE3D:
|
|
mipLevel = origin[getMipLevelOriginIdx(imageType)];
|
|
break;
|
|
default:
|
|
mipLevel = 0;
|
|
break;
|
|
}
|
|
|
|
return static_cast<uint32_t>(mipLevel);
|
|
}
|
|
|
|
bool isMipMapped(const MemObj *memObj) {
|
|
auto image = castToObject<Image>(memObj);
|
|
if (image == nullptr) {
|
|
return false;
|
|
}
|
|
return isMipMapped(image->getImageDesc());
|
|
}
|
|
|
|
uint32_t getMipOffset(Image *image, const size_t *origin) {
|
|
if (isMipMapped(image) == false) {
|
|
return 0;
|
|
}
|
|
UNRECOVERABLE_IF(origin == nullptr);
|
|
auto bytesPerPixel = image->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes;
|
|
size_t offset{};
|
|
auto imageType = image->getImageDesc().image_type;
|
|
auto lod = findMipLevel(imageType, origin);
|
|
auto baseWidth = image->getImageDesc().image_width;
|
|
auto baseHeight = image->getImageDesc().image_height;
|
|
if (lod) {
|
|
size_t mipHeight = baseHeight;
|
|
size_t mipWidth = baseWidth;
|
|
bool translate = false;
|
|
if (lod >= 2) {
|
|
translate = true;
|
|
mipWidth += std::max<size_t>(baseWidth >> 2, 1);
|
|
}
|
|
for (size_t currentLod = 3; currentLod <= lod; currentLod++) {
|
|
mipHeight += std::max<size_t>(baseHeight >> currentLod, 1);
|
|
mipWidth += std::max<size_t>(baseWidth >> currentLod, 1);
|
|
}
|
|
if (imageType == CL_MEM_OBJECT_IMAGE1D) {
|
|
offset = mipWidth;
|
|
} else {
|
|
offset = baseWidth * mipHeight;
|
|
if (translate) {
|
|
offset += std::max<size_t>(baseWidth >> 1, 1);
|
|
}
|
|
}
|
|
}
|
|
return static_cast<uint32_t>(bytesPerPixel * offset);
|
|
}
|
|
} // namespace NEO
|