diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | src/video_core/host_shaders/CMakeLists.txt | 43 | ||||
| -rw-r--r-- | src/video_core/host_shaders/StringShaderHeader.cmake | 11 | ||||
| -rw-r--r-- | src/video_core/host_shaders/opengl_present.frag | 10 | ||||
| -rw-r--r-- | src/video_core/host_shaders/opengl_present.vert | 24 | ||||
| -rw-r--r-- | src/video_core/host_shaders/source_shader.h.in | 9 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 46 |
7 files changed, 106 insertions, 42 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 3cd896a0f..d85f1e9d1 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | add_subdirectory(host_shaders) | ||
| 2 | |||
| 1 | add_library(video_core STATIC | 3 | add_library(video_core STATIC |
| 2 | buffer_cache/buffer_block.h | 4 | buffer_cache/buffer_block.h |
| 3 | buffer_cache/buffer_cache.h | 5 | buffer_cache/buffer_cache.h |
| @@ -244,6 +246,9 @@ create_target_directory_groups(video_core) | |||
| 244 | target_link_libraries(video_core PUBLIC common core) | 246 | target_link_libraries(video_core PUBLIC common core) |
| 245 | target_link_libraries(video_core PRIVATE glad xbyak) | 247 | target_link_libraries(video_core PRIVATE glad xbyak) |
| 246 | 248 | ||
| 249 | add_dependencies(video_core host_shaders) | ||
| 250 | target_include_directories(video_core PRIVATE ${HOST_SHADERS_INCLUDE}) | ||
| 251 | |||
| 247 | if (ENABLE_VULKAN) | 252 | if (ENABLE_VULKAN) |
| 248 | target_include_directories(video_core PRIVATE sirit ../../externals/Vulkan-Headers/include) | 253 | target_include_directories(video_core PRIVATE sirit ../../externals/Vulkan-Headers/include) |
| 249 | target_compile_definitions(video_core PRIVATE HAS_VULKAN) | 254 | target_compile_definitions(video_core PRIVATE HAS_VULKAN) |
diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt new file mode 100644 index 000000000..aa62363a7 --- /dev/null +++ b/src/video_core/host_shaders/CMakeLists.txt | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | set(SHADER_FILES | ||
| 2 | opengl_present.frag | ||
| 3 | opengl_present.vert | ||
| 4 | ) | ||
| 5 | |||
| 6 | set(SHADER_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/include) | ||
| 7 | set(HOST_SHADERS_INCLUDE ${SHADER_INCLUDE} PARENT_SCOPE) | ||
| 8 | |||
| 9 | set(SHADER_DIR ${SHADER_INCLUDE}/video_core/host_shaders) | ||
| 10 | add_custom_command( | ||
| 11 | OUTPUT | ||
| 12 | ${SHADER_DIR} | ||
| 13 | COMMAND | ||
| 14 | ${CMAKE_COMMAND} -E make_directory ${SHADER_DIR} | ||
| 15 | ) | ||
| 16 | |||
| 17 | set(INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/source_shader.h.in) | ||
| 18 | set(HEADER_GENERATOR ${CMAKE_CURRENT_SOURCE_DIR}/StringShaderHeader.cmake) | ||
| 19 | |||
| 20 | foreach(FILENAME IN ITEMS ${SHADER_FILES}) | ||
| 21 | string(REPLACE "." "_" SHADER_NAME ${FILENAME}) | ||
| 22 | set(SOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}) | ||
| 23 | set(HEADER_FILE ${SHADER_DIR}/${SHADER_NAME}.h) | ||
| 24 | add_custom_command( | ||
| 25 | OUTPUT | ||
| 26 | ${HEADER_FILE} | ||
| 27 | COMMAND | ||
| 28 | ${CMAKE_COMMAND} -P ${HEADER_GENERATOR} ${SOURCE_FILE} ${HEADER_FILE} ${INPUT_FILE} | ||
| 29 | MAIN_DEPENDENCY | ||
| 30 | ${SOURCE_FILE} | ||
| 31 | DEPENDS | ||
| 32 | ${HEADER_GENERATOR} | ||
| 33 | ${INPUT_FILE} | ||
| 34 | ) | ||
| 35 | set(SHADER_HEADERS ${SHADER_HEADERS} ${HEADER_FILE}) | ||
| 36 | endforeach() | ||
| 37 | |||
| 38 | add_custom_target(host_shaders | ||
| 39 | DEPENDS | ||
| 40 | ${SHADER_HEADERS} | ||
| 41 | SOURCES | ||
| 42 | ${SHADER_FILES} | ||
| 43 | ) | ||
diff --git a/src/video_core/host_shaders/StringShaderHeader.cmake b/src/video_core/host_shaders/StringShaderHeader.cmake new file mode 100644 index 000000000..368bce0ed --- /dev/null +++ b/src/video_core/host_shaders/StringShaderHeader.cmake | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | set(SOURCE_FILE ${CMAKE_ARGV3}) | ||
| 2 | set(HEADER_FILE ${CMAKE_ARGV4}) | ||
| 3 | set(INPUT_FILE ${CMAKE_ARGV5}) | ||
| 4 | |||
| 5 | get_filename_component(CONTENTS_NAME ${SOURCE_FILE} NAME) | ||
| 6 | string(REPLACE "." "_" CONTENTS_NAME ${CONTENTS_NAME}) | ||
| 7 | string(TOUPPER ${CONTENTS_NAME} CONTENTS_NAME) | ||
| 8 | |||
| 9 | file(READ ${SOURCE_FILE} CONTENTS) | ||
| 10 | |||
| 11 | configure_file(${INPUT_FILE} ${HEADER_FILE} @ONLY) | ||
diff --git a/src/video_core/host_shaders/opengl_present.frag b/src/video_core/host_shaders/opengl_present.frag new file mode 100644 index 000000000..8a4cb024b --- /dev/null +++ b/src/video_core/host_shaders/opengl_present.frag | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #version 430 core | ||
| 2 | |||
| 3 | layout (location = 0) in vec2 frag_tex_coord; | ||
| 4 | layout (location = 0) out vec4 color; | ||
| 5 | |||
| 6 | layout (binding = 0) uniform sampler2D color_texture; | ||
| 7 | |||
| 8 | void main() { | ||
| 9 | color = vec4(texture(color_texture, frag_tex_coord).rgb, 1.0f); | ||
| 10 | } | ||
diff --git a/src/video_core/host_shaders/opengl_present.vert b/src/video_core/host_shaders/opengl_present.vert new file mode 100644 index 000000000..2235d31a4 --- /dev/null +++ b/src/video_core/host_shaders/opengl_present.vert | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #version 430 core | ||
| 2 | |||
| 3 | out gl_PerVertex { | ||
| 4 | vec4 gl_Position; | ||
| 5 | }; | ||
| 6 | |||
| 7 | layout (location = 0) in vec2 vert_position; | ||
| 8 | layout (location = 1) in vec2 vert_tex_coord; | ||
| 9 | layout (location = 0) out vec2 frag_tex_coord; | ||
| 10 | |||
| 11 | // This is a truncated 3x3 matrix for 2D transformations: | ||
| 12 | // The upper-left 2x2 submatrix performs scaling/rotation/mirroring. | ||
| 13 | // The third column performs translation. | ||
| 14 | // The third row could be used for projection, which we don't need in 2D. It hence is assumed to | ||
| 15 | // implicitly be [0, 0, 1] | ||
| 16 | layout (location = 0) uniform mat3x2 modelview_matrix; | ||
| 17 | |||
| 18 | void main() { | ||
| 19 | // Multiply input position by the rotscale part of the matrix and then manually translate by | ||
| 20 | // the last column. This is equivalent to using a full 3x3 matrix and expanding the vector | ||
| 21 | // to `vec3(vert_position.xy, 1.0)` | ||
| 22 | gl_Position = vec4(mat2(modelview_matrix) * vert_position + modelview_matrix[2], 0.0, 1.0); | ||
| 23 | frag_tex_coord = vert_tex_coord; | ||
| 24 | } | ||
diff --git a/src/video_core/host_shaders/source_shader.h.in b/src/video_core/host_shaders/source_shader.h.in new file mode 100644 index 000000000..ccdb0d2a9 --- /dev/null +++ b/src/video_core/host_shaders/source_shader.h.in | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <string_view> | ||
| 4 | |||
| 5 | namespace HostShaders { | ||
| 6 | |||
| 7 | constexpr std::string_view @CONTENTS_NAME@ = R"(@CONTENTS@)"; | ||
| 8 | |||
| 9 | } // namespace HostShaders | ||
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 14bbc3a1c..4a13f37d7 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp | |||
| @@ -21,6 +21,8 @@ | |||
| 21 | #include "core/perf_stats.h" | 21 | #include "core/perf_stats.h" |
| 22 | #include "core/settings.h" | 22 | #include "core/settings.h" |
| 23 | #include "core/telemetry_session.h" | 23 | #include "core/telemetry_session.h" |
| 24 | #include "video_core/host_shaders/opengl_present_frag.h" | ||
| 25 | #include "video_core/host_shaders/opengl_present_vert.h" | ||
| 24 | #include "video_core/morton.h" | 26 | #include "video_core/morton.h" |
| 25 | #include "video_core/renderer_opengl/gl_rasterizer.h" | 27 | #include "video_core/renderer_opengl/gl_rasterizer.h" |
| 26 | #include "video_core/renderer_opengl/gl_shader_manager.h" | 28 | #include "video_core/renderer_opengl/gl_shader_manager.h" |
| @@ -44,46 +46,6 @@ struct Frame { | |||
| 44 | bool is_srgb{}; /// Framebuffer is sRGB or RGB | 46 | bool is_srgb{}; /// Framebuffer is sRGB or RGB |
| 45 | }; | 47 | }; |
| 46 | 48 | ||
| 47 | constexpr char VERTEX_SHADER[] = R"( | ||
| 48 | #version 430 core | ||
| 49 | |||
| 50 | out gl_PerVertex { | ||
| 51 | vec4 gl_Position; | ||
| 52 | }; | ||
| 53 | |||
| 54 | layout (location = 0) in vec2 vert_position; | ||
| 55 | layout (location = 1) in vec2 vert_tex_coord; | ||
| 56 | layout (location = 0) out vec2 frag_tex_coord; | ||
| 57 | |||
| 58 | // This is a truncated 3x3 matrix for 2D transformations: | ||
| 59 | // The upper-left 2x2 submatrix performs scaling/rotation/mirroring. | ||
| 60 | // The third column performs translation. | ||
| 61 | // The third row could be used for projection, which we don't need in 2D. It hence is assumed to | ||
| 62 | // implicitly be [0, 0, 1] | ||
| 63 | layout (location = 0) uniform mat3x2 modelview_matrix; | ||
| 64 | |||
| 65 | void main() { | ||
| 66 | // Multiply input position by the rotscale part of the matrix and then manually translate by | ||
| 67 | // the last column. This is equivalent to using a full 3x3 matrix and expanding the vector | ||
| 68 | // to `vec3(vert_position.xy, 1.0)` | ||
| 69 | gl_Position = vec4(mat2(modelview_matrix) * vert_position + modelview_matrix[2], 0.0, 1.0); | ||
| 70 | frag_tex_coord = vert_tex_coord; | ||
| 71 | } | ||
| 72 | )"; | ||
| 73 | |||
| 74 | constexpr char FRAGMENT_SHADER[] = R"( | ||
| 75 | #version 430 core | ||
| 76 | |||
| 77 | layout (location = 0) in vec2 frag_tex_coord; | ||
| 78 | layout (location = 0) out vec4 color; | ||
| 79 | |||
| 80 | layout (binding = 0) uniform sampler2D color_texture; | ||
| 81 | |||
| 82 | void main() { | ||
| 83 | color = vec4(texture(color_texture, frag_tex_coord).rgb, 1.0f); | ||
| 84 | } | ||
| 85 | )"; | ||
| 86 | |||
| 87 | constexpr GLint PositionLocation = 0; | 49 | constexpr GLint PositionLocation = 0; |
| 88 | constexpr GLint TexCoordLocation = 1; | 50 | constexpr GLint TexCoordLocation = 1; |
| 89 | constexpr GLint ModelViewMatrixLocation = 0; | 51 | constexpr GLint ModelViewMatrixLocation = 0; |
| @@ -460,10 +422,10 @@ void RendererOpenGL::InitOpenGLObjects() { | |||
| 460 | 422 | ||
| 461 | // Create shader programs | 423 | // Create shader programs |
| 462 | OGLShader vertex_shader; | 424 | OGLShader vertex_shader; |
| 463 | vertex_shader.Create(VERTEX_SHADER, GL_VERTEX_SHADER); | 425 | vertex_shader.Create(HostShaders::OPENGL_PRESENT_VERT, GL_VERTEX_SHADER); |
| 464 | 426 | ||
| 465 | OGLShader fragment_shader; | 427 | OGLShader fragment_shader; |
| 466 | fragment_shader.Create(FRAGMENT_SHADER, GL_FRAGMENT_SHADER); | 428 | fragment_shader.Create(HostShaders::OPENGL_PRESENT_FRAG, GL_FRAGMENT_SHADER); |
| 467 | 429 | ||
| 468 | vertex_program.Create(true, false, vertex_shader.handle); | 430 | vertex_program.Create(true, false, vertex_shader.handle); |
| 469 | fragment_program.Create(true, false, fragment_shader.handle); | 431 | fragment_program.Create(true, false, fragment_shader.handle); |