Skip to content

Commit ee01609

Browse files
committed
Adding nvidia multicast extension support.
1 parent e0f39cd commit ee01609

26 files changed

+892
-40
lines changed

include/cinder/Camera.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ class CI_API CameraPersp : public Camera {
224224
//! Returns a Camera whose eyePoint is positioned to exactly frame \a worldSpaceSphere but is equivalent in other parameters (including orientation). Sets the result's pivotDistance to be the distance to \a worldSpaceSphere's center.
225225
CameraPersp calcFraming( const Sphere &worldSpaceSphere ) const;
226226

227+
//! Returns a subdivided portion of this camera's view frustrum as a new CameraPersp; useful for multi-gpu or tiled-rendering for instance.
228+
CameraPersp subdivide( uint8_t columns, uint8_t rows, uint8_t columnIndex, uint8_t rowIndex ) const;
227229
protected:
228230
vec2 mLensShift;
229231

include/cinder/app/RendererGl.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class CI_API RendererGl : public Renderer {
7878
mDebugContext = false;
7979
mDebugLogSeverity = 0;
8080
mDebugBreakSeverity = 0;
81+
mNvidiaMGpuEnabled = false;
82+
mNvidiaMGpuMode = NvidiaMGpuMode::SINGLE;
8183
#endif
8284
mObjectTracking = false;
8385
mStencil = false;
@@ -101,6 +103,8 @@ class CI_API RendererGl : public Renderer {
101103
int getMsaa() const { return mMsaaSamples; }
102104

103105
#if ! defined( CINDER_GL_ES )
106+
enum class NvidiaMGpuMode { SINGLE, AFR, MULTICAST, MULTI_DISPLAY_MULTICAST };
107+
104108
//! Enables a debug context (per \c ARB_debug_output). Currently only implemented by MSW and Linux GL implementations. By default this is made \c GL_DEBUG_OUTPUT_SYNCHRONOUS
105109
Options& debug() { mDebugContext = true; return *this; }
106110
//! Returns whether the context has debug enabled
@@ -113,6 +117,18 @@ class CI_API RendererGl : public Renderer {
113117
Options& debugBreak( GLenum severity = GL_DEBUG_SEVERITY_HIGH ) { mDebugBreakSeverity = severity; mDebugContext = true; return *this; }
114118
//! Returns the severity threshold for debug breaking. A value of \c 0 indicates debugBreak is off.
115119
GLenum getDebugBreakSeverity() const { return mDebugBreakSeverity; }
120+
//! (NVIDIA ONLY) Specify the multi-GPU strategy (SLI mode) to be WGL_CONTEXT_MULTIGPU_ATTRIB_SINGLE_NV.
121+
Options& nvidiaMGpuSingle() { mNvidiaMGpuEnabled = true; mNvidiaMGpuMode = NvidiaMGpuMode::SINGLE; return *this; }
122+
//! (NVIDIA ONLY) Specify the multi-GPU strategy (SLI mode) to be WGL_CONTEXT_MULTIGPU_ATTRIB_AFR_NV.
123+
Options& nvidiaMGpuAFR() { mNvidiaMGpuEnabled = true; mNvidiaMGpuMode = NvidiaMGpuMode::AFR; return *this; }
124+
//! (NVIDIA ONLY) Specify the multi-GPU strategy (SLI mode) to be WGL_CONTEXT_MULTIGPU_ATTRIB_MULTICAST_NV.
125+
Options& nvidiaMGpuMulticast() { mNvidiaMGpuEnabled = true; mNvidiaMGpuMode = NvidiaMGpuMode::MULTICAST; return *this; }
126+
//! (NVIDIA ONLY) Specify the multi-GPU strategy (SLI mode) to be WGL_CONTEXT_MULTIGPU_ATTRIB_MULTI_DISPLAY_MULTICAST_NV.
127+
Options& nvidiaMGpuMDisplayMulticast() { mNvidiaMGpuEnabled = true; mNvidiaMGpuMode = NvidiaMGpuMode::MULTI_DISPLAY_MULTICAST; return *this; }
128+
//! (NVIDIA ONLY) Returns whether multi-GPU (SLI mode) is active or not.
129+
bool isNvidiaMGpuEnabled() const { return mNvidiaMGpuEnabled; }
130+
//! (NVIDIA ONLY) Returns the multi-GPU strategy (SLI mode).
131+
NvidiaMGpuMode getNvidiaMGpuMode() const { return mNvidiaMGpuMode; }
116132
#endif
117133

118134
//! Enables Context-level tracking of live objects. Defaults to \c false.
@@ -149,6 +165,8 @@ class CI_API RendererGl : public Renderer {
149165
bool mDebugContext;
150166
GLenum mDebugLogSeverity; // initial value of 0 means debug logging is disabled
151167
GLenum mDebugBreakSeverity; // initial value of 0 means debug break is disabled
168+
bool mNvidiaMGpuEnabled;
169+
NvidiaMGpuMode mNvidiaMGpuMode;
152170
#endif
153171
bool mObjectTracking;
154172
};

include/cinder/app/Window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ class CI_API Window : public std::enable_shared_from_this<Window> {
467467
}
468468

469469
void setApp( AppBase *app ) { mApp = app; }
470+
void applyCurrentContext();
470471

471472
#if defined( CINDER_COCOA )
472473
#if defined( __OBJC__ )

include/cinder/gl/BufferObj.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ class CI_API BufferObj {
9696
//! Sets the debugging label associated with the Buffer. Calls glObjectLabel() when available.
9797
void setLabel( const std::string &label );
9898

99+
//! Analogous to glBufferStorage .
100+
void bufferStorage( GLsizeiptr size, const void* data, GLbitfield flags ) const;
101+
//! Analogous to glNamedBufferStorage.
102+
void namedBufferStorage( GLsizeiptr size, const void* data, GLbitfield flags ) const;
99103
protected:
100104
BufferObj( GLenum target );
101105
BufferObj( GLenum target, GLsizeiptr allocationSize, const void *data, GLenum usage );

include/cinder/gl/Ssbo.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ class CI_API Ssbo : public BufferObj {
4747
inline void bindBase( GLuint index ) { glBindBufferBase( mTarget, index, mId ); mBase = index; }
4848
//! Unbinds the buffer.
4949
inline void unbindBase() { glBindBufferBase( mTarget, mBase, 0 ); mBase = 0; }
50-
//! Analogous to bufferStorage.
51-
inline void bufferStorage( GLsizeiptr size, const void *data, GLbitfield flags ) const { glBufferStorage( mTarget, size, data, flags ); }
5250
protected:
5351
Ssbo( GLsizeiptr allocationSize, const void *data = nullptr, GLenum usage = GL_STATIC_DRAW )
5452
: BufferObj( GL_SHADER_STORAGE_BUFFER, allocationSize, data, usage ),

include/cinder/gl/Texture.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ class CI_API TextureBase {
270270
//! Sets the debugging label associated with the Texture. Calls glObjectLabel() when available.
271271
Format& label( const std::string &label ) { setLabel( label ); return *this; }
272272

273+
//! (NVIDIA only) Returns whether per-gpu storage is enabled.
274+
bool isPerGpuStorage() const { return mPerGpuStorage; }
275+
//! (NVIDIA only) Enables per-gpu storage for multi-gpu multicast.
276+
void setPerGpuStorage( bool perGpuStorage ) { mPerGpuStorage = perGpuStorage; }
277+
//! (NVIDIA only) Enables per-gpu storage for multi-gpu multicast.
278+
Format& perGpuStorage( bool enable = true ) { mPerGpuStorage = enable; return *this; }
273279
protected:
274280
Format();
275281

@@ -282,6 +288,7 @@ class CI_API TextureBase {
282288
GLuint mBaseMipmapLevel;
283289
GLint mMaxMipmapLevel;
284290
bool mImmutableStorage;
291+
bool mPerGpuStorage;
285292
GLfloat mMaxAnisotropy;
286293
GLint mInternalFormat, mDataType;
287294
bool mSwizzleSpecified;
@@ -425,10 +432,10 @@ class CI_API Texture1d : public TextureBase {
425432
Format& immutableStorage( bool immutable = true ) { setImmutableStorage( immutable ); return *this; }
426433
//! Sets the debugging label associated with the Texture. Calls glObjectLabel() when available.
427434
Format& label( const std::string &label ) { setLabel( label ); return *this; }
428-
429435
//! Sets a custom deleter for destruction of the shared_ptr<Texture1d>
430436
Format& deleter( const std::function<void(Texture1d*)> &sharedPtrDeleter ) { mDeleter = sharedPtrDeleter; return *this; }
431-
437+
//! (NVIDIA only) Enables per-gpu storage for multi-gpu multicast.
438+
Format& perGpuStorage( bool enable = true ) { mPerGpuStorage = enable; return *this; }
432439
protected:
433440
std::function<void(Texture1d*)> mDeleter;
434441

@@ -503,7 +510,8 @@ class CI_API Texture2d : public TextureBase {
503510
Format& label( const std::string &label ) { setLabel( label ); return *this; }
504511
//! Sets a custom deleter for destruction of the shared_ptr<Texture2d>
505512
Format& deleter( const std::function<void(Texture2d*)> &sharedPtrDeleter ) { mDeleter = sharedPtrDeleter; return *this; }
506-
513+
//! (NVIDIA only) Enables per-gpu storage for multi-gpu multicast.
514+
Format& perGpuStorage( bool enable = true ) { mPerGpuStorage = enable; return *this; }
507515
protected:
508516
bool mLoadTopDown;
509517
std::function<void(Texture2d*)> mDeleter;
@@ -597,6 +605,8 @@ class CI_API Texture2d : public TextureBase {
597605
bool isTopDown() const { return mTopDown; }
598606
//! Marks whether the scanlines of the image are stored top-down in memory relative to the base address. Default is \c false.
599607
void setTopDown( bool topDown = true ) { mTopDown = topDown; }
608+
//! Explicitly regenerate mipmaps assuming mipmapping is enabled.
609+
void regenerateMipmap();
600610

601611
//! Returns an ImageSource pointing to this Texture
602612
ImageSourceRef createSource();
@@ -662,10 +672,10 @@ class CI_API Texture3d : public TextureBase {
662672
Format& immutableStorage( bool immutable = true ) { setImmutableStorage( immutable ); return *this; }
663673
//! Sets the debugging label associated with the Texture. Calls glObjectLabel() when available.
664674
Format& label( const std::string &label ) { setLabel( label ); return *this; }
665-
666675
//! Sets a custom deleter for destruction of the shared_ptr<Texture3d>
667676
Format& deleter( const std::function<void(Texture3d*)> &sharedPtrDeleter ) { mDeleter = sharedPtrDeleter; return *this; }
668-
677+
//! (NVIDIA only) Enables per-gpu storage for multi-gpu multicast.
678+
Format& perGpuStorage( bool enable = true ) { mPerGpuStorage = enable; return *this; }
669679
protected:
670680
std::function<void(Texture3d*)> mDeleter;
671681

@@ -723,10 +733,10 @@ class CI_API TextureCubeMap : public TextureBase
723733
Format& immutableStorage( bool immutable = true ) { setImmutableStorage( immutable ); return *this; }
724734
//! Sets the debugging label associated with the Texture. Calls glObjectLabel() when available.
725735
Format& label( const std::string &label ) { setLabel( label ); return *this; }
726-
727736
//! Sets a custom deleter for destruction of the shared_ptr<TextureCubeMap>
728737
Format& deleter( const std::function<void(TextureCubeMap*)> &sharedPtrDeleter ) { mDeleter = sharedPtrDeleter; return *this; }
729-
738+
//! (NVIDIA only) Enables per-gpu storage for multi-gpu multicast.
739+
Format& perGpuStorage( bool enable = true ) { mPerGpuStorage = enable; return *this; }
730740
protected:
731741
std::function<void(TextureCubeMap*)> mDeleter;
732742

@@ -756,7 +766,8 @@ class CI_API TextureCubeMap : public TextureBase
756766

757767
//! Replaces the pixels (and data store) of a Texture with contents of \a textureData.
758768
void replace( const TextureData &textureData );
759-
769+
//! Explicitly regenerate mipmaps assuming mipmapping is enabled.
770+
void regenerateMipmap();
760771
protected:
761772
TextureCubeMap( int32_t width, int32_t height, Format format );
762773
template<typename T>

include/cinder/gl/nv/Multicast.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#pragma once
2+
3+
#include "cinder/gl/platform.h"
4+
5+
#include <memory>
6+
#include <vector>
7+
8+
namespace cinder {
9+
namespace gl {
10+
11+
class BufferObj;
12+
class TextureBase;
13+
14+
namespace nv {
15+
namespace multicast {
16+
17+
class Device {
18+
public:
19+
explicit Device( GLuint index ) : mIndex{ index }, mMask{ 1u << index } { }
20+
virtual ~Device() { }
21+
Device( const Device& other ) = default;
22+
Device( Device&& other ) = default;
23+
Device& operator=( const Device& other ) = default;
24+
Device& operator=( Device&& other ) = default;
25+
26+
GLuint getIndex() const;
27+
GLbitfield getMask() const;
28+
protected:
29+
GLuint mIndex;
30+
GLbitfield mMask;
31+
};
32+
33+
class Context {
34+
public:
35+
static Context& instance();
36+
bool isEnabled() const;
37+
const std::vector<Device>& getDevices() const;
38+
GLbitfield getMaskAll() const;
39+
private:
40+
Context();
41+
42+
std::vector<Device> mLinkedDevices;
43+
GLbitfield mMaskAll;
44+
};
45+
46+
bool isEnabled();
47+
48+
const std::vector<Device>& getDevices();
49+
50+
//! Note: If a function restricted by UploadGpuMaskNVX operates on textures or buffer objects with GPU-shared storage type (as opposed to per-GPU storage ), UPLOAD_GPU_MASK_NVX is ignored.
51+
void enableUploadMask( const Device& device );
52+
void enableUploadMask( GLbitfield mask );
53+
void disableUploadMask();
54+
55+
void enableRenderMask( const Device& device );
56+
void enableRenderMask( GLbitfield mask );
57+
void disableRenderMask();
58+
59+
//! Signal other device to wait for this GPU to finish its work.
60+
void signalWaitSync( const Device& source, const Device& target );
61+
62+
//! Signal all masked devices to wait for this GPU to finish its work.
63+
void signalWaitSync( GLbitfield indexSource, GLbitfield targetMask );
64+
65+
void updateMasked( const std::shared_ptr<BufferObj>& buffer, GLsizeiptr size, const void* data, GLbitfield gpuMask );
66+
67+
void copyTexture( const std::shared_ptr<TextureBase>& source, const std::shared_ptr<TextureBase>& destination, GLuint sourceDeviceIndex, GLbitfield destinationMask );
68+
69+
void scissor( const Device& device, const glm::ivec2& position, const glm::ivec2& size );
70+
void viewport( const Device& device, const glm::ivec2& position, const glm::ivec2& size );
71+
}
72+
}
73+
}
74+
}

proj/vc2019/cinder.vcxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@
779779
<ClCompile Include="..\..\src\cinder\gl\EnvironmentEs.cpp" />
780780
<ClCompile Include="..\..\src\cinder\gl\Fbo.cpp" />
781781
<ClCompile Include="..\..\src\cinder\gl\GlslProg.cpp" />
782+
<ClCompile Include="..\..\src\cinder\gl\nv\Multicast.cpp" />
782783
<ClCompile Include="..\..\src\cinder\gl\Pbo.cpp" />
783784
<ClCompile Include="..\..\src\cinder\gl\Query.cpp" />
784785
<ClCompile Include="..\..\src\cinder\gl\scoped.cpp" />
@@ -1092,6 +1093,7 @@
10921093
<ClInclude Include="..\..\include\cinder\gl\Fbo.h" />
10931094
<ClInclude Include="..\..\include\cinder\gl\gl.h" />
10941095
<ClInclude Include="..\..\include\cinder\gl\GlslProg.h" />
1096+
<ClInclude Include="..\..\include\cinder\gl\nv\Multicast.h" />
10951097
<ClInclude Include="..\..\include\cinder\gl\Pbo.h" />
10961098
<ClInclude Include="..\..\include\cinder\gl\platform.h" />
10971099
<ClInclude Include="..\..\include\cinder\gl\Query.h" />
@@ -1380,4 +1382,4 @@
13801382
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
13811383
<ImportGroup Label="ExtensionTargets">
13821384
</ImportGroup>
1383-
</Project>
1385+
</Project>

proj/vc2019/cinder.vcxproj.filters

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@
238238
<Filter Include="Source Files\glad">
239239
<UniqueIdentifier>{ae176410-bb73-4c73-be34-5fcfee9cf95c}</UniqueIdentifier>
240240
</Filter>
241+
<Filter Include="Source Files\gl\nv">
242+
<UniqueIdentifier>{a601d014-b852-46fa-9829-896bfdee2d0a}</UniqueIdentifier>
243+
</Filter>
244+
<Filter Include="Header Files\gl\nv">
245+
<UniqueIdentifier>{7ff32b0d-8190-49b2-ab18-187db6196a2b}</UniqueIdentifier>
246+
</Filter>
241247
</ItemGroup>
242248
<ItemGroup>
243249
<ClCompile Include="..\..\src\cinder\Area.cpp">
@@ -744,7 +750,6 @@
744750
<ClCompile Include="..\..\src\cinder\gl\VboMesh.cpp">
745751
<Filter>Source Files\gl</Filter>
746752
</ClCompile>
747-
748753
<ClCompile Include="..\..\src\cinder\GeomIo.cpp">
749754
<Filter>Source Files</Filter>
750755
</ClCompile>
@@ -1042,6 +1047,9 @@
10421047
<ClCompile Include="..\..\src\glad\glad_es.c">
10431048
<Filter>Source Files\glad</Filter>
10441049
</ClCompile>
1050+
<ClCompile Include="..\..\src\cinder\gl\nv\Multicast.cpp">
1051+
<Filter>Source Files\gl\nv</Filter>
1052+
</ClCompile>
10451053
</ItemGroup>
10461054
<ItemGroup>
10471055
<ClInclude Include="..\..\src\AntTweakBar\AntPerfTimer.h">
@@ -2199,5 +2207,8 @@
21992207
<ClInclude Include="..\..\include\cinder\FileWatcher.h">
22002208
<Filter>Header Files</Filter>
22012209
</ClInclude>
2210+
<ClInclude Include="..\..\include\cinder\gl\nv\Multicast.h">
2211+
<Filter>Header Files\gl\nv</Filter>
2212+
</ClInclude>
22022213
</ItemGroup>
22032214
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"resolution": [1920, 1080],
3+
"fullscreen": false,
4+
"borderless": false,
5+
"multicast_multidisplay": false,
6+
"copy_to_primary": true,
7+
"vsync": false
8+
}

0 commit comments

Comments
 (0)