Commit 7399f6db authored by Sean McBride's avatar Sean McBride
Browse files

Changed public API of vtkGPUInfo to return vtkTypeUInt64 for memory sizes.

It previously used vtkIdType which could be 32 bit even on 64 bit systems.
Fixes overflow in the case of 32 bit vtkIdType and GPUs with more
than 2 GiB of memory.

Also changed "MB" to "MiB" in test output, since it's base 2.

Change-Id: I23ba36647596cc49e3a65fab5784e18c021070e1
parent ad745b5e
......@@ -35,34 +35,34 @@ public:
// Description:
// Set/Get dedicated video memory in bytes. Initial value is 0.
// Usually the fastest one. If it is not null, it should be take into
// Usually the fastest one. If it is not 0, it should be taken into
// account first and DedicatedSystemMemory or SharedSystemMemory should be
// ignored.
vtkSetMacro(DedicatedVideoMemory, vtkIdType);
vtkGetMacro(DedicatedVideoMemory, vtkIdType);
vtkSetMacro(DedicatedVideoMemory, vtkTypeUInt64);
vtkGetMacro(DedicatedVideoMemory, vtkTypeUInt64);
// Description:
// Set/Get dedicated system memory in bytes. Initial value is 0.
// This is slow memory. If it is not null, this value should be taken into
// This is slow memory. If it is not 0, this value should be taken into
// account only if there is no DedicatedVideoMemory and SharedSystemMemory
// should be ignored.
vtkSetMacro(DedicatedSystemMemory, vtkIdType);
vtkGetMacro(DedicatedSystemMemory, vtkIdType);
vtkSetMacro(DedicatedSystemMemory, vtkTypeUInt64);
vtkGetMacro(DedicatedSystemMemory, vtkTypeUInt64);
// Description:
// Set/Get shared system memory in bytes. Initial value is 0.
// Slowest memory. This value should be taken into account only if there is
// neither DedicatedVideoMemory nor DedicatedSystemMemory.
vtkSetMacro(SharedSystemMemory, vtkIdType);
vtkGetMacro(SharedSystemMemory, vtkIdType);
vtkSetMacro(SharedSystemMemory, vtkTypeUInt64);
vtkGetMacro(SharedSystemMemory, vtkTypeUInt64);
protected:
vtkGPUInfo();
~vtkGPUInfo();
vtkIdType DedicatedVideoMemory;
vtkIdType DedicatedSystemMemory;
vtkIdType SharedSystemMemory;
vtkTypeUInt64 DedicatedVideoMemory;
vtkTypeUInt64 DedicatedSystemMemory;
vtkTypeUInt64 SharedSystemMemory;
private:
vtkGPUInfo(const vtkGPUInfo&); // Not implemented.
......
......@@ -28,13 +28,13 @@ int TestGPUInfo(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
{
cout << " GPU " << i << ": " << endl;
vtkGPUInfo *info=l->GetGPUInfo(i);
vtkIdType value;
vtkTypeUInt64 value;
value=info->GetDedicatedVideoMemory();
cout << " dedicated VRAM=" << value/(1024*1024) << " MB" << endl;
cout << " dedicated VRAM=" << value/(1024*1024) << " MiB" << endl;
value=info->GetDedicatedSystemMemory();
cout << " dedicated RAM=" << value/(1024*1024) << " MB" << endl;
cout << " dedicated RAM=" << value/(1024*1024) << " MiB" << endl;
value=info->GetSharedSystemMemory();
cout << " shared RAM=" << value/(1024*1024) << " MB" << endl;
cout << " shared RAM=" << value/(1024*1024) << " MiB" << endl;
++i;
}
l->Delete();
......
......@@ -48,14 +48,13 @@ void vtkCoreGraphicsGPUInfoList::Probe()
for (GLint i = 0; i < count; i++)
{
GLint vramGL = 0;
vtkIdType vramVTK = 0;
vtkTypeUInt64 vramVTK = 0;
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
error = CGLDescribeRenderer(infoObj, i, kCGLRPVideoMemoryMegabytes, &vramGL);
vramVTK = static_cast<vtkIdType>(vramGL);
vramVTK *= (1024 * 1024); // may overflow with 32 bit vtkIdType and big GPU
vramVTK = static_cast<vtkTypeUInt64>(vramGL) * 1024 * 1024;
#else
error = CGLDescribeRenderer(infoObj, i, kCGLRPVideoMemory, &vramGL);
vramVTK = static_cast<vtkIdType>(vramGL);
vramVTK = static_cast<vtkTypeUInt64>(vramGL);
#endif
// The software renderer will return a video memory of 0, so ignore it.
......
......@@ -78,7 +78,7 @@ void vtkXGPUInfoList::Probe()
ramSize=0;
}
vtkGPUInfo *info=vtkGPUInfo::New();
info->SetDedicatedVideoMemory(static_cast<vtkIdType>(ramSize)*1024); // ramSize is in KB
info->SetDedicatedVideoMemory(static_cast<vtkTypeUInt64>(ramSize)*1024); // ramSize is in KiB
this->Array->v[j]=info;
++j;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment