Add Vulkan Host-Shader compilation

Compiles Vulkan Host shaders into spirv binary files and embeds them
into the application's virtual file-system.
This commit is contained in:
Wunkolo 2023-08-16 21:11:25 -07:00
parent f62f1bf9b2
commit 97b6b7f122
3 changed files with 51 additions and 1 deletions

View file

@ -251,10 +251,30 @@ if(ENABLE_VULKAN)
set(HEADER_FILES ${HEADER_FILES} ${RENDERER_VK_INCLUDE_FILES})
source_group("Source Files\\Core\\Vulkan Renderer" FILES ${RENDERER_VK_SOURCE_FILES})
set(RENDERER_VK_HOST_SHADERS_SOURCE
"src/host_shaders/vulkan_display.frag"
"src/host_shaders/vulkan_display.vert"
)
foreach( HOST_SHADER_SOURCE ${RENDERER_VK_HOST_SHADERS_SOURCE} )
get_filename_component( FILE_NAME ${HOST_SHADER_SOURCE} NAME )
set( HOST_SHADER_SPIRV "${PROJECT_BINARY_DIR}/host_shaders/${FILE_NAME}.spv" )
add_custom_command(
OUTPUT ${HOST_SHADER_SPIRV}
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/host_shaders/"
COMMAND Vulkan::glslangValidator -t --target-env vulkan1.1 -g -V "${PROJECT_SOURCE_DIR}/${HOST_SHADER_SOURCE}" -o ${HOST_SHADER_SPIRV}
#COMMAND ${SPIRV_OPT} -O ${HOST_SHADER_SPIRV} -o ${HOST_SHADER_SPIRV}
DEPENDS ${HOST_SHADER_SOURCE}
)
list( APPEND RENDERER_VK_HOST_SHADERS_SPIRV ${HOST_SHADER_SPIRV} )
endforeach()
cmrc_add_resource_library(
resources_renderer_vk
NAMESPACE RendererVK
WHENCE "src/host_shaders/"
WHENCE "${PROJECT_BINARY_DIR}/host_shaders/"
${RENDERER_VK_HOST_SHADERS_SPIRV}
)
endif()

View file

@ -0,0 +1,7 @@
#version 460 core
layout(location = 0) in vec2 UV;
layout(location = 0) out vec4 FragColor;
layout(binding = 0) uniform sampler2D u_texture;
void main() { FragColor = texture(u_texture, UV); }

View file

@ -0,0 +1,23 @@
#version 460 core
layout(location = 0) out vec2 UV;
void main() {
const vec4 positions[4] = vec4[](
vec4(-1.0, 1.0, 1.0, 1.0), // Top-left
vec4(1.0, 1.0, 1.0, 1.0), // Top-right
vec4(-1.0, -1.0, 1.0, 1.0), // Bottom-left
vec4(1.0, -1.0, 1.0, 1.0) // Bottom-right
);
// The 3DS displays both screens' framebuffer rotated 90 deg counter clockwise
// So we adjust our texcoords accordingly
const vec2 texcoords[4] = vec2[](
vec2(1.0, 1.0), // Top-right
vec2(1.0, 0.0), // Bottom-right
vec2(0.0, 1.0), // Top-left
vec2(0.0, 0.0) // Bottom-left
);
gl_Position = positions[gl_VertexIndex];
UV = texcoords[gl_VertexIndex];
}