MCPcopy Create free account
hub / github.com/carbonengine/trinity / GetVideoMemoryInfo

Function GetVideoMemoryInfo

trinity/TriDevice_Blue.cpp:78–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76
77
78PyObject* GetVideoMemoryInfo( PyObject* self, PyObject* args )
79{
80 if( !PyArg_ParseTuple( args, "" ) )
81 {
82 return NULL;
83 }
84 if( !gTriDev )
85 {
86 PyErr_SetString( PyExc_ValueError, "device is not available yet" );
87 return nullptr;
88 }
89
90#if TRINITY_PLATFORM == TRINITY_DIRECTX12
91 CComPtr<IDXGIAdapter1> dxgiAdapter;
92 CComPtr<IDXGIOutput> output;
93
94 if( FAILED( TrinityALImpl::GetVideoAdapter( gTriDev->GetAdapter(), &dxgiAdapter, &output ) ) )
95 {
96 PyErr_SetString( PyExc_OSError, "failed to query the GPU adapter" );
97 return nullptr;
98 }
99
100 CComQIPtr<IDXGIAdapter3> adapter( dxgiAdapter );
101 if( !adapter )
102 {
103 PyErr_SetString( PyExc_OSError, "no OS support: old Windows version?" );
104 return nullptr;
105 }
106
107 auto result = PyDict_New();
108
109 auto ExtractInfo = [&]( auto group, const char* groupName ) {
110 DXGI_QUERY_VIDEO_MEMORY_INFO info;
111 if( FAILED( adapter->QueryVideoMemoryInfo( 0, group, &info ) ) )
112 {
113 return;
114 }
115
116 auto dict = PyDict_New();
117 auto value = PyLong_FromSize_t( info.AvailableForReservation );
118 PyDict_SetItemString( dict, "AvailableForReservation", value );
119 Py_DecRef( value );
120 value = PyLong_FromSize_t( info.Budget );
121 PyDict_SetItemString( dict, "Budget", value );
122 Py_DecRef( value );
123 value = PyLong_FromSize_t( info.CurrentReservation );
124 PyDict_SetItemString( dict, "CurrentReservation", value );
125 Py_DecRef( value );
126 value = PyLong_FromSize_t( info.CurrentUsage );
127 PyDict_SetItemString( dict, "CurrentUsage", value );
128 Py_DecRef( value );
129 PyDict_SetItemString( result, groupName, dict );
130 Py_DecRef( dict );
131 };
132
133 ExtractInfo( DXGI_MEMORY_SEGMENT_GROUP_LOCAL, "Local" );
134 ExtractInfo( DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, "NonLocal" );
135

Callers

nothing calls this directly

Calls 1

GetVideoAdapterFunction · 0.85

Tested by

no test coverage detected