From f6566338ebd6559b0fbe61e1557ee735bf58dcdd Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sat, 13 Feb 2021 15:52:21 -0500 Subject: host_shaders: Modify shader cmake integration to allow for larger shaders using a raw string to encapsulate the entire shader code limits us to shaders of size less than 2KB. This change overcomes this limitation. --- src/video_core/host_shaders/CMakeLists.txt | 1 + .../host_shaders/StringShaderHeader.cmake | 22 +++++++++++++++++++++- src/video_core/host_shaders/source_shader.h.in | 4 +++- 3 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src/video_core/host_shaders') diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt index 3494318ca..2208e1922 100644 --- a/src/video_core/host_shaders/CMakeLists.txt +++ b/src/video_core/host_shaders/CMakeLists.txt @@ -1,4 +1,5 @@ set(SHADER_FILES + astc_decoder.comp block_linear_unswizzle_2d.comp block_linear_unswizzle_3d.comp convert_depth_to_float.frag diff --git a/src/video_core/host_shaders/StringShaderHeader.cmake b/src/video_core/host_shaders/StringShaderHeader.cmake index c0fc49768..1b4bc6103 100644 --- a/src/video_core/host_shaders/StringShaderHeader.cmake +++ b/src/video_core/host_shaders/StringShaderHeader.cmake @@ -6,7 +6,27 @@ get_filename_component(CONTENTS_NAME ${SOURCE_FILE} NAME) string(REPLACE "." "_" CONTENTS_NAME ${CONTENTS_NAME}) string(TOUPPER ${CONTENTS_NAME} CONTENTS_NAME) -file(READ ${SOURCE_FILE} CONTENTS) +FILE(READ ${SOURCE_FILE} line_contents) + +# Replace double quotes with single quotes, +# as double quotes will be used to wrap the lines +STRING(REGEX REPLACE "\"" "'" line_contents "${line_contents}") + +# CMake separates list elements with semicolons, but semicolons +# are used extensively in the shader code. +# Replace with a temporary marker, to be reverted later. +STRING(REGEX REPLACE ";" "{{SEMICOLON}}" line_contents "${line_contents}") + +# Make every line an individual element in the CMake list. +STRING(REGEX REPLACE "\n" ";" line_contents "${line_contents}") + +# Build the shader string, wrapping each line in double quotes. +foreach(line IN LISTS line_contents) + string(CONCAT CONTENTS "${CONTENTS}" \"${line}\\n\"\n) +endforeach() + +# Revert the original semicolons in the source. +STRING(REGEX REPLACE "{{SEMICOLON}}" ";" CONTENTS "${CONTENTS}") get_filename_component(OUTPUT_DIR ${HEADER_FILE} DIRECTORY) make_directory(${OUTPUT_DIR}) diff --git a/src/video_core/host_shaders/source_shader.h.in b/src/video_core/host_shaders/source_shader.h.in index ccdb0d2a9..929dec39b 100644 --- a/src/video_core/host_shaders/source_shader.h.in +++ b/src/video_core/host_shaders/source_shader.h.in @@ -4,6 +4,8 @@ namespace HostShaders { -constexpr std::string_view @CONTENTS_NAME@ = R"(@CONTENTS@)"; +constexpr std::string_view @CONTENTS_NAME@ = { +@CONTENTS@ +}; } // namespace HostShaders -- cgit v1.2.3