Home | History | Annotate | Download | only in ir
      1 /*
      2  * Copyright 2016 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SKSL_PROGRAM
      9 #define SKSL_PROGRAM
     10 
     11 #include <vector>
     12 #include <memory>
     13 
     14 #include "SkSLContext.h"
     15 #include "SkSLModifiers.h"
     16 #include "SkSLProgramElement.h"
     17 #include "SkSLSymbolTable.h"
     18 
     19 // name of the render target height uniform
     20 #define SKSL_RTHEIGHT_NAME "u_skRTHeight"
     21 
     22 namespace SkSL {
     23 
     24 /**
     25  * Represents a fully-digested program, ready for code generation.
     26  */
     27 struct Program {
     28     struct Settings {
     29         const GrShaderCaps* fCaps = nullptr;
     30         // if false, sk_FragCoord is exactly the same as gl_FragCoord. If true, the y coordinate
     31         // must be flipped.
     32         bool fFlipY = false;
     33     };
     34 
     35     struct Inputs {
     36         // if true, this program requires the render target height uniform to be defined
     37         bool fRTHeight;
     38 
     39         // if true, this program must be recompiled if the flipY setting changes. If false, the
     40         // program will compile to the same code regardless of the flipY setting.
     41         bool fFlipY;
     42 
     43         void reset() {
     44             fRTHeight = false;
     45             fFlipY = false;
     46         }
     47 
     48         bool isEmpty() {
     49             return !fRTHeight && !fFlipY;
     50         }
     51     };
     52 
     53     enum Kind {
     54         kFragment_Kind,
     55         kVertex_Kind,
     56         kGeometry_Kind
     57     };
     58 
     59     Program(Kind kind,
     60             Settings settings,
     61             Modifiers::Flag defaultPrecision,
     62             Context* context,
     63             std::vector<std::unique_ptr<ProgramElement>> elements,
     64             std::shared_ptr<SymbolTable> symbols,
     65             Inputs inputs)
     66     : fKind(kind)
     67     , fSettings(settings)
     68     , fDefaultPrecision(defaultPrecision)
     69     , fContext(context)
     70     , fSymbols(symbols)
     71     , fElements(std::move(elements))
     72     , fInputs(inputs) {}
     73 
     74     Kind fKind;
     75     Settings fSettings;
     76     // FIXME handle different types; currently it assumes this is for floats
     77     Modifiers::Flag fDefaultPrecision;
     78     Context* fContext;
     79     // it's important to keep fElements defined after (and thus destroyed before) fSymbols,
     80     // because destroying elements can modify reference counts in symbols
     81     std::shared_ptr<SymbolTable> fSymbols;
     82     std::vector<std::unique_ptr<ProgramElement>> fElements;
     83     Inputs fInputs;
     84 };
     85 
     86 } // namespace
     87 
     88 #endif
     89