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.h
Views: 1401
#pragma once12#include <vector>3#include <cstdint>4#include <cstddef> // for size_t56#include "Common/Common.h"78struct TBuiltInResource;9void InitShaderResources(TBuiltInResource &Resources);1011// GLSL_1xx and GLSL_3xx each cover a lot of sub variants. All the little quirks12// that differ are covered in ShaderLanguageDesc.13// Defined as a bitmask so stuff like GetSupportedShaderLanguages can return combinations.14// TODO: We can probably move away from this distinction soon, now that we mostly generate/translate shaders.15enum ShaderLanguage {16GLSL_1xx = 1,17GLSL_3xx = 2,18GLSL_VULKAN = 4,19HLSL_D3D9 = 8,20HLSL_D3D11 = 16,21};2223inline bool ShaderLanguageIsOpenGL(ShaderLanguage lang) {24return lang == GLSL_1xx || lang == GLSL_3xx;25}2627const char *ShaderLanguageAsString(ShaderLanguage lang);2829enum class ShaderStage {30Vertex,31Fragment,32Geometry,33Compute,34};3536const char *ShaderStageAsString(ShaderStage lang);3738struct ShaderLanguageDesc {39ShaderLanguageDesc() {}40explicit ShaderLanguageDesc(ShaderLanguage lang);4142void Init(ShaderLanguage lang);4344int glslVersionNumber = 0;45ShaderLanguage shaderLanguage;46bool gles = false;47const char *varying_fs = nullptr;48const char *varying_vs = nullptr;49const char *attribute = nullptr;50const char *fragColor0 = nullptr;51const char *fragColor1 = nullptr;52const char *texture = nullptr;53const char *texture3D = nullptr;54const char *texelFetch = nullptr;55const char *lastFragData = nullptr;56const char *framebufferFetchExtension = nullptr;57const char *vsOutPrefix = "";58const char *viewportYSign = "";5960bool vertexIndex = false;61bool glslES30 = false; // really glslES30Features. TODO: Clean this up.62bool bitwiseOps = false;63bool forceMatrix4x4 = false;64bool coefsFromBuffers = false;65char driverInfo[256]; // Really only GL uses this.66};6768enum class UniformType : int8_t {69FLOAT1,70FLOAT2,71FLOAT3,72FLOAT4,73MATRIX4X4,74};7576// Describe uniforms intricately enough that we can support them on all backends.77// This will generate a uniform struct on the newer backends and individual uniforms on the older ones.78struct UniformDesc {79const char *name; // For GL80int16_t vertexReg; // For D3D81int16_t fragmentReg; // For D3D82UniformType type;83int16_t offset; // in bytes84// TODO: Support array elements etc.85};8687struct UniformBufferDesc {88size_t uniformBufferSize;89std::vector<UniformDesc> uniforms;90};9192struct UniformDef {93const char *type;94const char *name;95int index;96};9798enum class SamplerFlags {99ARRAY_ON_VULKAN = 1,100};101ENUM_CLASS_BITOPS(SamplerFlags);102103struct SamplerDef {104int binding; // Might only be used by some backends.105const char *name;106SamplerFlags flags;107// TODO: Might need unsigned samplers, 3d samplers, or other types in the future.108};109110// For passing error messages from shader compilation (and other critical issues) back to the host.111// This can run on any thread - be aware!112// TODO: See if we can find a less generic name for this.113typedef void (*ErrorCallbackFn)(const char *shortDesc, const char *details, void *userdata);114115116