SWDEV-558845 - Support image in rocr on Windows (#1582)

Enable image build in Windows.
Remove some useless codes that fail building in Windows.
Some minor improvement.
Temporarily exclude mipmap test files.
Prevent negative tests affect some tests.
Move some catch info log codes into failed cases.
This commit is contained in:
MachineTom authored and GitHub committed 2025-11-05 09:33:41 -05:00
1 parent 16334bc15d
commit 3b1c0c3464
44 files changed
+577 -531

No files matched your search

@@ -67,10 +67,12 @@ endif()
## Add custom command to generate a kernel code object file
##==========================================
function(gen_kernel_bc TARGET_ID INPUT_FILE OUTPUT_FILE)
if(WIN32)
set (WIN_CL_COMPILE_OPTION "-fshort-wchar")
endif()
separate_arguments(CLANG_ARG_LIST UNIX_COMMAND
"-O2 -x cl -Xclang -finclude-default-header -cl-denorms-are-zero -cl-std=CL2.0
-target amdgcn-amd-amdhsa -mcpu=${TARGET_ID} -mcode-object-version=4
-target amdgcn-amd-amdhsa -mcpu=${TARGET_ID} -mcode-object-version=4 ${WIN_CL_COMPILE_OPTION}
-o ${OUTPUT_FILE} ${INPUT_FILE}")
## Add custom command to produce a code object file.
@@ -128,9 +130,18 @@ function(generate_blit_file BFILE)
## Add a custom command that generates opencl_blit_objects.cpp
## This depends on all the generated code object files and the C++ generator script.
add_custom_command(OUTPUT ${BFILE}.cpp
if (UNIX)
add_custom_command(OUTPUT ${BFILE}.cpp
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/create_hsaco_ascii_file.sh ${CMAKE_CURRENT_BINARY_DIR}/${BFILE}.cpp
DEPENDS ${HSACO_TARG_LIST} create_hsaco_ascii_file.sh )
else()
find_package(Python3 COMPONENTS Interpreter REQUIRED)
add_custom_command(
OUTPUT ${BFILE}.cpp
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/create_hsaco_ascii_file.py ${CMAKE_CURRENT_BINARY_DIR}/${BFILE}.cpp ${HSACO_TARG_LIST}
COMMENT "Collating blit shaders..."
DEPENDS ${HSACO_TARG_LIST} create_hsaco_ascii_file.py)
endif()
## Export a target that builds (and depends on) opencl_blit_objects.cpp
add_custom_target( ${BFILE} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${BFILE}.cpp )
@@ -0,0 +1,71 @@
################################################################################
##
## Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
##
## SPDX-License-Identifier: MIT
##
################################################################################
import sys
def GetSize(fileobject):
fileobject.seek(0,2) # move the cursor to the end of the file
size = fileobject.tell()
return size
def DumpFile(header, input_name):
try:
with open(input_name, "rb") as binary_file:
# Read the entire content of the file as bytes
binary_data = binary_file.read()
file_size = GetSize(binary_file)
#print(f"Binary size: {file_size}")
# Reset file pointer
binary_file.seek(0)
parts = input_name.split('.')
file_name = parts[0]
content = f"unsigned char {file_name}""[] = {\n "
header.write(content)
line = 0
count = 0
for byte_value in binary_data:
count += 1
padded_hex = '{:02x}'.format(byte_value)
if (count != file_size):
header.write(f"0x{padded_hex},")
else:
header.write(f"0x{padded_hex}")
line += 1
if (line == 12):
header.write(f"\n ")
line = 0
else:
header.write(f" ")
header.write("\n};\nunsigned int "f"{file_name}_len = {file_size};\n")
except FileNotFoundError:
print(f"Error: The file {input_name} was not found.")
except Exception as e:
print(f"An error occurred: {e}")
if len(sys.argv) > 1:
header_name = sys.argv[1];
with open(header_name, 'w') as header:
header.write("//==============================================================================\n")
header.write("// This file is automatically generated during build process, don't modify it\n")
header.write("//==============================================================================\n\n")
header.write("namespace rocr {\n")
header.write("namespace image {\n\n")
for i, arg in enumerate(sys.argv):
if (i > 1):
#print(f"File {i}: {arg}\n")
DumpFile(header, arg)
header.write("} // namespace image\n")
header.write("} // namespace rocr\n\n")
else:
print("Empty arguments!")