Gtk/Shaders: Use embedded copy of glslang.

This commit is contained in:
BearOso 2020-07-29 18:32:46 -05:00
parent 6db085dc23
commit 6e9cfce6f1
2 changed files with 102 additions and 166 deletions

View File

@ -2,13 +2,14 @@ project('snes9x-gtk',
['c', 'cpp'],
version: '1.60',
meson_version: '>=0.46.0',
default_options: ['cpp_std=c++14'])
default_options: ['cpp_std=c++17'])
args = ['-DSNES9X_GTK', '-DUNZIP_SUPPORT', '-DNETPLAY_SUPPORT', '-DJMA_SUPPORT', '-Wall', '-W', '-Wno-unused-parameter']
srcs = []
deps = []
includes = ['../apu/bapu', '../', 'src']
warns = []
libs = []
prefix = get_option('prefix')
localedir = join_paths(prefix, get_option('localedir'))
@ -54,7 +55,7 @@ opengl = get_option('opengl')
if opengl
opengl_dep = dependency('epoxy', required: false)
if opengl_dep.found()
if opengl_dep.found()
args += '-DUSE_OPENGL'
srcs += [ 'src/gtk_display_driver_opengl.cpp',
'src/gtk_display_driver_opengl.h',
@ -71,55 +72,96 @@ if opengl
endif
slang = get_option('slang')
if slang and opengl
spirv_cross_hpp = join_paths(meson.source_root(), '../shaders/SPIRV-Cross/spirv_cross.hpp')
if not meson.get_compiler('cpp').compiles('#include "' + spirv_cross_hpp + '"')
slang = false
warns += 'Slang support needs the SPIRV-Cross directory in ../shaders'
warns += 'It can be downloaded with:'
warns += ' git submodule init ../shaders/SPIRV-Cross'
warns += ' git submodule update ../shaders/SPIRV-Cross'
endif
endif
glslang_args = ['-w', '-fno-exceptions', '-DNV_EXTENSIONS', '-DAMD_EXTENSIONS', '-DGLSLANG_OSINCLUDE_UNIX', '-DENABLE_OPT=0']
if slang and opengl
glslang_dep = c_compiler.find_library('glslang', required: false)
hlsl_dep = c_compiler.find_library('HLSL', required: false)
spirv_dep = c_compiler.find_library('SPIRV', required: false)
osdependent_dep = c_compiler.find_library('OSDependent', required: false)
ogl_compiler_dep = c_compiler.find_library('OGLCompiler', required: false)
spv_remapper_dep = c_compiler.find_library('SPVRemapper', required: false)
OSDependent_src = ['../shaders/glslang/glslang/OSDependent/Unix/ossource.cpp']
OSDependent_lib = static_library('OSDependent',
OSDependent_src,
cpp_args: glslang_args)
libs += OSDependent_lib
if glslang_dep.found() and hlsl_dep.found() and spirv_dep.found() and osdependent_dep.found() and ogl_compiler_dep.found() and spv_remapper_dep.found()
deps += [glslang_dep, hlsl_dep, spirv_dep, osdependent_dep, ogl_compiler_dep, spv_remapper_dep]
glslang_src = [
'../shaders/glslang/glslang/MachineIndependent/glslang_tab.cpp',
'../shaders/glslang/glslang/MachineIndependent/attribute.cpp',
'../shaders/glslang/glslang/MachineIndependent/Constant.cpp',
'../shaders/glslang/glslang/MachineIndependent/iomapper.cpp',
'../shaders/glslang/glslang/MachineIndependent/InfoSink.cpp',
'../shaders/glslang/glslang/MachineIndependent/Initialize.cpp',
'../shaders/glslang/glslang/MachineIndependent/IntermTraverse.cpp',
'../shaders/glslang/glslang/MachineIndependent/Intermediate.cpp',
'../shaders/glslang/glslang/MachineIndependent/ParseContextBase.cpp',
'../shaders/glslang/glslang/MachineIndependent/ParseHelper.cpp',
'../shaders/glslang/glslang/MachineIndependent/PoolAlloc.cpp',
'../shaders/glslang/glslang/MachineIndependent/RemoveTree.cpp',
'../shaders/glslang/glslang/MachineIndependent/Scan.cpp',
'../shaders/glslang/glslang/MachineIndependent/ShaderLang.cpp',
'../shaders/glslang/glslang/MachineIndependent/SymbolTable.cpp',
'../shaders/glslang/glslang/MachineIndependent/Versions.cpp',
'../shaders/glslang/glslang/MachineIndependent/intermOut.cpp',
'../shaders/glslang/glslang/MachineIndependent/limits.cpp',
'../shaders/glslang/glslang/MachineIndependent/linkValidate.cpp',
'../shaders/glslang/glslang/MachineIndependent/parseConst.cpp',
'../shaders/glslang/glslang/MachineIndependent/reflection.cpp',
'../shaders/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp',
'../shaders/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp',
'../shaders/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp',
'../shaders/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp',
'../shaders/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp',
'../shaders/glslang/glslang/MachineIndependent/propagateNoContraction.cpp',
'../shaders/glslang/glslang/GenericCodeGen/CodeGen.cpp',
'../shaders/glslang/glslang/GenericCodeGen/Link.cpp',
'../shaders/glslang/StandAlone/ResourceLimits.cpp'
]
args += ['-DUSE_SLANG',
'-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS',
'-I' + join_paths(prefix, 'include', 'glslang')]
srcs += ['../shaders/slang.cpp']
srcs += ['../shaders/SPIRV-Cross/spirv_cfg.cpp',
'../shaders/SPIRV-Cross/spirv_cfg.hpp',
'../shaders/SPIRV-Cross/spirv_common.hpp',
'../shaders/SPIRV-Cross/spirv_cross.cpp',
'../shaders/SPIRV-Cross/spirv_cross.hpp',
'../shaders/SPIRV-Cross/spirv_glsl.cpp',
'../shaders/SPIRV-Cross/spirv_glsl.hpp',
'../shaders/SPIRV-Cross/spirv_cross_parsed_ir.cpp',
'../shaders/SPIRV-Cross/spirv_cross_parsed_ir.hpp',
'../shaders/SPIRV-Cross/spirv_parser.cpp',
'../shaders/SPIRV-Cross/spirv_parser.hpp',
'../shaders/SPIRV-Cross/spirv.hpp']
else
slang = false
warns += 'glslang libraries not found. Slang shaders will be disabled.'
endif
glslang_lib = static_library('glslang',
glslang_src,
cpp_args: glslang_args)
libs += glslang_lib
OGLCompilersDLL_src = ['../shaders/glslang/OGLCompilersDLL/InitializeDll.cpp']
OGLCompilersDLL_lib = static_library('OGLCompilersDLL',
OGLCompilersDLL_src,
cpp_args: glslang_args)
libs += OGLCompilersDLL_lib
SPIRV_src = [
'../shaders/glslang/SPIRV/GlslangToSpv.cpp',
'../shaders/glslang/SPIRV/InReadableOrder.cpp',
'../shaders/glslang/SPIRV/Logger.cpp',
'../shaders/glslang/SPIRV/SpvBuilder.cpp',
'../shaders/glslang/SPIRV/SpvPostProcess.cpp',
'../shaders/glslang/SPIRV/SpvTools.cpp',
'../shaders/glslang/SPIRV/disassemble.cpp',
'../shaders/glslang/SPIRV/SPVRemapper.cpp',
'../shaders/glslang/SPIRV/doc.cpp'
]
SPIRV_lib = static_library('SPIRV',
SPIRV_src,
cpp_args: glslang_args)
libs += SPIRV_lib
args += ['-DUSE_SLANG',
'-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS']
srcs += ['../shaders/slang.cpp']
srcs += ['../shaders/SPIRV-Cross/spirv_cfg.cpp',
'../shaders/SPIRV-Cross/spirv_cfg.hpp',
'../shaders/SPIRV-Cross/spirv_common.hpp',
'../shaders/SPIRV-Cross/spirv_cross.cpp',
'../shaders/SPIRV-Cross/spirv_cross.hpp',
'../shaders/SPIRV-Cross/spirv_glsl.cpp',
'../shaders/SPIRV-Cross/spirv_glsl.hpp',
'../shaders/SPIRV-Cross/spirv_cross_parsed_ir.cpp',
'../shaders/SPIRV-Cross/spirv_cross_parsed_ir.hpp',
'../shaders/SPIRV-Cross/spirv_parser.cpp',
'../shaders/SPIRV-Cross/spirv_parser.hpp',
'../shaders/SPIRV-Cross/spirv.hpp']
endif
wayland = get_option('wayland')
if wayland
wayland_dep = dependency('wayland-egl', required: false)
if wayland_dep.found()
args += '-DUSE_WAYLAND'
srcs += ['src/gtk_wayland_egl_context.cpp', 'src/gtk_wayland_egl_context.h']
@ -133,7 +175,7 @@ endif
xv = get_option('xv')
if xv
xv_dep = dependency('xv', required: false)
if xv_dep.found()
args += '-DUSE_XV'
srcs += ['src/gtk_display_driver_xv.cpp', 'src/gtk_display_driver_xv.h']
@ -147,7 +189,7 @@ endif
portaudio = get_option('portaudio')
if portaudio
portaudio_dep = dependency('portaudio-2.0', version: '>= 10', required: false)
if portaudio_dep.found()
args += '-DUSE_PORTAUDIO'
srcs += ['src/gtk_sound_driver_portaudio.cpp', 'src/gtk_sound_driver_portaudio.h']
@ -172,7 +214,7 @@ endif
alsa = get_option('alsa')
if alsa
alsa_dep = dependency('alsa', required: false)
if alsa_dep.found()
args += '-DUSE_ALSA'
srcs += ['src/gtk_sound_driver_alsa.cpp', 'src/gtk_sound_driver_alsa.h']
@ -186,7 +228,7 @@ endif
pulseaudio = get_option('pulseaudio')
if pulseaudio
pulseaudio_dep = dependency('libpulse', required: false)
if pulseaudio_dep.found()
args += '-DUSE_PULSEAUDIO'
srcs += ['src/gtk_sound_driver_pulse.cpp', 'src/gtk_sound_driver_pulse.h']
@ -220,7 +262,7 @@ else
includes += '../unzip'
srcs += ['../unzip/unzip.c', '../unzip/ioapi.c', '../unzip/zip.c']
endif
zlib = get_option('zlib')
if zlib
zlib_dep = dependency('zlib', required: false)
@ -394,26 +436,27 @@ libjma_srcs = [
'../jma/winout.cpp'
]
libjma = static_library('jma',
libjma_srcs,
c_args: args,
libjma = static_library('jma',
libjma_srcs,
c_args: args,
cpp_args: args,
include_directories: include_directories(includes))
libs += libjma
sourcify = executable('sourcify', 'src/sourcify.c', native: true)
gtk_snes9x_ui_cpp = custom_target('sourcify',
input: 'src/snes9x.ui',
gtk_snes9x_ui_cpp = custom_target('sourcify',
input: 'src/snes9x.ui',
output: 'gtk_snes9x_ui.cpp',
command: [sourcify, '@INPUT@', '@OUTPUT@', 'snes9x_ui'])
snes9x_gtk = executable('snes9x-gtk',
srcs,
snes9x_gtk = executable('snes9x-gtk',
srcs,
gtk_snes9x_ui_cpp,
c_args: args,
c_args: args,
cpp_args: args,
dependencies: deps,
include_directories: include_directories(includes),
link_with: libjma,
link_with: libs,
install: true)
summary = [

View File

@ -9,8 +9,9 @@
#include <vector>
#include <string>
#include <sstream>
#include <glslang/Public/ShaderLang.h>
#include <SPIRV/GlslangToSpv.h>
#include "glslang/glslang/Public/ShaderLang.h"
#include "glslang/SPIRV/GlslangToSpv.h"
#include "glslang/StandAlone/ResourceLimits.h"
#include "SPIRV-Cross/spirv_cross.hpp"
#include "SPIRV-Cross/spirv_glsl.hpp"
@ -83,114 +84,6 @@ static void printuniforms(std::vector<SlangUniform> &unif)
}
#endif // #if 0
namespace glslang {
static const TBuiltInResource DefaultTBuiltInResource = {
/* .MaxLights = */ 32,
/* .MaxClipPlanes = */ 6,
/* .MaxTextureUnits = */ 32,
/* .MaxTextureCoords = */ 32,
/* .MaxVertexAttribs = */ 64,
/* .MaxVertexUniformComponents = */ 4096,
/* .MaxVaryingFloats = */ 64,
/* .MaxVertexTextureImageUnits = */ 32,
/* .MaxCombinedTextureImageUnits = */ 80,
/* .MaxTextureImageUnits = */ 32,
/* .MaxFragmentUniformComponents = */ 4096,
/* .MaxDrawBuffers = */ 32,
/* .MaxVertexUniformVectors = */ 128,
/* .MaxVaryingVectors = */ 8,
/* .MaxFragmentUniformVectors = */ 16,
/* .MaxVertexOutputVectors = */ 16,
/* .MaxFragmentInputVectors = */ 15,
/* .MinProgramTexelOffset = */ -8,
/* .MaxProgramTexelOffset = */ 7,
/* .MaxClipDistances = */ 8,
/* .MaxComputeWorkGroupCountX = */ 65535,
/* .MaxComputeWorkGroupCountY = */ 65535,
/* .MaxComputeWorkGroupCountZ = */ 65535,
/* .MaxComputeWorkGroupSizeX = */ 1024,
/* .MaxComputeWorkGroupSizeY = */ 1024,
/* .MaxComputeWorkGroupSizeZ = */ 64,
/* .MaxComputeUniformComponents = */ 1024,
/* .MaxComputeTextureImageUnits = */ 16,
/* .MaxComputeImageUniforms = */ 8,
/* .MaxComputeAtomicCounters = */ 8,
/* .MaxComputeAtomicCounterBuffers = */ 1,
/* .MaxVaryingComponents = */ 60,
/* .MaxVertexOutputComponents = */ 64,
/* .MaxGeometryInputComponents = */ 64,
/* .MaxGeometryOutputComponents = */ 128,
/* .MaxFragmentInputComponents = */ 128,
/* .MaxImageUnits = */ 8,
/* .MaxCombinedImageUnitsAndFragmentOutputs = */ 8,
/* .MaxCombinedShaderOutputResources = */ 8,
/* .MaxImageSamples = */ 0,
/* .MaxVertexImageUniforms = */ 0,
/* .MaxTessControlImageUniforms = */ 0,
/* .MaxTessEvaluationImageUniforms = */ 0,
/* .MaxGeometryImageUniforms = */ 0,
/* .MaxFragmentImageUniforms = */ 8,
/* .MaxCombinedImageUniforms = */ 8,
/* .MaxGeometryTextureImageUnits = */ 16,
/* .MaxGeometryOutputVertices = */ 256,
/* .MaxGeometryTotalOutputComponents = */ 1024,
/* .MaxGeometryUniformComponents = */ 1024,
/* .MaxGeometryVaryingComponents = */ 64,
/* .MaxTessControlInputComponents = */ 128,
/* .MaxTessControlOutputComponents = */ 128,
/* .MaxTessControlTextureImageUnits = */ 16,
/* .MaxTessControlUniformComponents = */ 1024,
/* .MaxTessControlTotalOutputComponents = */ 4096,
/* .MaxTessEvaluationInputComponents = */ 128,
/* .MaxTessEvaluationOutputComponents = */ 128,
/* .MaxTessEvaluationTextureImageUnits = */ 16,
/* .MaxTessEvaluationUniformComponents = */ 1024,
/* .MaxTessPatchComponents = */ 120,
/* .MaxPatchVertices = */ 32,
/* .MaxTessGenLevel = */ 64,
/* .MaxViewports = */ 16,
/* .MaxVertexAtomicCounters = */ 0,
/* .MaxTessControlAtomicCounters = */ 0,
/* .MaxTessEvaluationAtomicCounters = */ 0,
/* .MaxGeometryAtomicCounters = */ 0,
/* .MaxFragmentAtomicCounters = */ 8,
/* .MaxCombinedAtomicCounters = */ 8,
/* .MaxAtomicCounterBindings = */ 1,
/* .MaxVertexAtomicCounterBuffers = */ 0,
/* .MaxTessControlAtomicCounterBuffers = */ 0,
/* .MaxTessEvaluationAtomicCounterBuffers = */ 0,
/* .MaxGeometryAtomicCounterBuffers = */ 0,
/* .MaxFragmentAtomicCounterBuffers = */ 1,
/* .MaxCombinedAtomicCounterBuffers = */ 1,
/* .MaxAtomicCounterBufferSize = */ 16384,
/* .MaxTransformFeedbackBuffers = */ 4,
/* .MaxTransformFeedbackInterleavedComponents = */ 64,
/* .MaxCullDistances = */ 8,
/* .MaxCombinedClipAndCullDistances = */ 8,
/* .MaxSamples = */ 4,
/* .maxMeshOutputVerticesNV = */ 256,
/* .maxMeshOutputPrimitivesNV = */ 512,
/* .maxMeshWorkGroupSizeX_NV = */ 32,
/* .maxMeshWorkGroupSizeY_NV = */ 1,
/* .maxMeshWorkGroupSizeZ_NV = */ 1,
/* .maxTaskWorkGroupSizeX_NV = */ 32,
/* .maxTaskWorkGroupSizeY_NV = */ 1,
/* .maxTaskWorkGroupSizeZ_NV = */ 1,
/* .maxMeshViewCountNV = */ 4,
/* .limits = */ {
/* .nonInductiveForLoops = */ 1,
/* .whileLoops = */ 1,
/* .doWhileLoops = */ 1,
/* .generalUniformIndexing = */ 1,
/* .generalAttributeMatrixVectorIndexing = */ 1,
/* .generalVaryingIndexing = */ 1,
/* .generalSamplerIndexing = */ 1,
/* .generalVariableIndexing = */ 1,
/* .generalConstantMatrixVectorIndexing = */ 1,
}};
} // namespace glslang
GLint GLSLShader::slang_compile(std::vector<std::string> &lines,
std::string stage)
{