CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Common/GPU/Shader.cpp
Views: 1401
#include "Common/GPU/Shader.h"12#ifdef USE_CRT_DBG3#undef new4#endif56#include "ext/glslang/SPIRV/GlslangToSpv.h"78const char *ShaderLanguageAsString(ShaderLanguage lang) {9switch (lang) {10case GLSL_1xx: return "GLSL 1.x";11case GLSL_3xx: return "GLSL 3.x";12case GLSL_VULKAN: return "GLSL-VK";13case HLSL_D3D9: return "HLSL-D3D9";14case HLSL_D3D11: return "HLSL-D3D11";15default: return "(combination)";16}17}1819const char *ShaderStageAsString(ShaderStage stage) {20switch (stage) {21case ShaderStage::Fragment: return "Fragment";22case ShaderStage::Vertex: return "Vertex";23case ShaderStage::Geometry: return "Geometry";24case ShaderStage::Compute: return "Compute";25default: return "(unknown)";26}27}2829ShaderLanguageDesc::ShaderLanguageDesc(ShaderLanguage lang) {30Init(lang);31}3233void ShaderLanguageDesc::Init(ShaderLanguage lang) {34shaderLanguage = lang;35strcpy(driverInfo, "");36switch (lang) {37case GLSL_1xx:38// Just used in the shader test, and as a basis for the others in DetectShaderLanguage.39// The real OpenGL initialization happens in thin3d_gl.cpp.40glslVersionNumber = 110;41attribute = "attribute";42varying_vs = "varying";43varying_fs = "varying";44fragColor0 = "gl_FragColor";45fragColor1 = "fragColor1";46texture = "texture2D";47texture3D = "texture3D";48texelFetch = nullptr;49bitwiseOps = false;50lastFragData = nullptr;51gles = false;52forceMatrix4x4 = true;53break;54case GLSL_3xx:55// Just used in the shader test.56glslVersionNumber = 300; // GLSL ES 3.057varying_vs = "out";58varying_fs = "in";59attribute = "in";60fragColor0 = "fragColor0";61fragColor1 = "fragColor1";62texture = "texture";63texture3D = "texture";64texelFetch = "texelFetch";65bitwiseOps = true;66lastFragData = nullptr;67gles = true;68forceMatrix4x4 = true;69glslES30 = true;70break;71case GLSL_VULKAN:72fragColor0 = "fragColor0";73fragColor1 = "fragColor1";74varying_fs = "in";75varying_vs = "out";76attribute = "in";77bitwiseOps = true;78framebufferFetchExtension = nullptr;79gles = false;80glslES30 = true;81glslVersionNumber = 450;82lastFragData = nullptr;83texture = "texture";84texture3D = "texture";85texelFetch = "texelFetch";86forceMatrix4x4 = false;87coefsFromBuffers = true;88vertexIndex = true;89break;90case HLSL_D3D9:91case HLSL_D3D11:92if (lang == HLSL_D3D11) {93fragColor0 = "outfragment.target";94fragColor1 = "outfragment.target1";95vertexIndex = true; // if declared as a semantic input96} else {97fragColor0 = "outfragment.target";98}99varying_fs = "in";100varying_vs = "out";101attribute = "in";102bitwiseOps = lang == HLSL_D3D11;103framebufferFetchExtension = nullptr;104gles = false;105glslES30 = true; // Hm, D3D9 too?106glslVersionNumber = 0;107lastFragData = nullptr;108texture = "texture";109texture3D = "texture";110texelFetch = "texelFetch";111forceMatrix4x4 = false;112coefsFromBuffers = true;113vsOutPrefix = "Out.";114viewportYSign = "-";115break;116}117}118119void InitShaderResources(TBuiltInResource &Resources) {120Resources.maxLights = 32;121Resources.maxClipPlanes = 6;122Resources.maxTextureUnits = 32;123Resources.maxTextureCoords = 32;124Resources.maxVertexAttribs = 64;125Resources.maxVertexUniformComponents = 4096;126Resources.maxVaryingFloats = 64;127Resources.maxVertexTextureImageUnits = 32;128Resources.maxCombinedTextureImageUnits = 80;129Resources.maxTextureImageUnits = 32;130Resources.maxFragmentUniformComponents = 4096;131Resources.maxDrawBuffers = 32;132Resources.maxVertexUniformVectors = 128;133Resources.maxVaryingVectors = 8;134Resources.maxFragmentUniformVectors = 16;135Resources.maxVertexOutputVectors = 16;136Resources.maxFragmentInputVectors = 15;137Resources.minProgramTexelOffset = -8;138Resources.maxProgramTexelOffset = 7;139Resources.maxClipDistances = 8;140Resources.maxComputeWorkGroupCountX = 65535;141Resources.maxComputeWorkGroupCountY = 65535;142Resources.maxComputeWorkGroupCountZ = 65535;143Resources.maxComputeWorkGroupSizeX = 1024;144Resources.maxComputeWorkGroupSizeY = 1024;145Resources.maxComputeWorkGroupSizeZ = 64;146Resources.maxComputeUniformComponents = 1024;147Resources.maxComputeTextureImageUnits = 16;148Resources.maxComputeImageUniforms = 8;149Resources.maxComputeAtomicCounters = 8;150Resources.maxComputeAtomicCounterBuffers = 1;151Resources.maxVaryingComponents = 60;152Resources.maxVertexOutputComponents = 64;153Resources.maxGeometryInputComponents = 64;154Resources.maxGeometryOutputComponents = 128;155Resources.maxFragmentInputComponents = 128;156Resources.maxImageUnits = 8;157Resources.maxCombinedImageUnitsAndFragmentOutputs = 8;158Resources.maxCombinedShaderOutputResources = 8;159Resources.maxImageSamples = 0;160Resources.maxVertexImageUniforms = 0;161Resources.maxTessControlImageUniforms = 0;162Resources.maxTessEvaluationImageUniforms = 0;163Resources.maxGeometryImageUniforms = 0;164Resources.maxFragmentImageUniforms = 8;165Resources.maxCombinedImageUniforms = 8;166Resources.maxGeometryTextureImageUnits = 16;167Resources.maxGeometryOutputVertices = 256;168Resources.maxGeometryTotalOutputComponents = 1024;169Resources.maxGeometryUniformComponents = 1024;170Resources.maxGeometryVaryingComponents = 64;171Resources.maxTessControlInputComponents = 128;172Resources.maxTessControlOutputComponents = 128;173Resources.maxTessControlTextureImageUnits = 16;174Resources.maxTessControlUniformComponents = 1024;175Resources.maxTessControlTotalOutputComponents = 4096;176Resources.maxTessEvaluationInputComponents = 128;177Resources.maxTessEvaluationOutputComponents = 128;178Resources.maxTessEvaluationTextureImageUnits = 16;179Resources.maxTessEvaluationUniformComponents = 1024;180Resources.maxTessPatchComponents = 120;181Resources.maxPatchVertices = 32;182Resources.maxTessGenLevel = 64;183Resources.maxViewports = 16;184Resources.maxVertexAtomicCounters = 0;185Resources.maxTessControlAtomicCounters = 0;186Resources.maxTessEvaluationAtomicCounters = 0;187Resources.maxGeometryAtomicCounters = 0;188Resources.maxFragmentAtomicCounters = 8;189Resources.maxCombinedAtomicCounters = 8;190Resources.maxAtomicCounterBindings = 1;191Resources.maxVertexAtomicCounterBuffers = 0;192Resources.maxTessControlAtomicCounterBuffers = 0;193Resources.maxTessEvaluationAtomicCounterBuffers = 0;194Resources.maxGeometryAtomicCounterBuffers = 0;195Resources.maxFragmentAtomicCounterBuffers = 1;196Resources.maxCombinedAtomicCounterBuffers = 1;197Resources.maxAtomicCounterBufferSize = 16384;198Resources.maxTransformFeedbackBuffers = 4;199Resources.maxTransformFeedbackInterleavedComponents = 64;200Resources.maxCullDistances = 8;201Resources.maxCombinedClipAndCullDistances = 8;202Resources.maxSamples = 4;203Resources.maxDualSourceDrawBuffersEXT = 1;204Resources.limits.nonInductiveForLoops = 1;205Resources.limits.whileLoops = 1;206Resources.limits.doWhileLoops = 1;207Resources.limits.generalUniformIndexing = 1;208Resources.limits.generalAttributeMatrixVectorIndexing = 1;209Resources.limits.generalVaryingIndexing = 1;210Resources.limits.generalSamplerIndexing = 1;211Resources.limits.generalVariableIndexing = 1;212Resources.limits.generalConstantMatrixVectorIndexing = 1;213}214215216