NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
StateDump.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2011, NVIDIA Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA Corporation nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "io/StateDump.hpp"
29 
30 using namespace FW;
31 
32 //------------------------------------------------------------------------
33 
35 {
36  clear();
37  S32 num;
38  s >> num;
39  for (int i = 0; i < num; i++)
40  {
41  String id;
42  Array<U8>* data = new Array<U8>;
43  s >> id >> *data;
44  setInternal(data, id);
45  }
46 }
47 
48 //------------------------------------------------------------------------
49 
51 {
52  s << m_values.getSize();
53  for (int i = m_values.firstSlot(); i != -1; i = m_values.nextSlot(i))
54  s << m_values.getSlot(i).key << *m_values.getSlot(i).value;
55 }
56 
57 //------------------------------------------------------------------------
58 
59 void StateDump::clear(void)
60 {
61  for (int i = m_values.firstSlot(); i != -1; i = m_values.nextSlot(i))
62  delete m_values.getSlot(i).value;
63  m_values.clear();
64 }
65 
66 //------------------------------------------------------------------------
67 
68 void StateDump::add(const StateDump& other)
69 {
70  if (&other != this)
71  for (int i = other.m_values.firstSlot(); i != -1; i = other.m_values.nextSlot(i))
72  setInternal(new Array<U8>(*other.m_values.getSlot(i).value), other.m_values.getSlot(i).key);
73 }
74 
75 //------------------------------------------------------------------------
76 
77 const Array<U8>* StateDump::get(const String& id) const
78 {
79  Array<U8>* const* data = m_values.search(xlateId(id));
80  return (data) ? *data : NULL;
81 }
82 
83 //------------------------------------------------------------------------
84 
85 bool StateDump::get(void* ptr, int size, const String& id)
86 {
87  FW_ASSERT(size >= 0);
88  FW_ASSERT(ptr || !size);
89 
90  Array<U8>* const* data = m_values.search(xlateId(id));
91  if (!data)
92  return false;
93 
94  FW_ASSERT((*data)->getNumBytes() == size);
95  memcpy(ptr, (*data)->getPtr(), size);
96  return true;
97 }
98 
99 //------------------------------------------------------------------------
100 
101 void StateDump::set(const void* ptr, int size, const String& id)
102 {
103  setInternal(new Array<U8>((const U8*)ptr, size), xlateId(id));
104 }
105 
106 //------------------------------------------------------------------------
107 
108 void StateDump::setInternal(Array<U8>* data, const String& id)
109 {
110  if (m_values.contains(id))
111  delete m_values.remove(id);
112  if (data)
113  m_values.add(id, data);
114 }
115 
116 //------------------------------------------------------------------------
virtual void writeToStream(OutputStream &s) const
Definition: StateDump.cpp:50
#define NULL
Definition: Defs.hpp:39
void clear(void)
Definition: StateDump.cpp:59
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid * data
Definition: DLLImports.inl:319
void ** ptr
Definition: DLLImports.cpp:74
void add(const StateDump &other)
Definition: StateDump.cpp:68
void set(const StateDump &other)
Definition: StateDump.hpp:49
#define FW_ASSERT(X)
Definition: Defs.hpp:67
signed int S32
Definition: Defs.hpp:88
virtual void readFromStream(InputStream &s)
Definition: StateDump.cpp:34
unsigned char U8
Definition: Defs.hpp:83
const Array< U8 > * get(const String &id) const
Definition: StateDump.cpp:77
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr size
Definition: DLLImports.inl:319