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/GPU/Common/ShaderCommon.h
Views: 1401
// Copyright (c) 2015- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <cstdint>20#include <vector>21#include <string>2223namespace Draw {24class DrawContext;25}2627enum DebugShaderType {28SHADER_TYPE_VERTEX = 0,29SHADER_TYPE_FRAGMENT = 1,30SHADER_TYPE_GEOMETRY = 2,31SHADER_TYPE_VERTEXLOADER = 3, // Not really a shader, but might as well re-use this mechanism32SHADER_TYPE_PIPELINE = 4, // Vulkan and DX12 combines a bunch of state into pipeline objects. Might as well make them inspectable.33SHADER_TYPE_TEXTURE = 5,34SHADER_TYPE_SAMPLER = 6, // Not really a shader either. Need to rename this enum...35};3637enum DebugShaderStringType {38SHADER_STRING_SHORT_DESC = 0,39SHADER_STRING_SOURCE_CODE = 1,40SHADER_STRING_STATS = 2,41};4243// Shared between the backends. Not all are necessarily used by each backend, but this lets us share44// more code than before. TODO: Can probably cut the number of these down without too much slowdown.45enum : uint64_t {46DIRTY_PROJMATRIX = 1ULL << 0,47DIRTY_PROJTHROUGHMATRIX = 1ULL << 1,48DIRTY_FOGCOLOR = 1ULL << 2,49DIRTY_FOGCOEF = 1ULL << 3,50DIRTY_TEXENV = 1ULL << 4,51DIRTY_ALPHACOLORREF = 1ULL << 5,5253DIRTY_STENCILREPLACEVALUE = 1ULL << 6,5455DIRTY_ALPHACOLORMASK = 1ULL << 7,56DIRTY_LIGHT0 = 1ULL << 8,57DIRTY_LIGHT1 = 1ULL << 9,58DIRTY_LIGHT2 = 1ULL << 10,59DIRTY_LIGHT3 = 1ULL << 11,6061DIRTY_MATDIFFUSE = 1ULL << 12,62DIRTY_MATSPECULAR = 1ULL << 13,63DIRTY_MATEMISSIVE = 1ULL << 14,64DIRTY_AMBIENT = 1ULL << 15,65DIRTY_MATAMBIENTALPHA = 1ULL << 16,6667DIRTY_SHADERBLEND = 1ULL << 17, // Used only for in-shader blending.6869DIRTY_UVSCALEOFFSET = 1ULL << 18,70DIRTY_DEPTHRANGE = 1ULL << 19,7172DIRTY_WORLDMATRIX = 1ULL << 21,73DIRTY_VIEWMATRIX = 1ULL << 22,74DIRTY_TEXMATRIX = 1ULL << 23,75DIRTY_BONEMATRIX0 = 1ULL << 24, // NOTE: These must be under 3276DIRTY_BONEMATRIX1 = 1ULL << 25,77DIRTY_BONEMATRIX2 = 1ULL << 26,78DIRTY_BONEMATRIX3 = 1ULL << 27,79DIRTY_BONEMATRIX4 = 1ULL << 28,80DIRTY_BONEMATRIX5 = 1ULL << 29,81DIRTY_BONEMATRIX6 = 1ULL << 30,82DIRTY_BONEMATRIX7 = 1ULL << 31,8384DIRTY_BEZIERSPLINE = 1ULL << 32,85DIRTY_TEXCLAMP = 1ULL << 33,86DIRTY_CULLRANGE = 1ULL << 34,8788DIRTY_DEPAL = 1ULL << 35,89DIRTY_COLORWRITEMASK = 1ULL << 36,9091DIRTY_MIPBIAS = 1ULL << 37,92DIRTY_LIGHT_CONTROL = 1ULL << 38,93DIRTY_TEX_ALPHA_MUL = 1ULL << 39,9495// Bits 40-42 are free for new uniforms. Then we're really out and need to start merging.96// Don't forget to update DIRTY_ALL_UNIFORMS when you start using them.9798DIRTY_BONE_UNIFORMS = 0xFF000000ULL,99100DIRTY_ALL_UNIFORMS = 0x0FFFFFFFFFFULL,101102// Other dirty elements that aren't uniforms103DIRTY_CULL_PLANES = 1ULL << 43,104DIRTY_FRAMEBUF = 1ULL << 44,105DIRTY_TEXTURE_IMAGE = 1ULL << 45, // Means that the definition of the texture image has changed (address, stride etc), and we need to look up again.106DIRTY_TEXTURE_PARAMS = 1ULL << 46,107108// Render State109DIRTY_BLEND_STATE = 1ULL << 47,110DIRTY_DEPTHSTENCIL_STATE = 1ULL << 48,111DIRTY_RASTER_STATE = 1ULL << 49,112DIRTY_VIEWPORTSCISSOR_STATE = 1ULL << 50,113DIRTY_VERTEXSHADER_STATE = 1ULL << 51,114DIRTY_FRAGMENTSHADER_STATE = 1ULL << 52,115DIRTY_GEOMETRYSHADER_STATE = 1ULL << 53,116117// Note that the top 8 bits (54-63) cannot be dirtied through the commonCommandTable due to packing of other flags.118119// Everything that's not uniforms. Use this after using thin3d.120// TODO: Should we also add DIRTY_FRAMEBUF here? It kinda generally takes care of itself.121DIRTY_ALL_RENDER_STATE = DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE | DIRTY_GEOMETRYSHADER_STATE | DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS,122123DIRTY_ALL = 0xFFFFFFFFFFFFFFFF124};125126class ShaderManagerCommon {127public:128ShaderManagerCommon(Draw::DrawContext *draw) : draw_(draw) {}129virtual ~ShaderManagerCommon() {}130131virtual void ClearShaders() = 0;132virtual void DirtyLastShader() = 0;133134virtual void DeviceLost() = 0;135virtual void DeviceRestore(Draw::DrawContext *draw) = 0; // must set draw_ to draw136137virtual std::vector<std::string> DebugGetShaderIDs(DebugShaderType type) = 0;138virtual std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType) = 0;139140protected:141Draw::DrawContext *draw_ = nullptr;142};143144enum DoLightComputation {145LIGHT_OFF,146LIGHT_SHADE,147LIGHT_FULL,148};149150// PSP vertex format.151enum class PspAttributeLocation {152POSITION = 0,153TEXCOORD = 1,154NORMAL = 2,155W1 = 3,156W2 = 4,157COLOR0 = 5,158COLOR1 = 6,159160COUNT161};162163// Pre-fetched attrs and uniforms (used by GL only).164enum {165ATTR_POSITION = 0,166ATTR_TEXCOORD = 1,167ATTR_NORMAL = 2,168ATTR_W1 = 3,169ATTR_W2 = 4,170ATTR_COLOR0 = 5,171ATTR_COLOR1 = 6,172173ATTR_COUNT,174};175176177