2020-11-04 08:18:35 +00:00
|
|
|
#include "Common/GPU/Shader.h"
|
2020-11-06 08:01:13 +00:00
|
|
|
|
2020-11-09 14:39:46 +00:00
|
|
|
#ifdef USE_CRT_DBG
|
|
|
|
#undef new
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ext/glslang/SPIRV/GlslangToSpv.h"
|
|
|
|
|
2021-01-03 18:13:25 +00:00
|
|
|
const char *ShaderLanguageAsString(ShaderLanguage lang) {
|
|
|
|
switch (lang) {
|
|
|
|
case GLSL_1xx: return "GLSL 1.x";
|
|
|
|
case GLSL_3xx: return "GLSL 3.x";
|
|
|
|
case GLSL_VULKAN: return "GLSL-VK";
|
|
|
|
case HLSL_D3D9: return "HLSL-D3D9";
|
|
|
|
case HLSL_D3D11: return "HLSL-D3D11";
|
|
|
|
default: return "(combination)";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 22:51:34 +00:00
|
|
|
const char *ShaderStageAsString(ShaderStage stage) {
|
|
|
|
switch (stage) {
|
|
|
|
case ShaderStage::Fragment: return "Fragment";
|
|
|
|
case ShaderStage::Vertex: return "Vertex";
|
|
|
|
case ShaderStage::Geometry: return "Geometry";
|
|
|
|
case ShaderStage::Compute: return "Compute";
|
|
|
|
default: return "(unknown)";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-06 08:01:13 +00:00
|
|
|
ShaderLanguageDesc::ShaderLanguageDesc(ShaderLanguage lang) {
|
|
|
|
Init(lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderLanguageDesc::Init(ShaderLanguage lang) {
|
|
|
|
shaderLanguage = lang;
|
2022-08-09 13:32:27 +00:00
|
|
|
strcpy(driverInfo, "");
|
2020-11-06 08:01:13 +00:00
|
|
|
switch (lang) {
|
|
|
|
case GLSL_1xx:
|
|
|
|
// Just used in the shader test, and as a basis for the others in DetectShaderLanguage.
|
2020-11-16 22:26:37 +00:00
|
|
|
// The real OpenGL initialization happens in thin3d_gl.cpp.
|
2020-11-06 08:01:13 +00:00
|
|
|
glslVersionNumber = 110;
|
|
|
|
attribute = "attribute";
|
|
|
|
varying_vs = "varying";
|
|
|
|
varying_fs = "varying";
|
|
|
|
fragColor0 = "gl_FragColor";
|
|
|
|
fragColor1 = "fragColor1";
|
|
|
|
texture = "texture2D";
|
2022-07-30 19:52:58 +00:00
|
|
|
texture3D = "texture3D";
|
2020-11-06 08:01:13 +00:00
|
|
|
texelFetch = nullptr;
|
|
|
|
bitwiseOps = false;
|
|
|
|
lastFragData = nullptr;
|
|
|
|
gles = false;
|
|
|
|
forceMatrix4x4 = true;
|
|
|
|
break;
|
|
|
|
case GLSL_3xx:
|
|
|
|
// Just used in the shader test.
|
|
|
|
glslVersionNumber = 300; // GLSL ES 3.0
|
|
|
|
varying_vs = "out";
|
|
|
|
varying_fs = "in";
|
|
|
|
attribute = "in";
|
|
|
|
fragColor0 = "fragColor0";
|
|
|
|
fragColor1 = "fragColor1";
|
|
|
|
texture = "texture";
|
2022-07-30 19:52:58 +00:00
|
|
|
texture3D = "texture";
|
2020-11-03 14:44:57 +00:00
|
|
|
texelFetch = "texelFetch";
|
|
|
|
bitwiseOps = true;
|
2020-11-06 08:01:13 +00:00
|
|
|
lastFragData = nullptr;
|
2020-11-03 14:44:57 +00:00
|
|
|
gles = true;
|
2020-11-06 08:01:13 +00:00
|
|
|
forceMatrix4x4 = true;
|
|
|
|
glslES30 = true;
|
|
|
|
break;
|
|
|
|
case GLSL_VULKAN:
|
|
|
|
fragColor0 = "fragColor0";
|
|
|
|
fragColor1 = "fragColor1";
|
|
|
|
varying_fs = "in";
|
|
|
|
varying_vs = "out";
|
|
|
|
attribute = "in";
|
|
|
|
bitwiseOps = true;
|
|
|
|
framebufferFetchExtension = nullptr;
|
|
|
|
gles = false;
|
|
|
|
glslES30 = true;
|
|
|
|
glslVersionNumber = 450;
|
|
|
|
lastFragData = nullptr;
|
|
|
|
texture = "texture";
|
2022-07-30 19:52:58 +00:00
|
|
|
texture3D = "texture";
|
2020-11-06 08:01:13 +00:00
|
|
|
texelFetch = "texelFetch";
|
|
|
|
forceMatrix4x4 = false;
|
|
|
|
coefsFromBuffers = true;
|
2022-07-24 18:07:29 +00:00
|
|
|
vertexIndex = true;
|
2020-11-06 08:01:13 +00:00
|
|
|
break;
|
|
|
|
case HLSL_D3D9:
|
|
|
|
case HLSL_D3D11:
|
2020-11-09 08:07:52 +00:00
|
|
|
if (lang == HLSL_D3D11) {
|
|
|
|
fragColor0 = "outfragment.target";
|
|
|
|
fragColor1 = "outfragment.target1";
|
2022-07-24 18:07:29 +00:00
|
|
|
vertexIndex = true; // if declared as a semantic input
|
2020-11-09 08:07:52 +00:00
|
|
|
} else {
|
2022-08-01 10:11:42 +00:00
|
|
|
fragColor0 = "outfragment.target";
|
2020-11-09 08:07:52 +00:00
|
|
|
}
|
2020-11-06 08:01:13 +00:00
|
|
|
varying_fs = "in";
|
|
|
|
varying_vs = "out";
|
|
|
|
attribute = "in";
|
|
|
|
bitwiseOps = lang == HLSL_D3D11;
|
|
|
|
framebufferFetchExtension = nullptr;
|
|
|
|
gles = false;
|
2020-11-07 22:20:34 +00:00
|
|
|
glslES30 = true; // Hm, D3D9 too?
|
2020-11-06 08:01:13 +00:00
|
|
|
glslVersionNumber = 0;
|
|
|
|
lastFragData = nullptr;
|
|
|
|
texture = "texture";
|
2022-07-30 19:52:58 +00:00
|
|
|
texture3D = "texture";
|
2020-11-06 08:01:13 +00:00
|
|
|
texelFetch = "texelFetch";
|
|
|
|
forceMatrix4x4 = false;
|
|
|
|
coefsFromBuffers = true;
|
|
|
|
vsOutPrefix = "Out.";
|
2020-11-07 10:53:48 +00:00
|
|
|
viewportYSign = "-";
|
2020-11-06 08:01:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-27 22:35:49 +00:00
|
|
|
void InitShaderResources(TBuiltInResource &Resources) {
|
2020-11-09 14:39:46 +00:00
|
|
|
Resources.maxLights = 32;
|
|
|
|
Resources.maxClipPlanes = 6;
|
|
|
|
Resources.maxTextureUnits = 32;
|
|
|
|
Resources.maxTextureCoords = 32;
|
|
|
|
Resources.maxVertexAttribs = 64;
|
|
|
|
Resources.maxVertexUniformComponents = 4096;
|
|
|
|
Resources.maxVaryingFloats = 64;
|
|
|
|
Resources.maxVertexTextureImageUnits = 32;
|
|
|
|
Resources.maxCombinedTextureImageUnits = 80;
|
|
|
|
Resources.maxTextureImageUnits = 32;
|
|
|
|
Resources.maxFragmentUniformComponents = 4096;
|
|
|
|
Resources.maxDrawBuffers = 32;
|
|
|
|
Resources.maxVertexUniformVectors = 128;
|
|
|
|
Resources.maxVaryingVectors = 8;
|
|
|
|
Resources.maxFragmentUniformVectors = 16;
|
|
|
|
Resources.maxVertexOutputVectors = 16;
|
|
|
|
Resources.maxFragmentInputVectors = 15;
|
|
|
|
Resources.minProgramTexelOffset = -8;
|
|
|
|
Resources.maxProgramTexelOffset = 7;
|
|
|
|
Resources.maxClipDistances = 8;
|
|
|
|
Resources.maxComputeWorkGroupCountX = 65535;
|
|
|
|
Resources.maxComputeWorkGroupCountY = 65535;
|
|
|
|
Resources.maxComputeWorkGroupCountZ = 65535;
|
|
|
|
Resources.maxComputeWorkGroupSizeX = 1024;
|
|
|
|
Resources.maxComputeWorkGroupSizeY = 1024;
|
|
|
|
Resources.maxComputeWorkGroupSizeZ = 64;
|
|
|
|
Resources.maxComputeUniformComponents = 1024;
|
|
|
|
Resources.maxComputeTextureImageUnits = 16;
|
|
|
|
Resources.maxComputeImageUniforms = 8;
|
|
|
|
Resources.maxComputeAtomicCounters = 8;
|
|
|
|
Resources.maxComputeAtomicCounterBuffers = 1;
|
|
|
|
Resources.maxVaryingComponents = 60;
|
|
|
|
Resources.maxVertexOutputComponents = 64;
|
|
|
|
Resources.maxGeometryInputComponents = 64;
|
|
|
|
Resources.maxGeometryOutputComponents = 128;
|
|
|
|
Resources.maxFragmentInputComponents = 128;
|
|
|
|
Resources.maxImageUnits = 8;
|
|
|
|
Resources.maxCombinedImageUnitsAndFragmentOutputs = 8;
|
|
|
|
Resources.maxCombinedShaderOutputResources = 8;
|
|
|
|
Resources.maxImageSamples = 0;
|
|
|
|
Resources.maxVertexImageUniforms = 0;
|
|
|
|
Resources.maxTessControlImageUniforms = 0;
|
|
|
|
Resources.maxTessEvaluationImageUniforms = 0;
|
|
|
|
Resources.maxGeometryImageUniforms = 0;
|
|
|
|
Resources.maxFragmentImageUniforms = 8;
|
|
|
|
Resources.maxCombinedImageUniforms = 8;
|
|
|
|
Resources.maxGeometryTextureImageUnits = 16;
|
|
|
|
Resources.maxGeometryOutputVertices = 256;
|
|
|
|
Resources.maxGeometryTotalOutputComponents = 1024;
|
|
|
|
Resources.maxGeometryUniformComponents = 1024;
|
|
|
|
Resources.maxGeometryVaryingComponents = 64;
|
|
|
|
Resources.maxTessControlInputComponents = 128;
|
|
|
|
Resources.maxTessControlOutputComponents = 128;
|
|
|
|
Resources.maxTessControlTextureImageUnits = 16;
|
|
|
|
Resources.maxTessControlUniformComponents = 1024;
|
|
|
|
Resources.maxTessControlTotalOutputComponents = 4096;
|
|
|
|
Resources.maxTessEvaluationInputComponents = 128;
|
|
|
|
Resources.maxTessEvaluationOutputComponents = 128;
|
|
|
|
Resources.maxTessEvaluationTextureImageUnits = 16;
|
|
|
|
Resources.maxTessEvaluationUniformComponents = 1024;
|
|
|
|
Resources.maxTessPatchComponents = 120;
|
|
|
|
Resources.maxPatchVertices = 32;
|
|
|
|
Resources.maxTessGenLevel = 64;
|
|
|
|
Resources.maxViewports = 16;
|
|
|
|
Resources.maxVertexAtomicCounters = 0;
|
|
|
|
Resources.maxTessControlAtomicCounters = 0;
|
|
|
|
Resources.maxTessEvaluationAtomicCounters = 0;
|
|
|
|
Resources.maxGeometryAtomicCounters = 0;
|
|
|
|
Resources.maxFragmentAtomicCounters = 8;
|
|
|
|
Resources.maxCombinedAtomicCounters = 8;
|
|
|
|
Resources.maxAtomicCounterBindings = 1;
|
|
|
|
Resources.maxVertexAtomicCounterBuffers = 0;
|
|
|
|
Resources.maxTessControlAtomicCounterBuffers = 0;
|
|
|
|
Resources.maxTessEvaluationAtomicCounterBuffers = 0;
|
|
|
|
Resources.maxGeometryAtomicCounterBuffers = 0;
|
|
|
|
Resources.maxFragmentAtomicCounterBuffers = 1;
|
|
|
|
Resources.maxCombinedAtomicCounterBuffers = 1;
|
|
|
|
Resources.maxAtomicCounterBufferSize = 16384;
|
|
|
|
Resources.maxTransformFeedbackBuffers = 4;
|
|
|
|
Resources.maxTransformFeedbackInterleavedComponents = 64;
|
|
|
|
Resources.maxCullDistances = 8;
|
|
|
|
Resources.maxCombinedClipAndCullDistances = 8;
|
|
|
|
Resources.maxSamples = 4;
|
2022-10-10 15:14:56 +00:00
|
|
|
Resources.maxDualSourceDrawBuffersEXT = 1;
|
2020-11-09 14:39:46 +00:00
|
|
|
Resources.limits.nonInductiveForLoops = 1;
|
|
|
|
Resources.limits.whileLoops = 1;
|
|
|
|
Resources.limits.doWhileLoops = 1;
|
|
|
|
Resources.limits.generalUniformIndexing = 1;
|
|
|
|
Resources.limits.generalAttributeMatrixVectorIndexing = 1;
|
|
|
|
Resources.limits.generalVaryingIndexing = 1;
|
|
|
|
Resources.limits.generalSamplerIndexing = 1;
|
|
|
|
Resources.limits.generalVariableIndexing = 1;
|
|
|
|
Resources.limits.generalConstantMatrixVectorIndexing = 1;
|
|
|
|
}
|