1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 **************************************************************************/
26 // File: vogl_gl_state_snapshot.h
27 #ifndef VOGL_GL_STATE_SNAPSHOT_H
28 #define VOGL_GL_STATE_SNAPSHOT_H
30 #include "vogl_core.h"
31 #include "vogl_sparse_vector.h"
34 #include "vogl_common.h"
35 #include "vogl_general_context_state.h"
36 #include "vogl_texture_state.h"
37 #include "vogl_buffer_state.h"
38 #include "vogl_fbo_state.h"
39 #include "vogl_sampler_state.h"
40 #include "vogl_shader_state.h"
41 #include "vogl_program_state.h"
42 #include "vogl_renderbuffer_state.h"
43 #include "vogl_query_state.h"
44 #include "vogl_vao_state.h"
45 #include "vogl_texenv_state.h"
46 #include "vogl_light_state.h"
47 #include "vogl_material_state.h"
48 #include "vogl_display_list_state.h"
49 #include "vogl_matrix_state.h"
50 #include "vogl_current_vertex_attrib_state.h"
51 #include "vogl_arb_program_state.h"
52 #include "vogl_handle_tracker.h"
53 #include "vogl_default_framebuffer_state.h"
55 //----------------------------------------------------------------------------------------------------------------------
57 //----------------------------------------------------------------------------------------------------------------------
58 typedef vogl::hash_map<GLuint, GLenum> vogl_handle_hash_map;
59 typedef vogl::hash_map<GLuint> vogl_handle_hash_set;
60 typedef vogl::hash_map<uint64_t, empty_type> vogl_sync_hash_set;
62 //----------------------------------------------------------------------------------------------------------------------
63 // vogl_handle_to_sync
64 //----------------------------------------------------------------------------------------------------------------------
65 inline GLsync vogl_handle_to_sync(uint64_t handle)
68 memcpy(&sync, &handle, math::minimum<uint>(sizeof(GLsync), sizeof(uint64_t)));
72 //----------------------------------------------------------------------------------------------------------------------
73 // vogl_sync_to_handle
74 //----------------------------------------------------------------------------------------------------------------------
75 inline uint64_t vogl_sync_to_handle(GLsync sync)
78 memcpy(&handle, &sync, math::minimum<uint>(sizeof(GLsync), sizeof(uint64_t)));
82 //----------------------------------------------------------------------------------------------------------------------
83 // class vogl_capture_context_params
84 // TODO: Rename this to vogl_context_state_shadow?
85 //----------------------------------------------------------------------------------------------------------------------
86 class vogl_capture_context_params
89 vogl_capture_context_params()
90 : m_rbos(VOGL_NAMESPACE_RENDER_BUFFERS),
91 m_textures(VOGL_NAMESPACE_TEXTURES),
92 m_objs(VOGL_NAMESPACE_PROGRAMS),
93 m_filter_program_handles(false)
102 m_query_targets.clear();
103 m_buffer_targets.clear();
107 m_framebuffers.clear();
108 m_display_lists.clear();
109 m_arb_program_targets.clear();
115 m_linked_programs.clear();
117 m_program_handles_filter.clear();
118 m_filter_program_handles = false;
121 // During tracing: All handles live in the tracing GL namespace (there is no replay namespace).
122 // During replay: Any handles here live in the actual GL namespace (i.e. the "replay" or native GL namespace, NOT the trace namespace).
123 vogl_handle_hash_map m_query_targets;
124 vogl_handle_hash_map m_buffer_targets;
125 vogl_handle_hash_set m_samplers;
126 vogl_handle_hash_set m_vaos;
127 vogl_sync_hash_set m_syncs;
128 vogl_handle_hash_set m_framebuffers;
129 vogl_handle_hash_map m_arb_program_targets;
131 // During replay: trace domain
132 vogl_display_list_state m_display_lists;
134 // During replay: replay domain
135 vogl_linked_program_state m_linked_programs;
137 // During replay: These objects map from trace (non-inv) to replay (inv).
138 // TODO: Transition ALL the above hash sets/maps to instances of vogl_handle_tracker.
139 vogl_handle_tracker m_rbos;
140 vogl_handle_tracker m_textures;
141 vogl_handle_tracker m_objs;
143 vogl_handle_hash_set m_program_handles_filter;
144 bool m_filter_program_handles;
147 //----------------------------------------------------------------------------------------------------------------------
148 // class vogl_state_snapshot
149 //----------------------------------------------------------------------------------------------------------------------
150 class vogl_context_snapshot
152 VOGL_NO_COPY_OR_ASSIGNMENT_OP(vogl_context_snapshot);
155 vogl_context_snapshot();
156 ~vogl_context_snapshot();
160 bool capture(const vogl_context_desc &desc, const vogl_context_info &info, const vogl_capture_context_params &capture_params, vogl_handle_remapper &remapper);
162 bool is_valid() const
167 const vogl_context_desc &get_context_desc() const
169 return m_context_desc;
171 const vogl_context_info &get_context_info() const
173 return m_context_info;
176 bool remap_handles(vogl_handle_remapper &remapper);
178 const vogl_general_context_state &get_general_state() const
180 return m_general_state;
182 vogl_general_context_state &get_general_state()
184 return m_general_state;
187 const vogl_texenv_state &get_texenv_state() const
189 return m_texenv_state;
191 vogl_texenv_state &get_texenv_state()
193 return m_texenv_state;
196 const vogl_light_state &get_light_state() const
198 return m_light_state;
200 vogl_light_state &get_light_state()
202 return m_light_state;
205 const vogl_material_state &get_material_state() const
207 return m_material_state;
209 vogl_material_state &get_material_state()
211 return m_material_state;
214 const vogl_display_list_state &get_display_list_state() const
216 return m_display_list_state;
218 vogl_display_list_state &get_display_list_state()
220 return m_display_list_state;
223 const vogl_matrix_state &get_matrix_state() const
225 return m_matrix_state;
227 vogl_matrix_state &get_matrix_state()
229 return m_matrix_state;
232 const vogl_polygon_stipple_state &get_polygon_stipple_state() const
234 return m_polygon_stipple_state;
236 vogl_polygon_stipple_state &get_polygon_stipple_state()
238 return m_polygon_stipple_state;
241 const vogl_gl_object_state_ptr_vec &get_objects() const
243 return m_object_ptrs;
245 vogl_gl_object_state_ptr_vec &get_objects()
247 return m_object_ptrs;
250 const vogl_current_vertex_attrib_state &get_current_vertex_attrib_state() const
252 return m_current_vertex_attrib_state;
254 vogl_current_vertex_attrib_state &get_current_vertex_attrib_state()
256 return m_current_vertex_attrib_state;
259 const vogl_arb_program_environment_state &get_arb_program_environment_state() const
261 return m_arb_program_environment_state;
263 vogl_arb_program_environment_state &get_arb_program_environment_state()
265 return m_arb_program_environment_state;
268 void get_all_objects_of_category(vogl_gl_object_state_type state_type, vogl_gl_object_state_ptr_vec &obj_ptr_vec) const;
270 bool serialize(json_node &node, vogl_blob_manager &blob_manager, const vogl_ctypes *pCtypes) const;
271 bool deserialize(const json_node &node, const vogl_blob_manager &blob_manager, const vogl_ctypes *pCtypes);
274 vogl_context_desc m_context_desc;
275 vogl_context_info m_context_info;
277 vogl_general_context_state m_general_state;
278 vogl_texenv_state m_texenv_state;
279 vogl_light_state m_light_state;
280 vogl_material_state m_material_state;
281 vogl_display_list_state m_display_list_state;
282 vogl_matrix_state m_matrix_state;
283 vogl_polygon_stipple_state m_polygon_stipple_state;
284 vogl_current_vertex_attrib_state m_current_vertex_attrib_state;
285 vogl_arb_program_environment_state m_arb_program_environment_state;
287 vogl_gl_object_state_ptr_vec m_object_ptrs;
289 bool capture_objects(vogl_gl_object_state_type state_type, const vogl_capture_context_params &capture_params, vogl_handle_remapper &remapper);
293 void destroy_objects();
296 typedef vogl::vector<vogl_context_snapshot *> vogl_context_snapshot_ptr_vec;
298 //----------------------------------------------------------------------------------------------------------------------
299 // struct vogl_client_side_array_desc
300 //----------------------------------------------------------------------------------------------------------------------
301 struct vogl_client_side_array_desc
303 vogl_client_side_array_desc()
306 vogl_client_side_array_desc(vogl_trace_ptr_value ptr, uint size)
307 : m_ptr(ptr), m_size(size)
311 void init(vogl_trace_ptr_value ptr, uint size)
317 vogl_trace_ptr_value m_ptr;
320 bool serialize(json_node &node, vogl_blob_manager &blob_manager) const
324 VOGL_NOTE_UNUSED(blob_manager);
326 node.add_key_value("ptr", m_ptr);
327 node.add_key_value("size", m_size);
331 bool deserialize(const json_node &node, const vogl_blob_manager &blob_manager)
335 VOGL_NOTE_UNUSED(blob_manager);
337 m_ptr = node.value_as_uint64("ptr");
338 m_size = node.value_as_uint32("size");
343 typedef vogl::vector<vogl_client_side_array_desc> vogl_client_side_array_desc_vec;
345 //----------------------------------------------------------------------------------------------------------------------
346 // class vogl_gl_state_snapshot
347 //----------------------------------------------------------------------------------------------------------------------
348 class vogl_gl_state_snapshot
350 VOGL_NO_COPY_OR_ASSIGNMENT_OP(vogl_gl_state_snapshot);
353 vogl_gl_state_snapshot();
354 ~vogl_gl_state_snapshot();
358 // frame_index indicates the beginning of frame X, at a swap boundary
359 bool begin_capture(uint window_width, uint window_height, vogl_trace_ptr_value cur_context, uint frame_index, int64_t gl_call_counter, bool at_frame_boundary);
361 void add_client_side_array_ptrs(const vogl_client_side_array_desc_vec &client_side_vertex_attrib_ptrs, const vogl_client_side_array_desc_vec &client_side_array_ptrs, const vogl_client_side_array_desc_vec &client_side_texcoord_ptrs);
363 bool capture_context(
364 const vogl_context_desc &desc, const vogl_context_info &info, vogl_handle_remapper &remapper,
365 const vogl_capture_context_params &capture_params);
369 bool is_valid() const
374 bool serialize(json_node &node, vogl_blob_manager &blob_manager, const vogl_ctypes *pCtypes) const;
375 bool deserialize(const json_node &node, const vogl_blob_manager &blob_manager, const vogl_ctypes *pCtypes);
377 md5_hash get_uuid() const
381 uint get_window_width() const
383 return m_window_width;
385 uint get_window_height() const
387 return m_window_height;
389 vogl_trace_ptr_value get_cur_trace_context() const
391 return m_cur_trace_context;
394 void set_frame_index(uint frame_index)
396 m_frame_index = frame_index;
398 uint get_frame_index() const
400 return m_frame_index;
402 int64_t get_gl_call_counter() const
404 return m_gl_call_counter;
406 bool get_at_frame_boundary() const
408 return m_at_frame_boundary;
411 bool get_is_restorable() const
413 return m_is_restorable;
415 void set_is_restorable(bool is_restorable)
417 m_is_restorable = is_restorable;
420 const vogl_client_side_array_desc_vec &get_client_side_vertex_attrib_ptrs() const
422 return m_client_side_vertex_attrib_ptrs;
424 const vogl_client_side_array_desc_vec &get_client_side_array_ptrs() const
426 return m_client_side_array_ptrs;
428 const vogl_client_side_array_desc_vec &get_client_side_texcoord_ptrs() const
430 return m_client_side_texcoord_ptrs;
433 const vogl_context_snapshot_ptr_vec &get_contexts() const
435 return m_context_ptrs;
437 vogl_context_snapshot_ptr_vec &get_contexts()
439 return m_context_ptrs;
442 const vogl_default_framebuffer_state &get_default_framebuffer() const
444 return m_default_framebuffer;
446 vogl_default_framebuffer_state &get_default_framebuffer()
448 return m_default_framebuffer;
451 vogl_context_snapshot* get_context(vogl_trace_ptr_value contextHandle) const
453 for (vogl_context_snapshot_ptr_vec::const_iterator iter = m_context_ptrs.begin(); iter != m_context_ptrs.end(); iter++)
455 if ((*iter)->get_context_desc().get_trace_context() == contextHandle)
466 uint m_window_height;
467 vogl_trace_ptr_value m_cur_trace_context;
469 int64_t m_gl_call_counter;
470 bool m_at_frame_boundary;
471 bool m_is_restorable;
473 vogl_client_side_array_desc_vec m_client_side_vertex_attrib_ptrs;
474 vogl_client_side_array_desc_vec m_client_side_array_ptrs;
475 vogl_client_side_array_desc_vec m_client_side_texcoord_ptrs;
477 vogl_context_snapshot_ptr_vec m_context_ptrs;
479 vogl_default_framebuffer_state m_default_framebuffer;
481 bool m_captured_default_framebuffer;
484 void destroy_contexts()
486 for (uint i = 0; i < m_context_ptrs.size(); i++)
487 vogl_delete(m_context_ptrs[i]);
488 m_context_ptrs.clear();
494 VOGL_DEFINE_BITWISE_MOVABLE(vogl_context_snapshot);
495 VOGL_DEFINE_BITWISE_MOVABLE(vogl_gl_state_snapshot);
498 #endif // VOGL_GL_STATE_SNAPSHOT_H