summaryrefslogtreecommitdiff
path: root/retrace/daemon/glframe_state.hpp
blob: 456723d06febdfdfc45ed0d1415f035deb93d2b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**************************************************************************
 *
 * Copyright 2015 Intel Corporation
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * Authors:
 *   Mark Janes <mark.a.janes@intel.com>
 **************************************************************************/

#ifndef _GLFRAME_STATE_HPP_
#define _GLFRAME_STATE_HPP_

#include <stdint.h>

#include <map>
#include <string>
#include <vector>

#include "glframe_retrace_interface.hpp"
#include "retrace.hpp"

namespace trace {
class Call;
}

namespace glretrace {
class OnFrameRetrace;

class StateTrack;
class OutputPoller {
 public:
  virtual void poll(int current_program, StateTrack *cb) = 0;
  virtual void pollBatch(SelectionId selectionCount,
                         ExperimentId experimentCount,
                         RenderId id,
                         OnFrameRetrace *cb) = 0;
  virtual ~OutputPoller() {}
  virtual void init() = 0;
};

enum ShaderType {
  kShaderTypeUnknown,
  kVertex,
  kFragment,
  kTessEval,
  kTessControl,
  kGeometry,
  kCompute
};

enum AssemblyType {
  kAssemblyTypeUnknown,
  kOriginal,
  kBeforeUnification,
  kAfterUnification,
  kBeforeOptimization,
  kConstCoalescing,
  kGenIrLowering,
  kLayout,
  kOptimized,
  kPushAnalysis,
  kCodeHoisting,
  kCodeSinking,
  kSimd8,
  kSimd16,
  kSimd32,
  kIr,
  kNirSsa,
  kNirFinal
};

// tracks subset of gl state for frameretrace purposes
class StateTrack {
 public:
  explicit StateTrack(OutputPoller *p);
  ~StateTrack() {}
  void track(const trace::Call &call);
  void flush();
  int CurrentProgram() const { return current_program; }
  const ShaderAssembly &currentVertexShader() const;
  const ShaderAssembly &currentFragmentShader() const;
  const ShaderAssembly &currentTessControlShader() const;
  const ShaderAssembly &currentTessEvalShader() const;
  const ShaderAssembly &currentGeomShader() const;
  const ShaderAssembly &currentCompShader() const;
  void onAssembly(ShaderType st, AssemblyType at, const std::string &assembly);
  int useProgram(int orig_program,
                 const std::string &vs, const std::string &fs,
                 const std::string &tessControl, const std::string &tessEval,
                 const std::string &geom, const std::string &comp,
                 std::string *message = NULL);
  void useProgram(int program);
  void retraceProgramSideEffects(int orig_program, trace::Call *c,
                                 retrace::Retracer *retracer) const;
  static void useProgramGL(int program);

 private:
  class TrackMap {
   public:
    TrackMap();
    bool track(StateTrack *tracker, const trace::Call &call);
   private:
    typedef void (glretrace::StateTrack::*MemberFunType)(const trace::Call&);
    std::map <std::string, MemberFunType> lookup;
  };
  static TrackMap lookup;
  class ProgramKey {
   public:
    ProgramKey(int orig_progam,
               const std::string &v, const std::string &f,
               const std::string &t_c, const std::string &t_e,
               const std::string &geom, const std::string &comp);
    bool operator<(const ProgramKey &o) const;
   private:
    int orig;
    std::string vs, fs, tess_control, tess_eval, geom, comp;
  };

  void parse();
  void trackCreateProgram(const trace::Call &);
  void trackAttachShader(const trace::Call &);
  void trackCreateShader(const trace::Call &);
  void trackShaderSource(const trace::Call &);
  void trackLinkProgram(const trace::Call &);
  void trackUseProgram(const trace::Call &);
  void trackDeleteProgram(const trace::Call &);
  void trackBindAttribLocation(const trace::Call &);
  void trackGetAttribLocation(const trace::Call &);
  void trackGetUniformLocation(const trace::Call &);
  void trackGetProgramResourceName(const trace::Call &);
  void trackGetUniformBlockIndex(const trace::Call &);
  void trackUniformBlockBinding(const trace::Call &);
  void trackBindFragDataLocation(const trace::Call &);
  void trackBindProgramPipeline(const trace::Call &);
  void trackUseProgramStages(const trace::Call &);

  OutputPoller *m_poller;
  int current_program, current_pipeline;
  std::map<int, std::string> shader_to_source;
  std::map<int, int> shader_to_type;
  std::map<std::string, int> source_to_shader;
  std::map<ProgramKey, int> m_sources_to_program;
  std::map<int, std::map<int, std::string>> m_program_to_bound_attrib;
  std::map<int, std::map<int, std::string>> m_program_to_uniform_name;
  std::map<int, std::map<std::string, int>> m_program_to_uniform_block_index;
  std::map<int, std::map<std::string, int>> m_program_to_frag_data_location;
  // key is program, internal key is index, value is binding
  std::map<int, std::map<int, int>> m_program_to_uniform_block_binding;

  // for these maps, key is program
  std::map<int, ShaderAssembly> program_to_vertex;
  std::map<int, ShaderAssembly> program_to_fragment;
  std::map<int, ShaderAssembly> program_to_tess_control;
  std::map<int, ShaderAssembly> program_to_tess_eval;
  std::map<int, ShaderAssembly> program_to_geom;
  std::map<int, ShaderAssembly> program_to_comp;

  // for these maps, key is pipeline.  Value is the program stage
  // bound to the pipeline
  std::map<int, int> pipeline_to_vertex_program;
  std::map<int, int> pipeline_to_fragment_program;
  std::map<int, int> pipeline_to_tess_control_program;
  std::map<int, int> pipeline_to_tess_eval_program;
  std::map<int, int> pipeline_to_geom_program;
  std::map<int, int> pipeline_to_comp_program;

  std::map<int, int> vertex_to_program;
  std::map<int, int> fragment_to_program;
  std::map<int, int> tess_control_to_program;
  std::map<int, int> tess_eval_to_program;
  std::map<int, int> geom_to_program;
  std::map<int, int> comp_to_program;

  const ShaderAssembly empty_shader;

  // any call with program side effects (eg glUniform) needs to be
  // executed on replacement programs (eg rendertarget highlighting)
  std::map<int, std::vector<int>> program_to_replacements;
};
}  // namespace glretrace
#endif