From 733a152c542c37d127f3d7a50687e085d35116d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 4 Nov 2020 09:18:35 +0100 Subject: [PATCH 1/2] Move ShaderWriter to Common/GPU, along with some stuff from ShaderCommon.h. --- CMakeLists.txt | 6 ++-- Common/Common.vcxproj | 4 +++ Common/Common.vcxproj.filters | 12 +++++++ Common/GPU/Shader.cpp | 1 + Common/GPU/Shader.h | 40 +++++++++++++++++++++ {GPU/Common => Common/GPU}/ShaderWriter.cpp | 7 +++- {GPU/Common => Common/GPU}/ShaderWriter.h | 6 ++-- GPU/Common/DepalettizeShaderCommon.h | 5 +-- GPU/Common/FragmentShaderGenerator.cpp | 2 +- GPU/Common/FragmentShaderGenerator.h | 2 +- GPU/Common/PresentationCommon.h | 2 +- GPU/Common/ShaderCommon.cpp | 3 +- GPU/Common/ShaderCommon.h | 39 -------------------- GPU/Common/ShaderTranslation.cpp | 1 + GPU/Common/ShaderTranslation.h | 3 +- GPU/Common/VertexShaderGenerator.cpp | 4 +-- GPU/Common/VertexShaderGenerator.h | 3 ++ GPU/GLES/ShaderManagerGLES.cpp | 1 + GPU/GPU.vcxproj | 2 -- GPU/GPU.vcxproj.filters | 6 ---- UWP/CommonUWP/CommonUWP.vcxproj | 4 +++ UWP/CommonUWP/CommonUWP.vcxproj.filters | 12 +++++++ UWP/GPU_UWP/GPU_UWP.vcxproj | 2 -- UWP/GPU_UWP/GPU_UWP.vcxproj.filters | 2 -- android/jni/Android.mk | 3 +- libretro/Makefile.common | 3 +- 26 files changed, 107 insertions(+), 68 deletions(-) create mode 100644 Common/GPU/Shader.cpp create mode 100644 Common/GPU/Shader.h rename {GPU/Common => Common/GPU}/ShaderWriter.cpp (96%) rename {GPU/Common => Common/GPU}/ShaderWriter.h (93%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f9f5ee4e1..ce37815473 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -496,6 +496,10 @@ add_library(Common STATIC Common/GPU/thin3d.cpp Common/GPU/thin3d.h Common/GPU/thin3d_create.h + Common/GPU/Shader.cpp + Common/GPU/Shader.h + Common/GPU/ShaderWriter.cpp + Common/GPU/ShaderWriter.h Common/GPU/OpenGL/GLCommon.h Common/GPU/OpenGL/GLDebugLog.cpp Common/GPU/OpenGL/GLDebugLog.h @@ -1356,8 +1360,6 @@ set(GPU_SOURCES GPU/Common/ShaderUniforms.h GPU/Common/ShaderCommon.cpp GPU/Common/ShaderCommon.h - GPU/Common/ShaderWriter.cpp - GPU/Common/ShaderWriter.h GPU/Common/ShaderTranslation.cpp GPU/Common/ShaderTranslation.h GPU/Common/SplineCommon.cpp diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index 0bb5e7ef50..f3ebb5328d 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -428,6 +428,8 @@ + + @@ -749,6 +751,8 @@ + + diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index 5cc1151375..0d11399460 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -375,6 +375,12 @@ Data\Collections + + GPU + + + GPU + @@ -723,6 +729,12 @@ Render\Text + + GPU + + + GPU + diff --git a/Common/GPU/Shader.cpp b/Common/GPU/Shader.cpp new file mode 100644 index 0000000000..79684874c3 --- /dev/null +++ b/Common/GPU/Shader.cpp @@ -0,0 +1 @@ +#include "Common/GPU/Shader.h" diff --git a/Common/GPU/Shader.h b/Common/GPU/Shader.h new file mode 100644 index 0000000000..1ed1685dde --- /dev/null +++ b/Common/GPU/Shader.h @@ -0,0 +1,40 @@ +#pragma once + +enum ShaderLanguage { + GLSL_140, // really covers a lot more. This set of languages is not good. + GLSL_300, + GLSL_VULKAN, + HLSL_D3D9, + HLSL_D3D11, +}; + +inline bool ShaderLanguageIsOpenGL(ShaderLanguage lang) { + return lang == GLSL_140 || lang == GLSL_300; +} + +enum class ShaderStage { + Vertex, + Fragment +}; + +struct ShaderLanguageDesc { + explicit ShaderLanguageDesc(ShaderLanguage lang); + + int glslVersionNumber = 0; + ShaderLanguage shaderLanguage; + bool gles = false; + const char *varying_fs = nullptr; + const char *varying_vs = nullptr; + const char *attribute = nullptr; + const char *fragColor0 = nullptr; + const char *fragColor1 = nullptr; + const char *texture = nullptr; + const char *texelFetch = nullptr; + const char *lastFragData = nullptr; + const char *framebufferFetchExtension = nullptr; + const char *vsOutPrefix = ""; + bool glslES30 = false; + bool bitwiseOps = false; + bool forceMatrix4x4 = false; + bool coefsFromBuffers = false; +}; diff --git a/GPU/Common/ShaderWriter.cpp b/Common/GPU/ShaderWriter.cpp similarity index 96% rename from GPU/Common/ShaderWriter.cpp rename to Common/GPU/ShaderWriter.cpp index 44959b57fe..cebb0d017a 100644 --- a/GPU/Common/ShaderWriter.cpp +++ b/Common/GPU/ShaderWriter.cpp @@ -1,4 +1,9 @@ -#include "GPU/Common/ShaderWriter.h" +#include +#include +#include + +#include "Common/GPU/Shader.h" +#include "Common/GPU/ShaderWriter.h" const char *vulkan_glsl_preamble_fs = "#version 450\n" diff --git a/GPU/Common/ShaderWriter.h b/Common/GPU/ShaderWriter.h similarity index 93% rename from GPU/Common/ShaderWriter.h rename to Common/GPU/ShaderWriter.h index 7a060c6732..d870f72fe4 100644 --- a/GPU/Common/ShaderWriter.h +++ b/Common/GPU/ShaderWriter.h @@ -1,9 +1,9 @@ #pragma once +#include + #include "Common/Log.h" -#include "GPU/ge_constants.h" -#include "GPU/GPUCommon.h" -#include "GPU/Common/ShaderCommon.h" +#include "Common/GPU/Shader.h" // Helps generate a shader compatible with all backends. // Using #defines and magic in this class, we partially define our own shader language that basically looks diff --git a/GPU/Common/DepalettizeShaderCommon.h b/GPU/Common/DepalettizeShaderCommon.h index 3520fded93..75a46c67ad 100644 --- a/GPU/Common/DepalettizeShaderCommon.h +++ b/GPU/Common/DepalettizeShaderCommon.h @@ -18,8 +18,9 @@ #pragma once #include + +#include "Common/GPU/Shader.h" #include "GPU/ge_constants.h" -#include "GPU/Common/ShaderCommon.h" static const int DEPAL_TEXTURE_OLD_AGE = 120; @@ -32,4 +33,4 @@ public: protected: uint32_t GenerateShaderID(uint32_t clutMode, GEBufferFormat pixelFormat) const; uint32_t GetClutID(GEPaletteFormat clutFormat, uint32_t clutHash) const; -}; \ No newline at end of file +}; diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index 676d3b602e..10b34cf167 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -21,13 +21,13 @@ #include "Common/Log.h" #include "Common/StringUtils.h" #include "Common/GPU/OpenGL/GLFeatures.h" +#include "Common/GPU/ShaderWriter.h" #include "Core/Reporting.h" #include "Core/Config.h" #include "GPU/Common/GPUStateUtils.h" #include "GPU/Common/ShaderId.h" #include "GPU/Common/ShaderUniforms.h" #include "GPU/Common/FragmentShaderGenerator.h" -#include "GPU/Common/ShaderWriter.h" #include "GPU/ge_constants.h" #include "GPU/GPUState.h" diff --git a/GPU/Common/FragmentShaderGenerator.h b/GPU/Common/FragmentShaderGenerator.h index 7c75e35c2f..2e27d165d0 100644 --- a/GPU/Common/FragmentShaderGenerator.h +++ b/GPU/Common/FragmentShaderGenerator.h @@ -17,7 +17,7 @@ #pragma once -#include "GPU/Common/ShaderCommon.h" +#include "Common/GPU/Shader.h" struct FShaderID; diff --git a/GPU/Common/PresentationCommon.h b/GPU/Common/PresentationCommon.h index 7acce4083a..2616e2dfd5 100644 --- a/GPU/Common/PresentationCommon.h +++ b/GPU/Common/PresentationCommon.h @@ -17,7 +17,7 @@ #pragma once -#include "GPU/Common/ShaderCommon.h" +#include "Common/GPU/Shader.h" struct CardboardSettings { bool enabled; diff --git a/GPU/Common/ShaderCommon.cpp b/GPU/Common/ShaderCommon.cpp index 1f13458b93..190270cd3b 100644 --- a/GPU/Common/ShaderCommon.cpp +++ b/GPU/Common/ShaderCommon.cpp @@ -4,7 +4,8 @@ #include "ext/glslang/SPIRV/GlslangToSpv.h" -#include "ShaderCommon.h" +#include "Common/GPU/Shader.h" +#include "GPU/Common/ShaderCommon.h" void init_resources(TBuiltInResource &Resources) { Resources.maxLights = 32; diff --git a/GPU/Common/ShaderCommon.h b/GPU/Common/ShaderCommon.h index e238bd9dc6..4d5a41f077 100644 --- a/GPU/Common/ShaderCommon.h +++ b/GPU/Common/ShaderCommon.h @@ -24,18 +24,6 @@ namespace Draw { class DrawContext; } -enum ShaderLanguage { - GLSL_140, // really covers a lot more. This set of languages is not good. - GLSL_300, - GLSL_VULKAN, - HLSL_D3D9, - HLSL_D3D11, -}; - -inline bool ShaderLanguageIsOpenGL(ShaderLanguage lang) { - return lang == GLSL_140 || lang == GLSL_300; -} - enum DebugShaderType { SHADER_TYPE_VERTEX = 0, SHADER_TYPE_FRAGMENT = 1, @@ -52,11 +40,6 @@ enum DebugShaderStringType { SHADER_STRING_STATS = 2, }; -enum class ShaderStage { - Vertex, - Fragment -}; - // Shared between the backends. Not all are necessarily used by each backend, but this lets us share // more code than before. enum : uint64_t { @@ -147,28 +130,6 @@ enum DoLightComputation { LIGHT_FULL, }; -struct ShaderLanguageDesc { - explicit ShaderLanguageDesc(ShaderLanguage lang); - - int glslVersionNumber = 0; - ShaderLanguage shaderLanguage; - bool gles = false; - const char *varying_fs = nullptr; - const char *varying_vs = nullptr; - const char *attribute = nullptr; - const char *fragColor0 = nullptr; - const char *fragColor1 = nullptr; - const char *texture = nullptr; - const char *texelFetch = nullptr; - const char *lastFragData = nullptr; - const char *framebufferFetchExtension = nullptr; - const char *vsOutPrefix = ""; - bool glslES30 = false; - bool bitwiseOps = false; - bool forceMatrix4x4 = false; - bool coefsFromBuffers = false; -}; - // PSP vertex format. enum class PspAttributeLocation { POSITION = 0, diff --git a/GPU/Common/ShaderTranslation.cpp b/GPU/Common/ShaderTranslation.cpp index 8e4b7c27bb..936cdc2560 100644 --- a/GPU/Common/ShaderTranslation.cpp +++ b/GPU/Common/ShaderTranslation.cpp @@ -36,6 +36,7 @@ #include "Common/Log.h" #include "Common/StringUtils.h" +#include "Common/GPU/Shader.h" #include "GPU/Common/ShaderTranslation.h" #include "ext/glslang/SPIRV/GlslangToSpv.h" diff --git a/GPU/Common/ShaderTranslation.h b/GPU/Common/ShaderTranslation.h index 9d4e41e3f1..e5f92d8ef8 100644 --- a/GPU/Common/ShaderTranslation.h +++ b/GPU/Common/ShaderTranslation.h @@ -18,7 +18,8 @@ #pragma once #include -#include "GPU/Common/ShaderCommon.h" + +#include "Common/GPU/Shader.h" #include "Common/GPU/thin3d.h" struct TranslatedShaderMetadata { diff --git a/GPU/Common/VertexShaderGenerator.cpp b/GPU/Common/VertexShaderGenerator.cpp index da781e111a..a36259ac55 100644 --- a/GPU/Common/VertexShaderGenerator.cpp +++ b/GPU/Common/VertexShaderGenerator.cpp @@ -19,14 +19,14 @@ #include #include -#include "Common/GPU/OpenGL/GLFeatures.h" #include "Common/StringUtils.h" +#include "Common/GPU/OpenGL/GLFeatures.h" +#include "Common/GPU/ShaderWriter.h" #include "Core/Config.h" #include "GPU/ge_constants.h" #include "GPU/GPUState.h" #include "GPU/Common/ShaderId.h" #include "GPU/Common/ShaderUniforms.h" -#include "GPU/Common/ShaderWriter.h" #include "GPU/Common/VertexDecoderCommon.h" #include "GPU/Common/VertexShaderGenerator.h" diff --git a/GPU/Common/VertexShaderGenerator.h b/GPU/Common/VertexShaderGenerator.h index 8f69f5bcd8..df62f76289 100644 --- a/GPU/Common/VertexShaderGenerator.h +++ b/GPU/Common/VertexShaderGenerator.h @@ -17,7 +17,10 @@ #pragma once +#include + #include "Common/CommonTypes.h" +#include "Common/GPU/Shader.h" struct VShaderID; diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index 7e77133a85..ba8539f4ee 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -30,6 +30,7 @@ #include "Common/Math/math_util.h" #include "Common/Math/lin/matrix4x4.h" #include "Common/Profiler/Profiler.h" +#include "Common/GPU/Shader.h" #include "Common/GPU/thin3d.h" #include "Common/GPU/OpenGL/GLRenderManager.h" diff --git a/GPU/GPU.vcxproj b/GPU/GPU.vcxproj index bb7bb6980f..675602d6d5 100644 --- a/GPU/GPU.vcxproj +++ b/GPU/GPU.vcxproj @@ -351,7 +351,6 @@ - @@ -489,7 +488,6 @@ - diff --git a/GPU/GPU.vcxproj.filters b/GPU/GPU.vcxproj.filters index c19594763f..509e962588 100644 --- a/GPU/GPU.vcxproj.filters +++ b/GPU/GPU.vcxproj.filters @@ -270,9 +270,6 @@ Common - - Common - @@ -542,8 +539,5 @@ Common - - Common - \ No newline at end of file diff --git a/UWP/CommonUWP/CommonUWP.vcxproj b/UWP/CommonUWP/CommonUWP.vcxproj index e8d56b3ab6..56f207c60f 100644 --- a/UWP/CommonUWP/CommonUWP.vcxproj +++ b/UWP/CommonUWP/CommonUWP.vcxproj @@ -419,6 +419,8 @@ + + @@ -536,6 +538,8 @@ + + diff --git a/UWP/CommonUWP/CommonUWP.vcxproj.filters b/UWP/CommonUWP/CommonUWP.vcxproj.filters index 7576f5735f..8c7551735d 100644 --- a/UWP/CommonUWP/CommonUWP.vcxproj.filters +++ b/UWP/CommonUWP/CommonUWP.vcxproj.filters @@ -363,6 +363,12 @@ Render\Text + + GPU + + + GPU + @@ -662,6 +668,12 @@ Data\Collections + + GPU + + + GPU + diff --git a/UWP/GPU_UWP/GPU_UWP.vcxproj b/UWP/GPU_UWP/GPU_UWP.vcxproj index aef600ae34..d5b5d3167e 100644 --- a/UWP/GPU_UWP/GPU_UWP.vcxproj +++ b/UWP/GPU_UWP/GPU_UWP.vcxproj @@ -392,7 +392,6 @@ - @@ -450,7 +449,6 @@ - diff --git a/UWP/GPU_UWP/GPU_UWP.vcxproj.filters b/UWP/GPU_UWP/GPU_UWP.vcxproj.filters index c1e17c829d..12f33ec3af 100644 --- a/UWP/GPU_UWP/GPU_UWP.vcxproj.filters +++ b/UWP/GPU_UWP/GPU_UWP.vcxproj.filters @@ -57,7 +57,6 @@ - @@ -115,6 +114,5 @@ - \ No newline at end of file diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 4498059207..845f3ca441 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -252,6 +252,8 @@ EXEC_AND_LIB_FILES := \ $(SRC)/Common/File/DirListing.cpp \ $(SRC)/Common/File/FileDescriptor.cpp \ $(SRC)/Common/GPU/thin3d.cpp \ + $(SRC)/Common/GPU/Shader.cpp \ + $(SRC)/Common/GPU/ShaderWriter.cpp \ $(SRC)/Common/Render/DrawBuffer.cpp \ $(SRC)/Common/Render/TextureAtlas.cpp \ $(SRC)/Common/Render/Text/draw_text.cpp \ @@ -318,7 +320,6 @@ EXEC_AND_LIB_FILES := \ $(SRC)/GPU/Common/TextureCacheCommon.cpp.arm \ $(SRC)/GPU/Common/TextureScalerCommon.cpp.arm \ $(SRC)/GPU/Common/ShaderCommon.cpp \ - $(SRC)/GPU/Common/ShaderWriter.cpp \ $(SRC)/GPU/Common/ShaderTranslation.cpp \ $(SRC)/GPU/Common/StencilCommon.cpp \ $(SRC)/GPU/Common/SplineCommon.cpp.arm \ diff --git a/libretro/Makefile.common b/libretro/Makefile.common index bd03911b48..15620ed2b6 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -166,6 +166,8 @@ SOURCES_CXX += \ $(COMMONDIR)/File/FileDescriptor.cpp \ $(COMMONDIR)/File/DirListing.cpp \ $(COMMONDIR)/GPU/thin3d.cpp \ + $(COMMONDIR)/GPU/Shader.cpp \ + $(COMMONDIR)/GPU/ShaderWriter.cpp \ $(COMMONDIR)/GPU/OpenGL/thin3d_gl.cpp \ $(COMMONDIR)/GPU/OpenGL/GLDebugLog.cpp \ $(COMMONDIR)/GPU/OpenGL/GLSLProgram.cpp \ @@ -236,7 +238,6 @@ SOURCES_CXX += \ $(GPUCOMMONDIR)/ShaderCommon.cpp \ $(GPUCOMMONDIR)/ShaderUniforms.cpp \ $(GPUCOMMONDIR)/ShaderTranslation.cpp \ - $(GPUCOMMONDIR)/ShaderWriter.cpp \ $(GPUCOMMONDIR)/GPUDebugInterface.cpp \ $(GPUCOMMONDIR)/DepalettizeShaderCommon.cpp \ $(GPUCOMMONDIR)/TransformCommon.cpp \ From 03e8eac6efb7c101f46b10aca7de08421440a9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 4 Nov 2020 09:40:11 +0100 Subject: [PATCH 2/2] Merge the two ShaderLanguage enums. --- Common/GPU/OpenGL/thin3d_gl.cpp | 12 ++++++----- Common/GPU/Shader.h | 15 ++++++++------ Common/GPU/thin3d.cpp | 10 ++++----- Common/GPU/thin3d.h | 12 ++--------- GPU/Common/DepalettizeShaderCommon.cpp | 6 +++--- GPU/Common/PresentationCommon.cpp | 28 +++----------------------- GPU/Common/ShaderCommon.cpp | 4 ++-- GPU/Common/ShaderTranslation.cpp | 8 ++++---- GPU/GLES/DepalettizeShaderGLES.cpp | 2 +- GPU/GLES/FramebufferManagerGLES.cpp | 2 +- GPU/GLES/ShaderManagerGLES.cpp | 12 +++++------ GPU/Software/SoftGpu.cpp | 2 +- UI/GPUDriverTestScreen.cpp | 5 +++-- unittest/TestShaderGenerators.cpp | 24 +++++++++++----------- 14 files changed, 59 insertions(+), 83 deletions(-) diff --git a/Common/GPU/OpenGL/thin3d_gl.cpp b/Common/GPU/OpenGL/thin3d_gl.cpp index a58432e14b..be13d312e8 100644 --- a/Common/GPU/OpenGL/thin3d_gl.cpp +++ b/Common/GPU/OpenGL/thin3d_gl.cpp @@ -8,6 +8,7 @@ #include "Common/Math/math_util.h" #include "Common/Math/lin/matrix4x4.h" #include "Common/GPU/thin3d.h" +#include "Common/GPU/Shader.h" #include "Common/GPU/OpenGL/DataFormatGL.h" #include "Common/GPU/OpenGL/GLCommon.h" #include "Common/GPU/OpenGL/GLDebugLog.h" @@ -254,7 +255,7 @@ public: private: GLRenderManager *render_; ShaderStage stage_; - ShaderLanguage language_ = ShaderLanguage::GLSL_ES_200; + ShaderLanguage language_ = GLSL_1xx; GLRShader *shader_ = nullptr; GLuint glstage_ = 0; std::string source_; // So we can recompile in case of context loss. @@ -345,10 +346,11 @@ public: return caps_; } uint32_t GetSupportedShaderLanguages() const override { - if (gl_extensions.IsGLES) - return (uint32_t)ShaderLanguage::GLSL_ES_200 | (uint32_t)ShaderLanguage::GLSL_ES_300; - else - return (uint32_t)ShaderLanguage::GLSL_ES_200 | (uint32_t)ShaderLanguage::GLSL_410; + if (gl_extensions.GLES3) { + return (uint32_t)(ShaderLanguage::GLSL_3xx | ShaderLanguage::GLSL_1xx); + } else { + return (uint32_t)ShaderLanguage::GLSL_1xx; + } } uint32_t GetDataFormatSupport(DataFormat fmt) const override; diff --git a/Common/GPU/Shader.h b/Common/GPU/Shader.h index 1ed1685dde..9457a8461b 100644 --- a/Common/GPU/Shader.h +++ b/Common/GPU/Shader.h @@ -1,15 +1,18 @@ #pragma once +// GLSL_1xx and GLSL_3xx each cover a lot of sub variants. All the little quirks +// that differ are covered in ShaderLanguageDesc. +// Defined as a bitmask so stuff like GetSupportedShaderLanguages can return combinations. enum ShaderLanguage { - GLSL_140, // really covers a lot more. This set of languages is not good. - GLSL_300, - GLSL_VULKAN, - HLSL_D3D9, - HLSL_D3D11, + GLSL_1xx = 1, + GLSL_3xx = 2, + GLSL_VULKAN = 4, + HLSL_D3D9 = 8, + HLSL_D3D11 = 16, }; inline bool ShaderLanguageIsOpenGL(ShaderLanguage lang) { - return lang == GLSL_140 || lang == GLSL_300; + return lang == GLSL_1xx || lang == GLSL_3xx; } enum class ShaderStage { diff --git a/Common/GPU/thin3d.cpp b/Common/GPU/thin3d.cpp index 95dce26147..0c1b8917a1 100644 --- a/Common/GPU/thin3d.cpp +++ b/Common/GPU/thin3d.cpp @@ -101,7 +101,7 @@ bool RefCountedObject::ReleaseAssertLast() { // The Vulkan ones can be re-used with modern GL later if desired, as they're just GLSL. static const std::vector fsTexCol = { - {ShaderLanguage::GLSL_ES_200, + {ShaderLanguage::GLSL_1xx, "#ifdef GL_ES\n" "precision lowp float;\n" "#endif\n" @@ -145,7 +145,7 @@ static const std::vector fsTexCol = { }; static const std::vector fsTexColRBSwizzle = { - {ShaderLanguage::GLSL_ES_200, + {GLSL_1xx, "#ifdef GL_ES\n" "precision lowp float;\n" "#endif\n" @@ -189,7 +189,7 @@ static const std::vector fsTexColRBSwizzle = { }; static const std::vector fsCol = { - { ShaderLanguage::GLSL_ES_200, + { GLSL_1xx, "#ifdef GL_ES\n" "precision lowp float;\n" "#endif\n" @@ -226,7 +226,7 @@ static const std::vector fsCol = { // ================================== VERTEX SHADERS static const std::vector vsCol = { - { ShaderLanguage::GLSL_ES_200, + { GLSL_1xx, "#if __VERSION__ >= 130\n" "#define attribute in\n" "#define varying out\n" @@ -288,7 +288,7 @@ const UniformBufferDesc vsColBufDesc { sizeof(VsColUB), { } }; static const std::vector vsTexCol = { - { ShaderLanguage::GLSL_ES_200, + { GLSL_1xx, "#if __VERSION__ >= 130\n" "#define attribute in\n" "#define varying out\n" diff --git a/Common/GPU/thin3d.h b/Common/GPU/thin3d.h index e3f6390afe..8aeaa819b2 100644 --- a/Common/GPU/thin3d.h +++ b/Common/GPU/thin3d.h @@ -12,7 +12,8 @@ #include #include -#include "DataFormat.h" +#include "Common/GPU/DataFormat.h" +#include "Common/GPU/Shader.h" namespace Lin { class Matrix4x4; @@ -203,15 +204,6 @@ enum class TextureAddressMode { CLAMP_TO_BORDER, }; -enum class ShaderLanguage { - GLSL_ES_200 = 1, - GLSL_ES_300 = 2, - GLSL_410 = 4, - GLSL_VULKAN = 8, - HLSL_D3D9 = 32, - HLSL_D3D11 = 64, -}; - enum FormatSupport { FMT_RENDERTARGET = 1, FMT_TEXTURE = 2, diff --git a/GPU/Common/DepalettizeShaderCommon.cpp b/GPU/Common/DepalettizeShaderCommon.cpp index 516c3b9fde..11236f1f9a 100644 --- a/GPU/Common/DepalettizeShaderCommon.cpp +++ b/GPU/Common/DepalettizeShaderCommon.cpp @@ -286,7 +286,7 @@ void GenerateDepalShaderFloat(char *buffer, GEBufferFormat pixelFormat, ShaderLa float texel_offset = ((float)clutBase + 0.5f) / texturePixels; sprintf(offset, " + %f", texel_offset); - if (lang == GLSL_140) { + if (lang == GLSL_1xx) { if (gl_extensions.IsGLES) { WRITE(p, "#version 100\n"); WRITE(p, "precision mediump float;\n"); @@ -318,10 +318,10 @@ void GenerateDepalShaderFloat(char *buffer, GEBufferFormat pixelFormat, ShaderLa void GenerateDepalShader(char *buffer, GEBufferFormat pixelFormat, ShaderLanguage language) { switch (language) { - case GLSL_140: + case GLSL_1xx: GenerateDepalShaderFloat(buffer, pixelFormat, language); break; - case GLSL_300: + case GLSL_3xx: case GLSL_VULKAN: case HLSL_D3D11: GenerateDepalShader300(buffer, pixelFormat, language); diff --git a/GPU/Common/PresentationCommon.cpp b/GPU/Common/PresentationCommon.cpp index c359922085..7636619e24 100644 --- a/GPU/Common/PresentationCommon.cpp +++ b/GPU/Common/PresentationCommon.cpp @@ -240,8 +240,8 @@ bool PresentationCommon::BuildPostShader(const ShaderInfo *shaderInfo, const Sha } std::string vsError, fsError; - Draw::ShaderModule *vs = CompileShaderModule(Draw::ShaderStage::VERTEX, GLSL_140, vsSourceGLSL, &vsError); - Draw::ShaderModule *fs = CompileShaderModule(Draw::ShaderStage::FRAGMENT, GLSL_140, fsSourceGLSL, &fsError); + Draw::ShaderModule *vs = CompileShaderModule(Draw::ShaderStage::VERTEX, GLSL_1xx, vsSourceGLSL, &vsError); + Draw::ShaderModule *fs = CompileShaderModule(Draw::ShaderStage::FRAGMENT, GLSL_1xx, fsSourceGLSL, &fsError); // Don't worry, CompileShaderModule makes sure they get freed if one succeeded. if (!fs || !vs) { @@ -476,29 +476,7 @@ Draw::ShaderModule *PresentationCommon::CompileShaderModule(Draw::ShaderStage st } } - Draw::ShaderLanguage mappedLang; - // These aren't exact, unfortunately, but we just need the type Draw will accept. - switch (lang_) { - case GLSL_140: - mappedLang = Draw::ShaderLanguage::GLSL_ES_200; - break; - case GLSL_300: - mappedLang = Draw::ShaderLanguage::GLSL_410; - break; - case GLSL_VULKAN: - mappedLang = Draw::ShaderLanguage::GLSL_VULKAN; - break; - case HLSL_D3D9: - mappedLang = Draw::ShaderLanguage::HLSL_D3D9; - break; - case HLSL_D3D11: - mappedLang = Draw::ShaderLanguage::HLSL_D3D11; - break; - default: - mappedLang = Draw::ShaderLanguage::GLSL_ES_200; - break; - } - Draw::ShaderModule *shader = draw_->CreateShaderModule(stage, mappedLang, (const uint8_t *)translated.c_str(), translated.size(), "postshader"); + Draw::ShaderModule *shader = draw_->CreateShaderModule(stage, lang_, (const uint8_t *)translated.c_str(), translated.size(), "postshader"); if (shader) postShaderModules_.push_back(shader); return shader; diff --git a/GPU/Common/ShaderCommon.cpp b/GPU/Common/ShaderCommon.cpp index 190270cd3b..45ba5ab357 100644 --- a/GPU/Common/ShaderCommon.cpp +++ b/GPU/Common/ShaderCommon.cpp @@ -105,7 +105,7 @@ void init_resources(TBuiltInResource &Resources) { ShaderLanguageDesc::ShaderLanguageDesc(ShaderLanguage lang) { shaderLanguage = lang; switch (lang) { - case GLSL_140: + case GLSL_1xx: // Just used in the shader test, and as a basis for the others in DetectShaderLanguage. glslVersionNumber = 110; attribute = "attribute"; @@ -120,7 +120,7 @@ ShaderLanguageDesc::ShaderLanguageDesc(ShaderLanguage lang) { gles = false; forceMatrix4x4 = true; break; - case GLSL_300: + case GLSL_3xx: // Just used in the shader test. glslVersionNumber = 300; // GLSL ES 3.0 varying_vs = "out"; diff --git a/GPU/Common/ShaderTranslation.cpp b/GPU/Common/ShaderTranslation.cpp index 936cdc2560..e32d3fb615 100644 --- a/GPU/Common/ShaderTranslation.cpp +++ b/GPU/Common/ShaderTranslation.cpp @@ -220,10 +220,10 @@ bool ConvertToVulkanGLSL(std::string *dest, TranslatedShaderMetadata *destMetada } bool TranslateShader(std::string *dest, ShaderLanguage destLang, TranslatedShaderMetadata *destMetadata, std::string src, ShaderLanguage srcLang, Draw::ShaderStage stage, std::string *errorMessage) { - if (srcLang != GLSL_300 && srcLang != GLSL_140) + if (srcLang != GLSL_3xx && srcLang != GLSL_1xx) return false; - if ((srcLang == GLSL_140 || srcLang == GLSL_300) && destLang == GLSL_VULKAN) { + if ((srcLang == GLSL_1xx || srcLang == GLSL_3xx) && destLang == GLSL_VULKAN) { // Let's just mess about at the string level, no need to recompile. bool result = ConvertToVulkanGLSL(dest, destMetadata, src, stage, errorMessage); return result; @@ -327,7 +327,7 @@ bool TranslateShader(std::string *dest, ShaderLanguage destLang, TranslatedShade return true; } #endif - case GLSL_140: + case GLSL_1xx: { spirv_cross::CompilerGLSL glsl(std::move(spirv)); // The SPIR-V is now parsed, and we can perform reflection on it. @@ -352,7 +352,7 @@ bool TranslateShader(std::string *dest, ShaderLanguage destLang, TranslatedShade *dest = glsl.compile(); return true; } - case GLSL_300: + case GLSL_3xx: { spirv_cross::CompilerGLSL glsl(std::move(spirv)); // The SPIR-V is now parsed, and we can perform reflection on it. diff --git a/GPU/GLES/DepalettizeShaderGLES.cpp b/GPU/GLES/DepalettizeShaderGLES.cpp index 59517c0f4d..8e58de7c55 100644 --- a/GPU/GLES/DepalettizeShaderGLES.cpp +++ b/GPU/GLES/DepalettizeShaderGLES.cpp @@ -162,7 +162,7 @@ DepalShader *DepalShaderCacheGLES::GetDepalettizeShader(uint32_t clutMode, GEBuf char *buffer = new char[2048]; - GenerateDepalShader(buffer, pixelFormat, useGL3_ ? GLSL_300 : GLSL_140); + GenerateDepalShader(buffer, pixelFormat, useGL3_ ? GLSL_3xx : GLSL_1xx); std::string src(buffer); GLRShader *fragShader = render_->CreateShader(GL_FRAGMENT_SHADER, src, "depal"); diff --git a/GPU/GLES/FramebufferManagerGLES.cpp b/GPU/GLES/FramebufferManagerGLES.cpp index c551b7756f..5ba89b5c4e 100644 --- a/GPU/GLES/FramebufferManagerGLES.cpp +++ b/GPU/GLES/FramebufferManagerGLES.cpp @@ -105,7 +105,7 @@ FramebufferManagerGLES::FramebufferManagerGLES(Draw::DrawContext *draw, GLRender needGLESRebinds_ = true; CreateDeviceObjects(); render_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); - presentation_->SetLanguage(gl_extensions.IsCoreContext ? GLSL_300 : GLSL_140); + presentation_->SetLanguage(gl_extensions.IsCoreContext ? GLSL_3xx : GLSL_1xx); } void FramebufferManagerGLES::Init() { diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index ba8539f4ee..e86573a1e8 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -572,7 +572,7 @@ void LinkedShader::UpdateUniforms(u32 vertType, const ShaderID &vsid, bool useBu } ShaderManagerGLES::ShaderManagerGLES(Draw::DrawContext *draw) - : ShaderManagerCommon(draw), compat_(GLSL_140), fsCache_(16), vsCache_(16) { + : ShaderManagerCommon(draw), compat_(GLSL_1xx), fsCache_(16), vsCache_(16) { render_ = (GLRenderManager *)draw->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); codeBuffer_ = new char[16384]; lastFSID_.set_invalid(); @@ -591,7 +591,7 @@ void ShaderManagerGLES::DetectShaderLanguage() { if (compat.gles) { if (gstate_c.Supports(GPU_SUPPORTS_GLSL_ES_300)) { - compat.shaderLanguage = ShaderLanguage::GLSL_300; + compat.shaderLanguage = ShaderLanguage::GLSL_3xx; compat.glslVersionNumber = 300; // GLSL ES 3.0 compat.fragColor0 = "fragColor0"; compat.texture = "texture"; @@ -602,7 +602,7 @@ void ShaderManagerGLES::DetectShaderLanguage() { compat.varying_fs = "in"; compat.attribute = "in"; } else { - compat.shaderLanguage = ShaderLanguage::GLSL_140; + compat.shaderLanguage = ShaderLanguage::GLSL_1xx; compat.glslVersionNumber = 100; // GLSL ES 1.0 if (gl_extensions.EXT_gpu_shader4) { compat.bitwiseOps = true; @@ -616,7 +616,7 @@ void ShaderManagerGLES::DetectShaderLanguage() { } else { if (!gl_extensions.ForceGL2 || gl_extensions.IsCoreContext) { if (gl_extensions.VersionGEThan(3, 3, 0)) { - compat.shaderLanguage = ShaderLanguage::GLSL_300; + compat.shaderLanguage = ShaderLanguage::GLSL_3xx; compat.glslVersionNumber = 330; compat.fragColor0 = "fragColor0"; compat.texture = "texture"; @@ -627,13 +627,13 @@ void ShaderManagerGLES::DetectShaderLanguage() { compat.varying_fs = "in"; compat.attribute = "in"; } else if (gl_extensions.VersionGEThan(3, 0, 0)) { - compat.shaderLanguage = ShaderLanguage::GLSL_140; + compat.shaderLanguage = ShaderLanguage::GLSL_1xx; compat.glslVersionNumber = 130; compat.fragColor0 = "fragColor0"; compat.bitwiseOps = true; compat.texelFetch = "texelFetch"; } else { - compat.shaderLanguage = ShaderLanguage::GLSL_140; + compat.shaderLanguage = ShaderLanguage::GLSL_1xx; compat.glslVersionNumber = 110; if (gl_extensions.EXT_gpu_shader4) { compat.bitwiseOps = true; diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 26453819f9..7016f0b001 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -72,7 +72,7 @@ SoftGPU::SoftGPU(GraphicsContext *gfxCtx, Draw::DrawContext *draw) switch (GetGPUBackend()) { case GPUBackend::OPENGL: - presentation_->SetLanguage(gl_extensions.IsCoreContext ? GLSL_300 : GLSL_140); + presentation_->SetLanguage(gl_extensions.IsCoreContext ? GLSL_3xx : GLSL_1xx); break; case GPUBackend::DIRECT3D9: ShaderTranslationInit(); diff --git a/UI/GPUDriverTestScreen.cpp b/UI/GPUDriverTestScreen.cpp index 56547cd8b9..8089550e25 100644 --- a/UI/GPUDriverTestScreen.cpp +++ b/UI/GPUDriverTestScreen.cpp @@ -1,9 +1,10 @@ #include "GPUDriverTestScreen.h" #include "Common/Data/Text/I18n.h" #include "Common/UI/View.h" +#include "Common/GPU/Shader.h" static const std::vector fsDiscard = { - {Draw::ShaderLanguage::GLSL_ES_200, + {ShaderLanguage::GLSL_1xx, R"( #ifdef GL_ES precision lowp float; @@ -23,7 +24,7 @@ static const std::vector fsDiscard = { gl_FragColor = color; })" }, - {Draw::ShaderLanguage::GLSL_VULKAN, + {ShaderLanguage::GLSL_VULKAN, R"(#version 450 #extension GL_ARB_separate_shader_objects : enable #extension GL_ARB_shading_language_420pack : enable diff --git a/unittest/TestShaderGenerators.cpp b/unittest/TestShaderGenerators.cpp index 645069172e..2f67729573 100644 --- a/unittest/TestShaderGenerators.cpp +++ b/unittest/TestShaderGenerators.cpp @@ -26,14 +26,14 @@ bool GenerateFShader(FShaderID id, char *buffer, ShaderLanguage lang, std::strin ShaderLanguageDesc compat(ShaderLanguage::GLSL_VULKAN); return GenerateFragmentShader(id, buffer, compat, &uniformMask, errorString); } - case ShaderLanguage::GLSL_140: + case ShaderLanguage::GLSL_1xx: { - ShaderLanguageDesc compat(ShaderLanguage::GLSL_140); + ShaderLanguageDesc compat(ShaderLanguage::GLSL_1xx); return GenerateFragmentShader(id, buffer, compat, &uniformMask, errorString); } - case ShaderLanguage::GLSL_300: + case ShaderLanguage::GLSL_3xx: { - ShaderLanguageDesc compat(ShaderLanguage::GLSL_140); + ShaderLanguageDesc compat(ShaderLanguage::GLSL_1xx); return GenerateFragmentShader(id, buffer, compat, &uniformMask, errorString); } case ShaderLanguage::HLSL_D3D9: @@ -60,14 +60,14 @@ bool GenerateVShader(VShaderID id, char *buffer, ShaderLanguage lang, std::strin ShaderLanguageDesc compat(ShaderLanguage::GLSL_VULKAN); return GenerateVertexShader(id, buffer, compat, &attrMask, &uniformMask, errorString); } - case ShaderLanguage::GLSL_140: + case ShaderLanguage::GLSL_1xx: { - ShaderLanguageDesc compat(ShaderLanguage::GLSL_140); + ShaderLanguageDesc compat(ShaderLanguage::GLSL_1xx); return GenerateVertexShader(id, buffer, compat, &attrMask, &uniformMask, errorString); } - case ShaderLanguage::GLSL_300: + case ShaderLanguage::GLSL_3xx: { - ShaderLanguageDesc compat(ShaderLanguage::GLSL_140); + ShaderLanguageDesc compat(ShaderLanguage::GLSL_1xx); return GenerateVertexShader(id, buffer, compat, &attrMask, &uniformMask, errorString); } case ShaderLanguage::HLSL_D3D9: @@ -106,9 +106,9 @@ bool TestCompileShader(const char *buffer, ShaderLanguage lang, bool vertex, std case ShaderLanguage::GLSL_VULKAN: return GLSLtoSPV(vertex ? VK_SHADER_STAGE_VERTEX_BIT : VK_SHADER_STAGE_FRAGMENT_BIT, buffer, GLSLVariant::VULKAN, spirv, errorMessage); - case ShaderLanguage::GLSL_140: + case ShaderLanguage::GLSL_1xx: return GLSLtoSPV(vertex ? VK_SHADER_STAGE_VERTEX_BIT : VK_SHADER_STAGE_FRAGMENT_BIT, buffer, GLSLVariant::GL140, spirv, errorMessage); - case ShaderLanguage::GLSL_300: + case ShaderLanguage::GLSL_3xx: return GLSLtoSPV(vertex ? VK_SHADER_STAGE_VERTEX_BIT : VK_SHADER_STAGE_FRAGMENT_BIT, buffer, GLSLVariant::GLES300, spirv, errorMessage); default: return false; @@ -151,8 +151,8 @@ bool TestShaderGenerators() { ShaderLanguage::HLSL_D3D9, ShaderLanguage::HLSL_D3D11, ShaderLanguage::GLSL_VULKAN, - ShaderLanguage::GLSL_140, - ShaderLanguage::GLSL_300, + ShaderLanguage::GLSL_1xx, + ShaderLanguage::GLSL_3xx, }; const int numLanguages = ARRAY_SIZE(languages);