| 138 | } |
| 139 | |
| 140 | BlueScriptValue Tr2GpuProfiler::GetRegionReport( size_t& index ) |
| 141 | { |
| 142 | #if BLUE_WITH_PYTHON |
| 143 | USE_MAIN_THREAD_RENDER_CONTEXT(); |
| 144 | |
| 145 | auto result = PyList_New( 0 ); |
| 146 | |
| 147 | while( index < m_zones.size() ) |
| 148 | { |
| 149 | auto& zone = m_zones[index++]; |
| 150 | if( zone.type == Zone::REGION_END ) |
| 151 | { |
| 152 | return result; |
| 153 | } |
| 154 | |
| 155 | PyObject* children; |
| 156 | if( zone.type == Zone::REGION_BEGIN ) |
| 157 | { |
| 158 | children = GetRegionReport( index ); |
| 159 | } |
| 160 | else |
| 161 | { |
| 162 | children = PyList_New( 0 ); |
| 163 | } |
| 164 | |
| 165 | auto stats = PyDict_New(); |
| 166 | { |
| 167 | auto value = PyFloat_FromDouble( zone.timer.GetTime( renderContext ) ); |
| 168 | PyDict_SetItemString( stats, "GPU Time", value ); |
| 169 | Py_DecRef( value ); |
| 170 | } |
| 171 | Tr2PipelineStatsDataAL data; |
| 172 | if( SUCCEEDED( zone.query.GetStats( data, renderContext ) ) ) |
| 173 | { |
| 174 | auto count = Tr2PipelineStatsQueryAL::GetValueCount( data ); |
| 175 | for( size_t i = 0; i < count; ++i ) |
| 176 | { |
| 177 | auto value = PyLong_FromLongLong( static_cast<long long>( Tr2PipelineStatsQueryAL::GetValue( data, i ) ) ); |
| 178 | PyDict_SetItemString( stats, Tr2PipelineStatsQueryAL::GetLabel( data, i ), value ); |
| 179 | Py_DecRef( value ); |
| 180 | } |
| 181 | } |
| 182 | PyObject* owner; |
| 183 | if( zone.owner ) |
| 184 | { |
| 185 | owner = PyOS->WrapBlueObject( zone.owner ); |
| 186 | } |
| 187 | else |
| 188 | { |
| 189 | owner = Py_None; |
| 190 | Py_IncRef( owner ); |
| 191 | } |
| 192 | PyObject* item = Py_BuildValue( "OsOO", owner, zone.message.c_str(), stats, children ); |
| 193 | Py_DecRef( stats ); |
| 194 | Py_DecRef( owner ); |
| 195 | |
| 196 | PyList_Append( result, item ); |
| 197 | Py_DecRef( item ); |