mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/69330 --- ## Context Previously, our shader files did not declare any [image format qualifiers](https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)#Image_formats) for image layouts. This causes the SPIR-V modules produced to declare the [StorageImageWriteWithoutFormat](https://www.khronos.org/registry/SPIR-V/specs/unified1/SPIRV.html#_a_id_capability_a_capability) capability, which requires `shaderStorageImageWriteWithoutFormat` to be enabled in [VkPhysicalDeviceFeatures](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkPhysicalDeviceFeatures.html). `shaderStorageImageWriteWithoutFormat` is not available on some devices, causing errors to be reported by the Vulkan validation layer. ## Changes Vulkan shaders now declare the image format explicitly so that the SPIR-V modules produced are compatible with devices that do not have `shaderStorageImageWriteWithoutFormat` enabled. Test Plan: Imported from OSS Reviewed By: beback4u Differential Revision: D32840909 Pulled By: SS-JIA fbshipit-source-id: 76e0a0da68b423ebc74ae7e839b9cfaf57d2cd39
80 lines
2.3 KiB
CMake
80 lines
2.3 KiB
CMake
# Shaders processing
|
|
if(NOT USE_VULKAN)
|
|
return()
|
|
endif()
|
|
|
|
set(VULKAN_GEN_OUTPUT_PATH "${CMAKE_BINARY_DIR}/vulkan/ATen/native/vulkan")
|
|
set(VULKAN_GEN_ARG_ENV "")
|
|
|
|
if(USE_VULKAN_RELAXED_PRECISION)
|
|
string(APPEND VULKAN_GEN_ARG_ENV "precision=mediump")
|
|
endif()
|
|
if(USE_VULKAN_FP16_INFERENCE)
|
|
string(APPEND VULKAN_GEN_ARG_ENV "format=rgba16f")
|
|
endif()
|
|
|
|
if(USE_VULKAN_SHADERC_RUNTIME)
|
|
set(PYTHONPATH "$ENV{PYTHONPATH}")
|
|
set(ENV{PYTHONPATH} "$ENV{PYTHONPATH}:${CMAKE_CURRENT_LIST_DIR}/..")
|
|
execute_process(
|
|
COMMAND
|
|
"${PYTHON_EXECUTABLE}"
|
|
${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/gen_vulkan_glsl.py
|
|
--glsl-path ${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/native/vulkan/glsl
|
|
--output-path ${VULKAN_GEN_OUTPUT_PATH}
|
|
--tmp-dir-path=${CMAKE_BINARY_DIR}/vulkan/glsl
|
|
--env ${VULKAN_GEN_ARG_ENV}
|
|
RESULT_VARIABLE error_code)
|
|
set(ENV{PYTHONPATH} "$PYTHONPATH")
|
|
|
|
if(error_code)
|
|
message(FATAL_ERROR "Failed to gen glsl.h and glsl.cpp with shaders sources for Vulkan backend")
|
|
endif()
|
|
|
|
set(vulkan_generated_cpp ${VULKAN_GEN_OUTPUT_PATH}/glsl.cpp)
|
|
return()
|
|
endif()
|
|
|
|
if(NOT USE_VULKAN_SHADERC_RUNTIME)
|
|
# Precompiling shaders
|
|
if(ANDROID)
|
|
if(NOT ANDROID_NDK)
|
|
message(FATAL_ERROR "ANDROID_NDK not set")
|
|
endif()
|
|
|
|
set(GLSLC_PATH "${ANDROID_NDK}/shader-tools/${ANDROID_NDK_HOST_SYSTEM_NAME}/glslc")
|
|
else()
|
|
find_program(
|
|
GLSLC_PATH glslc
|
|
PATHS
|
|
ENV VULKAN_SDK
|
|
PATHS "$ENV{VULKAN_SDK}/${CMAKE_HOST_SYSTEM_PROCESSOR}/bin"
|
|
PATHS "$ENV{VULKAN_SDK}/bin"
|
|
)
|
|
|
|
if(NOT GLSLC_PATH)
|
|
message(FATAL_ERROR "USE_VULKAN glslc not found")
|
|
endif(NOT GLSLC_PATH)
|
|
endif()
|
|
|
|
set(PYTHONPATH "$ENV{PYTHONPATH}")
|
|
set(ENV{PYTHONPATH} "$ENV{PYTHONPATH}:${CMAKE_CURRENT_LIST_DIR}/..")
|
|
execute_process(
|
|
COMMAND
|
|
"${PYTHON_EXECUTABLE}"
|
|
${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/gen_vulkan_spv.py
|
|
--glsl-path ${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/native/vulkan/glsl
|
|
--output-path ${VULKAN_GEN_OUTPUT_PATH}
|
|
--glslc-path=${GLSLC_PATH}
|
|
--tmp-dir-path=${CMAKE_BINARY_DIR}/vulkan/spv
|
|
--env ${VULKAN_GEN_ARG_ENV}
|
|
RESULT_VARIABLE error_code)
|
|
set(ENV{PYTHONPATH} "$PYTHONPATH")
|
|
|
|
if(error_code)
|
|
message(FATAL_ERROR "Failed to gen spv.h and spv.cpp with precompiled shaders for Vulkan backend")
|
|
endif()
|
|
|
|
set(vulkan_generated_cpp ${VULKAN_GEN_OUTPUT_PATH}/spv.cpp)
|
|
endif()
|