mirror of
https://git.h3cjp.net/H3cJP/citra.git
synced 2024-11-24 13:53:02 +00:00
video_core/host_shaders: Add support for prebuilt SPIR-V shaders
Add support for building SPIR-V shaders from GLSL and generating headers to include the text of those same GLSL shaders to consume from OpenGL.
This commit is contained in:
parent
85cfd96f62
commit
95d156a150
|
@ -1,8 +1,12 @@
|
||||||
set(SHADER_SOURCES
|
set(SHADER_FILES
|
||||||
opengl_present.frag
|
opengl_present.frag
|
||||||
opengl_present.vert
|
opengl_present.vert
|
||||||
)
|
)
|
||||||
|
|
||||||
|
find_program(GLSLANGVALIDATOR "glslangValidator" REQUIRED)
|
||||||
|
|
||||||
|
set(GLSL_FLAGS "")
|
||||||
|
|
||||||
set(SHADER_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/include)
|
set(SHADER_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/include)
|
||||||
set(SHADER_DIR ${SHADER_INCLUDE}/video_core/host_shaders)
|
set(SHADER_DIR ${SHADER_INCLUDE}/video_core/host_shaders)
|
||||||
set(HOST_SHADERS_INCLUDE ${SHADER_INCLUDE} PARENT_SCOPE)
|
set(HOST_SHADERS_INCLUDE ${SHADER_INCLUDE} PARENT_SCOPE)
|
||||||
|
@ -10,27 +14,44 @@ set(HOST_SHADERS_INCLUDE ${SHADER_INCLUDE} PARENT_SCOPE)
|
||||||
set(INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/source_shader.h.in)
|
set(INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/source_shader.h.in)
|
||||||
set(HEADER_GENERATOR ${CMAKE_CURRENT_SOURCE_DIR}/StringShaderHeader.cmake)
|
set(HEADER_GENERATOR ${CMAKE_CURRENT_SOURCE_DIR}/StringShaderHeader.cmake)
|
||||||
|
|
||||||
foreach(FILENAME IN ITEMS ${SHADER_SOURCES})
|
foreach(FILENAME IN ITEMS ${SHADER_FILES})
|
||||||
string(REPLACE "." "_" SHADER_NAME ${FILENAME})
|
string(REPLACE "." "_" SHADER_NAME ${FILENAME})
|
||||||
set(SOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME})
|
set(SOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME})
|
||||||
set(HEADER_FILE ${SHADER_DIR}/${SHADER_NAME}.h)
|
# Skip generating source headers on Vulkan exclusive files
|
||||||
add_custom_command(
|
if (NOT ${FILENAME} MATCHES "vulkan.*")
|
||||||
OUTPUT
|
set(SOURCE_HEADER_FILE ${SHADER_DIR}/${SHADER_NAME}.h)
|
||||||
${HEADER_FILE}
|
add_custom_command(
|
||||||
COMMAND
|
OUTPUT
|
||||||
${CMAKE_COMMAND} -P ${HEADER_GENERATOR} ${SOURCE_FILE} ${HEADER_FILE} ${INPUT_FILE}
|
${SOURCE_HEADER_FILE}
|
||||||
MAIN_DEPENDENCY
|
COMMAND
|
||||||
${SOURCE_FILE}
|
${CMAKE_COMMAND} -P ${HEADER_GENERATOR} ${SOURCE_FILE} ${SOURCE_HEADER_FILE} ${INPUT_FILE}
|
||||||
DEPENDS
|
MAIN_DEPENDENCY
|
||||||
${INPUT_FILE}
|
${SOURCE_FILE}
|
||||||
# HEADER_GENERATOR should be included here but msbuild seems to assume it's always modified
|
DEPENDS
|
||||||
)
|
${INPUT_FILE}
|
||||||
set(SHADER_HEADERS ${SHADER_HEADERS} ${HEADER_FILE})
|
# HEADER_GENERATOR should be included here but msbuild seems to assume it's always modified
|
||||||
|
)
|
||||||
|
set(SHADER_HEADERS ${SHADER_HEADERS} ${SOURCE_HEADER_FILE})
|
||||||
|
endif()
|
||||||
|
# Skip compiling to SPIR-V OpenGL exclusive files
|
||||||
|
if (NOT ${FILENAME} MATCHES "opengl.*")
|
||||||
|
string(TOUPPER ${SHADER_NAME}_SPV SPIRV_VARIABLE_NAME)
|
||||||
|
set(SPIRV_HEADER_FILE ${SHADER_DIR}/${SHADER_NAME}_spv.h)
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT
|
||||||
|
${SPIRV_HEADER_FILE}
|
||||||
|
COMMAND
|
||||||
|
${GLSLANGVALIDATOR} -V ${GLSL_FLAGS} --variable-name ${SPIRV_VARIABLE_NAME} -o ${SPIRV_HEADER_FILE} ${SOURCE_FILE}
|
||||||
|
MAIN_DEPENDENCY
|
||||||
|
${SOURCE_FILE}
|
||||||
|
)
|
||||||
|
set(SHADER_HEADERS ${SHADER_HEADERS} ${SPIRV_HEADER_FILE})
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
add_custom_target(host_shaders
|
add_custom_target(host_shaders
|
||||||
DEPENDS
|
DEPENDS
|
||||||
${SHADER_HEADERS}
|
${SHADER_HEADERS}
|
||||||
SOURCES
|
SOURCES
|
||||||
${SHADER_SOURCES}
|
${SHADER_FILES}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue