Commit a4e7a4db authored by Samuli Laine's avatar Samuli Laine
Browse files

Remove glew dependency

parent 7b346299
...@@ -19,10 +19,6 @@ For business inquiries, please contact [researchinquiries@nvidia.com](mailto:res ...@@ -19,10 +19,6 @@ For business inquiries, please contact [researchinquiries@nvidia.com](mailto:res
We do not currently accept outside code contributions in the form of pull requests. We do not currently accept outside code contributions in the form of pull requests.
[GLEW](https://github.com/nigels-com/glew) library redistributed under the
[Modified BSD License](http://glew.sourceforge.net/glew.txt), the
[Mesa 3-D License](http://glew.sourceforge.net/mesa.txt) (MIT) and the
[Khronos License](http://glew.sourceforge.net/khronos.txt) (MIT).
Environment map stored as part of `samples/data/envphong.npz` is derived from a Wave Engine Environment map stored as part of `samples/data/envphong.npz` is derived from a Wave Engine
[sample material](https://github.com/WaveEngine/Samples/tree/master/Materials/EnvironmentMap/Content/Assets/CubeMap.cubemap) [sample material](https://github.com/WaveEngine/Samples/tree/master/Materials/EnvironmentMap/Content/Assets/CubeMap.cubemap)
originally shared under originally shared under
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# #
# This file defaults to pytorch/pytorch as it works on slightly older # This file defaults to pytorch/pytorch as it works on slightly older
# driver versions. # driver versions.
ARG BASE_IMAGE=pytorch/pytorch:1.6.0-cuda10.1-cudnn7-devel ARG BASE_IMAGE=pytorch/pytorch:1.7.1-cuda11.0-cudnn8-devel
FROM $BASE_IMAGE FROM $BASE_IMAGE
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
...@@ -44,14 +44,6 @@ ENV PYOPENGL_PLATFORM egl ...@@ -44,14 +44,6 @@ ENV PYOPENGL_PLATFORM egl
COPY docker/10_nvidia.json /usr/share/glvnd/egl_vendor.d/10_nvidia.json COPY docker/10_nvidia.json /usr/share/glvnd/egl_vendor.d/10_nvidia.json
# glew installation from source
RUN curl -L https://downloads.sourceforge.net/project/glew/glew/2.1.0/glew-2.1.0.tgz > /tmp/glew-2.1.0.tgz
RUN mkdir -p /tmp && \
cd /tmp && tar zxf /tmp/glew-2.1.0.tgz && cd glew-2.1.0 && \
SYSTEM=linux-egl make && \
SYSTEM=linux-egl make install && \
rm -rf /tmp/glew-2.1.0.zip /tmp/glew-2.1.0
RUN pip install imageio imageio-ffmpeg RUN pip install imageio imageio-ffmpeg
COPY nvdiffrast /tmp/pip/nvdiffrast/ COPY nvdiffrast /tmp/pip/nvdiffrast/
......
...@@ -994,7 +994,7 @@ severity will be silent.</td></tr></table></div> ...@@ -994,7 +994,7 @@ severity will be silent.</td></tr></table></div>
<p>This work is made available under the <a href="https://github.com/NVlabs/nvdiffrast/blob/main/LICENSE.txt">Nvidia Source Code License</a>.</p> <p>This work is made available under the <a href="https://github.com/NVlabs/nvdiffrast/blob/main/LICENSE.txt">Nvidia Source Code License</a>.</p>
<p>For business inquiries, please contact <a href="mailto:researchinquiries@nvidia.com">researchinquiries@nvidia.com</a></p> <p>For business inquiries, please contact <a href="mailto:researchinquiries@nvidia.com">researchinquiries@nvidia.com</a></p>
<p>We do not currently accept outside contributions in the form of pull requests.</p> <p>We do not currently accept outside contributions in the form of pull requests.</p>
<p><a href="https://github.com/nigels-com/glew">GLEW</a> library redistributed under the <a href="http://glew.sourceforge.net/glew.txt">Modified BSD License</a>, the <a href="http://glew.sourceforge.net/mesa.txt">Mesa 3-D License</a> (MIT) and the <a href="http://glew.sourceforge.net/khronos.txt">Khronos License</a> (MIT). Environment map stored as part of <code>samples/data/envphong.npz</code> is derived from a Wave Engine <a href="https://github.com/WaveEngine/Samples/tree/master/Materials/EnvironmentMap/Content/Assets/CubeMap.cubemap">sample material</a> originally shared under <a href="https://github.com/WaveEngine/Samples/blob/master/LICENSE.md">MIT License</a>. Mesh and texture stored as part of <code>samples/data/earth.npz</code> are derived from <a href="https://www.turbosquid.com/3d-models/3d-realistic-earth-photorealistic-2k-1279125">3D Earth Photorealistic 2K</a> model originally made available under <a href="https://blog.turbosquid.com/turbosquid-3d-model-license/#3d-model-license">TurboSquid 3D Model License</a>.</p> <p>Environment map stored as part of <code>samples/data/envphong.npz</code> is derived from a Wave Engine <a href="https://github.com/WaveEngine/Samples/tree/master/Materials/EnvironmentMap/Content/Assets/CubeMap.cubemap">sample material</a> originally shared under <a href="https://github.com/WaveEngine/Samples/blob/master/LICENSE.md">MIT License</a>. Mesh and texture stored as part of <code>samples/data/earth.npz</code> are derived from <a href="https://www.turbosquid.com/3d-models/3d-realistic-earth-photorealistic-2k-1279125">3D Earth Photorealistic 2K</a> model originally made available under <a href="https://blog.turbosquid.com/turbosquid-3d-model-license/#3d-model-license">TurboSquid 3D Model License</a>.</p>
<h2 id="citation">Citation</h2> <h2 id="citation">Citation</h2>
<pre><code>@article{Laine2020diffrast, <pre><code>@article{Laine2020diffrast,
title = {Modular Primitives for High-Performance Differentiable Rendering}, title = {Modular Primitives for High-Performance Differentiable Rendering},
......
...@@ -6,4 +6,4 @@ ...@@ -6,4 +6,4 @@
# distribution of this software and related documentation without an express # distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited. # license agreement from NVIDIA CORPORATION is strictly prohibited.
__version__ = '0.2.4' __version__ = '0.2.5'
...@@ -42,7 +42,7 @@ using namespace tensorflow::shape_inference; ...@@ -42,7 +42,7 @@ using namespace tensorflow::shape_inference;
#define NVDR_CTX_ARGS int _nvdr_ctx_dummy #define NVDR_CTX_ARGS int _nvdr_ctx_dummy
#define NVDR_CTX_PARAMS 0 #define NVDR_CTX_PARAMS 0
#define NVDR_CHECK(COND, ERR) do { TORCH_CHECK(COND, ERR) } while(0) #define NVDR_CHECK(COND, ERR) do { TORCH_CHECK(COND, ERR) } while(0)
#define NVDR_CHECK_CUDA_ERROR(CUDA_CALL) do { cudaError_t err = CUDA_CALL; TORCH_CHECK(err == CUDA_SUCCESS, "Cuda error: ", cudaGetLastError(), "[", #CUDA_CALL, ";]"); } while(0) #define NVDR_CHECK_CUDA_ERROR(CUDA_CALL) do { cudaError_t err = CUDA_CALL; TORCH_CHECK(!err, "Cuda error: ", cudaGetLastError(), "[", #CUDA_CALL, ";]"); } while(0)
#define NVDR_CHECK_GL_ERROR(GL_CALL) do { GL_CALL; GLenum err = glGetError(); TORCH_CHECK(err == GL_NO_ERROR, "OpenGL error: ", getGLErrorString(err), "[", #GL_CALL, ";]"); } while(0) #define NVDR_CHECK_GL_ERROR(GL_CALL) do { GL_CALL; GLenum err = glGetError(); TORCH_CHECK(err == GL_NO_ERROR, "OpenGL error: ", getGLErrorString(err), "[", #GL_CALL, ";]"); } while(0)
#endif #endif
......
...@@ -6,64 +6,118 @@ ...@@ -6,64 +6,118 @@
// distribution of this software and related documentation without an express // distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited. // license agreement from NVIDIA CORPORATION is strictly prohibited.
#pragma once //------------------------------------------------------------------------
// Common.
//------------------------------------------------------------------------
#include "framework.h" #include "framework.h"
#include "glutil.h"
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
// Create the function pointers.
#define GLUTIL_EXT(return_type, name, ...) return_type (GLAPIENTRY* name)(__VA_ARGS__) = 0;
#include "glutil_extlist.h"
#undef GLUTIL_EXT
// Track initialization status.
static volatile bool s_glExtInitialized = false;
// Error strings.
const char* getGLErrorString(GLenum err)
{
switch(err)
{
case GL_NO_ERROR: return "GL_NO_ERROR";
case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW";
case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW";
case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION";
case GL_TABLE_TOO_LARGE: return "GL_TABLE_TOO_LARGE";
case GL_CONTEXT_LOST: return "GL_CONTEXT_LOST";
}
return "Unknown error";
}
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Windows. // Windows.
//------------------------------------------------------------------------ //------------------------------------------------------------------------
#ifdef _WIN32 #ifdef _WIN32
#define NOMINMAX
#include <windows.h>
#define GLEW_STATIC
#include "../lib/glew.h"
#include <GL/gl.h>
#include <cuda_gl_interop.h>
//------------------------------------------------------------------------ static CRITICAL_SECTION getInitializedCriticalSection(void)
{
CRITICAL_SECTION cs;
InitializeCriticalSection(&cs);
return cs;
}
static CRITICAL_SECTION s_getProcAddressMutex = getInitializedCriticalSection();
struct GLContext static void safeGetProcAddress(const char* name, PROC* pfn)
{ {
HDC hdc; PROC result = wglGetProcAddress(name);
HGLRC hglrc; if (!result)
int glewInitialized; {
}; LeaveCriticalSection(&s_getProcAddressMutex); // Prepare for thread exit.
LOG(FATAL) << "wglGetProcAddress() failed for '" << name << "'";
exit(1); // Should never get here but make sure we exit.
}
*pfn = result;
}
//------------------------------------------------------------------------ static void initializeGLExtensions(void)
{
// Use critical section for thread safety.
EnterCriticalSection(&s_getProcAddressMutex);
// Only dig function pointers if not done already.
if (!s_glExtInitialized)
{
// Generate code to populate the function pointers.
#define GLUTIL_EXT(return_type, name, ...) safeGetProcAddress(#name, (PROC*)&name);
#include "glutil_extlist.h"
#undef GLUTIL_EXT
// Mark as initialized.
s_glExtInitialized = true;
}
// Done.
LeaveCriticalSection(&s_getProcAddressMutex);
return;
}
static void setGLContext(GLContext& glctx) void setGLContext(GLContext& glctx)
{ {
if (!glctx.hglrc) if (!glctx.hglrc)
LOG(FATAL) << "setGLContext() called with null gltcx"; LOG(FATAL) << "setGLContext() called with null gltcx";
if (!wglMakeCurrent(glctx.hdc, glctx.hglrc)) if (!wglMakeCurrent(glctx.hdc, glctx.hglrc))
LOG(FATAL) << "wglMakeCurrent() failed when setting GL context"; LOG(FATAL) << "wglMakeCurrent() failed when setting GL context";
if (glctx.glewInitialized) if (glctx.extInitialized)
return; return;
GLenum result = glewInit(); initializeGLExtensions();
if (result != GLEW_OK) glctx.extInitialized = 1;
LOG(FATAL) << "glewInit() failed, return value = " << result;
glctx.glewInitialized = 1;
} }
static void releaseGLContext(void) void releaseGLContext(void)
{ {
if (!wglMakeCurrent(NULL, NULL)) if (!wglMakeCurrent(NULL, NULL))
LOG(FATAL) << "wglMakeCurrent() failed when releasing GL context"; LOG(FATAL) << "wglMakeCurrent() failed when releasing GL context";
} }
extern "C" int set_gpu(const char*); extern "C" int set_gpu(const char*); // In setgpu.lib
GLContext createGLContext(int cudaDeviceIdx)
static GLContext createGLContext(int cudaDeviceIdx)
{ {
if (cudaDeviceIdx >= 0) if (cudaDeviceIdx >= 0)
{ {
char pciBusId[256] = ""; char pciBusId[256] = "";
LOG(INFO) << "Creating GL context for Cuda device " << cudaDeviceIdx; LOG(INFO) << "Creating GL context for Cuda device " << cudaDeviceIdx;
if (cudaDeviceGetPCIBusId(pciBusId, 255, cudaDeviceIdx) != CUDA_SUCCESS) if (cudaDeviceGetPCIBusId(pciBusId, 255, cudaDeviceIdx))
{ {
LOG(INFO) << "PCI bus id query failed"; LOG(INFO) << "PCI bus id query failed";
} }
...@@ -115,7 +169,7 @@ static GLContext createGLContext(int cudaDeviceIdx) ...@@ -115,7 +169,7 @@ static GLContext createGLContext(int cudaDeviceIdx)
return glctx; return glctx;
} }
static void destroyGLContext(GLContext& glctx) void destroyGLContext(GLContext& glctx)
{ {
if (!glctx.hglrc) if (!glctx.hglrc)
LOG(FATAL) << "destroyGLContext() called with null gltcx"; LOG(FATAL) << "destroyGLContext() called with null gltcx";
...@@ -148,31 +202,44 @@ static void destroyGLContext(GLContext& glctx) ...@@ -148,31 +202,44 @@ static void destroyGLContext(GLContext& glctx)
//------------------------------------------------------------------------ //------------------------------------------------------------------------
#ifdef __linux__ #ifdef __linux__
#define GLEW_NO_GLU
#define EGL_NO_X11 // X11/Xlib.h has "#define Status int" which breaks Tensorflow. Avoid it.
#define MESA_EGL_NO_X11_HEADERS
#if 1
# include "../lib/glew.h" // Use local glew.h
#else
# include <GL/glew.h> // Use system-supplied glew.h
#endif
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GL/gl.h>
#include <cuda_gl_interop.h>
//------------------------------------------------------------------------ static pthread_mutex_t s_getProcAddressMutex;
struct GLContext typedef void (*PROCFN)();
static void safeGetProcAddress(const char* name, PROCFN* pfn)
{ {
EGLDisplay display; PROCFN result = eglGetProcAddress(name);
EGLContext context; if (!result)
int glewInitialized; {
}; pthread_mutex_unlock(&s_getProcAddressMutex); // Prepare for thread exit.
LOG(FATAL) << "wglGetProcAddress() failed for '" << name << "'";
exit(1); // Should never get here but make sure we exit.
}
*pfn = result;
}
//------------------------------------------------------------------------ static void initializeGLExtensions(void)
{
pthread_mutex_lock(&s_getProcAddressMutex);
static void setGLContext(GLContext& glctx) // Only dig function pointers if not done already.
if (!s_glExtInitialized)
{
// Generate code to populate the function pointers.
#define GLUTIL_EXT(return_type, name, ...) safeGetProcAddress(#name, (PROCFN*)&name);
#include "glutil_extlist.h"
#undef GLUTIL_EXT
// Mark as initialized.
s_glExtInitialized = true;
}
pthread_mutex_unlock(&s_getProcAddressMutex);
return;
}
void setGLContext(GLContext& glctx)
{ {
if (!glctx.context) if (!glctx.context)
LOG(FATAL) << "setGLContext() called with null gltcx"; LOG(FATAL) << "setGLContext() called with null gltcx";
...@@ -180,16 +247,13 @@ static void setGLContext(GLContext& glctx) ...@@ -180,16 +247,13 @@ static void setGLContext(GLContext& glctx)
if (!eglMakeCurrent(glctx.display, EGL_NO_SURFACE, EGL_NO_SURFACE, glctx.context)) if (!eglMakeCurrent(glctx.display, EGL_NO_SURFACE, EGL_NO_SURFACE, glctx.context))
LOG(ERROR) << "eglMakeCurrent() failed when setting GL context"; LOG(ERROR) << "eglMakeCurrent() failed when setting GL context";
if (glctx.glewInitialized) if (glctx.extInitialized)
return; return;
initializeGLExtensions();
GLenum result = glewInit(); glctx.extInitialized = 1;
if (result != GLEW_OK)
LOG(FATAL) << "glewInit() failed, return value = " << result;
glctx.glewInitialized = 1;
} }
static void releaseGLContext(void) void releaseGLContext(void)
{ {
EGLDisplay display = eglGetCurrentDisplay(); EGLDisplay display = eglGetCurrentDisplay();
if (display == EGL_NO_DISPLAY) if (display == EGL_NO_DISPLAY)
...@@ -229,13 +293,13 @@ static EGLDisplay getCudaDisplay(int cudaDeviceIdx) ...@@ -229,13 +293,13 @@ static EGLDisplay getCudaDisplay(int cudaDeviceIdx)
eglQueryDevicesEXT(0, 0, &num_devices); eglQueryDevicesEXT(0, 0, &num_devices);
if (!num_devices) if (!num_devices)
return 0; return 0;
EGLDisplay display = 0; EGLDisplay display = 0;
EGLDeviceEXT* devices = (EGLDeviceEXT*)malloc(num_devices * sizeof(void*)); EGLDeviceEXT* devices = (EGLDeviceEXT*)malloc(num_devices * sizeof(void*));
eglQueryDevicesEXT(num_devices, devices, &num_devices); eglQueryDevicesEXT(num_devices, devices, &num_devices);
for (int i=0; i < num_devices; i++) for (int i=0; i < num_devices; i++)
{ {
EGLDeviceEXT device = devices[i]; EGLDeviceEXT device = devices[i];
intptr_t value = -1; intptr_t value = -1;
if (eglQueryDeviceAttribEXT(device, EGL_CUDA_DEVICE_NV, &value) && value == cudaDeviceIdx) if (eglQueryDeviceAttribEXT(device, EGL_CUDA_DEVICE_NV, &value) && value == cudaDeviceIdx)
{ {
...@@ -248,7 +312,7 @@ static EGLDisplay getCudaDisplay(int cudaDeviceIdx) ...@@ -248,7 +312,7 @@ static EGLDisplay getCudaDisplay(int cudaDeviceIdx)
return display; return display;
} }
static GLContext createGLContext(int cudaDeviceIdx) GLContext createGLContext(int cudaDeviceIdx)
{ {
EGLDisplay display = 0; EGLDisplay display = 0;
...@@ -261,7 +325,7 @@ static GLContext createGLContext(int cudaDeviceIdx) ...@@ -261,7 +325,7 @@ static GLContext createGLContext(int cudaDeviceIdx)
LOG(INFO) << "Failed, falling back to default display"; LOG(INFO) << "Failed, falling back to default display";
} }
if (!display) if (!display)
{ {
display = eglGetDisplay(EGL_DEFAULT_DISPLAY); display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (display == EGL_NO_DISPLAY) if (display == EGL_NO_DISPLAY)
...@@ -312,7 +376,7 @@ static GLContext createGLContext(int cudaDeviceIdx) ...@@ -312,7 +376,7 @@ static GLContext createGLContext(int cudaDeviceIdx)
return glctx; return glctx;
} }
static void destroyGLContext(GLContext& glctx) void destroyGLContext(GLContext& glctx)
{ {
if (!glctx.context) if (!glctx.context)
LOG(FATAL) << "destroyGLContext() called with null gltcx"; LOG(FATAL) << "destroyGLContext() called with null gltcx";
...@@ -332,28 +396,8 @@ static void destroyGLContext(GLContext& glctx) ...@@ -332,28 +396,8 @@ static void destroyGLContext(GLContext& glctx)
memset(&glctx, 0, sizeof(GLContext)); memset(&glctx, 0, sizeof(GLContext));
} }
#endif // __linux__
//------------------------------------------------------------------------
// Common.
//------------------------------------------------------------------------ //------------------------------------------------------------------------
static const char* getGLErrorString(GLenum err) #endif // __linux__
{
switch(err)
{
case GL_NO_ERROR: return "GL_NO_ERROR";
case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW";
case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW";
case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION";
case GL_TABLE_TOO_LARGE: return "GL_TABLE_TOO_LARGE";
case GL_CONTEXT_LOST: return "GL_CONTEXT_LOST";
}
return "Unknown error";
}
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
#pragma once
//------------------------------------------------------------------------
// Windows-specific headers and types.
//------------------------------------------------------------------------
#ifdef _WIN32
#define NOMINMAX
#include <windows.h> // Required by gl.h in Windows.
#define GLAPIENTRY APIENTRY
struct GLContext
{
HDC hdc;
HGLRC hglrc;
int extInitialized;
};
#endif // _WIN32
//------------------------------------------------------------------------
// Linux-specific headers and types.
//------------------------------------------------------------------------
#ifdef __linux__
#define EGL_NO_X11 // X11/Xlib.h has "#define Status int" which breaks Tensorflow. Avoid it.
#define MESA_EGL_NO_X11_HEADERS
#include <EGL/egl.h>
#include <EGL/eglext.h>
#define GLAPIENTRY
struct GLContext
{
EGLDisplay display;
EGLContext context;
int extInitialized;
};
#endif // __linux__
//------------------------------------------------------------------------
// OpenGL, CUDA interop, GL extensions.
//------------------------------------------------------------------------
#define GL_GLEXT_LEGACY
#include <GL/gl.h>
#include <cuda_gl_interop.h>
// Constants.
#ifndef GL_VERSION_1_2
#define GL_CLAMP_TO_EDGE 0x812F
#define GL_TEXTURE_3D 0x806F
#endif
#ifndef GL_VERSION_1_5
#define GL_ARRAY_BUFFER 0x8892
#define GL_DYNAMIC_DRAW 0x88E8
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
#endif
#ifndef GL_VERSION_2_0
#define GL_FRAGMENT_SHADER 0x8B30
#define GL_INFO_LOG_LENGTH 0x8B84
#define GL_LINK_STATUS 0x8B82
#define GL_VERTEX_SHADER 0x8B31
#endif
#ifndef GL_VERSION_3_0
#define GL_MAJOR_VERSION 0x821B
#define GL_MINOR_VERSION 0x821C
#define GL_RGBA32F 0x8814
#define GL_TEXTURE_2D_ARRAY 0x8C1A
#endif
#ifndef GL_VERSION_3_2
#define GL_GEOMETRY_SHADER 0x8DD9
#endif
#ifndef GL_ARB_framebuffer_object
#define GL_COLOR_ATTACHMENT0 0x8CE0
#define GL_COLOR_ATTACHMENT1 0x8CE1
#define GL_DEPTH_STENCIL 0x84F9
#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A
#define GL_DEPTH24_STENCIL8 0x88F0
#define GL_FRAMEBUFFER 0x8D40
#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506
#define GL_UNSIGNED_INT_24_8 0x84FA
#endif
#ifndef GL_ARB_imaging
#define GL_TABLE_TOO_LARGE 0x8031
#endif
#ifndef GL_KHR_robustness
#define GL_CONTEXT_LOST 0x0507
#endif
// Declare function pointers to OpenGL extension functions.
#define GLUTIL_EXT(return_type, name, ...) extern return_type (GLAPIENTRY* name)(__VA_ARGS__);
#include "glutil_extlist.h"
#undef GLUTIL_EXT
//------------------------------------------------------------------------
// Common functions.
//------------------------------------------------------------------------
void setGLContext (GLContext& glctx);
void releaseGLContext (void);
GLContext createGLContext (int cudaDeviceIdx);
void destroyGLContext (GLContext& glctx);
const char* getGLErrorString (GLenum err);
//------------------------------------------------------------------------
// Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
#ifndef GL_VERSION_1_2
GLUTIL_EXT(void, glTexImage3D, GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
#endif
#ifndef GL_VERSION_1_5
GLUTIL_EXT(void, glBindBuffer, GLenum target, GLuint buffer);
GLUTIL_EXT(void, glBufferData, GLenum target, ptrdiff_t size, const void* data, GLenum usage);
GLUTIL_EXT(void, glGenBuffers, GLsizei n, GLuint* buffers);
#endif
#ifndef GL_VERSION_2_0
GLUTIL_EXT(void, glAttachShader, GLuint program, GLuint shader);
GLUTIL_EXT(void, glCompileShader, GLuint shader);
GLUTIL_EXT(GLuint, glCreateProgram, void);
GLUTIL_EXT(GLuint, glCreateShader, GLenum type);
GLUTIL_EXT(void, glDrawBuffers, GLsizei n, const GLenum* bufs);
GLUTIL_EXT(void, glEnableVertexAttribArray, GLuint index);
GLUTIL_EXT(void, glGetProgramInfoLog, GLuint program, GLsizei bufSize, GLsizei* length, char* infoLog);
GLUTIL_EXT(void, glGetProgramiv, GLuint program, GLenum pname, GLint* param);
GLUTIL_EXT(void, glLinkProgram, GLuint program);
GLUTIL_EXT(void, glShaderSource, GLuint shader, GLsizei count, const char *const* string, const GLint* length);
GLUTIL_EXT(void, glUniform2f, GLint location, GLfloat v0, GLfloat v1);
GLUTIL_EXT(void, glUseProgram, GLuint program);
GLUTIL_EXT(void, glVertexAttribPointer, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* pointer);
#endif
#ifndef GL_VERSION_3_2
GLUTIL_EXT(void, glFramebufferTexture, GLenum target, GLenum attachment, GLuint texture, GLint level);
#endif
#ifndef GL_ARB_framebuffer_object
GLUTIL_EXT(void, glBindFramebuffer, GLenum target, GLuint framebuffer);
GLUTIL_EXT(void, glGenFramebuffers, GLsizei n, GLuint* framebuffers);
#endif
#ifndef GL_ARB_vertex_array_object
GLUTIL_EXT(void, glBindVertexArray, GLuint array);
GLUTIL_EXT(void, glGenVertexArrays, GLsizei n, GLuint* arrays);
#endif
#ifndef GL_ARB_multi_draw_indirect
GLUTIL_EXT(void, glMultiDrawElementsIndirect, GLenum mode, GLenum type, const void *indirect, GLsizei primcount, GLsizei stride);
#endif
//------------------------------------------------------------------------
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
// license agreement from NVIDIA CORPORATION is strictly prohibited. // license agreement from NVIDIA CORPORATION is strictly prohibited.
#include "rasterize.h" #include "rasterize.h"
#include "glutil.inl" #include "glutil.h"
#include <vector> #include <vector>
#define STRINGIFY_SHADER_SOURCE(x) #x #define STRINGIFY_SHADER_SOURCE(x) #x
......
...@@ -35,10 +35,11 @@ struct RasterizeGradParams ...@@ -35,10 +35,11 @@ struct RasterizeGradParams
}; };
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// The rest is for C++ compilation only when using torch. // Do not try to include OpenGL stuff when compiling CUDA kernels for torch.
#if !defined(NVDR_TORCH) || !defined(__CUDACC__) #if !(defined(NVDR_TORCH) && defined(__CUDACC__))
#include "glutil.inl" #include "framework.h"
#include "glutil.h"
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Draw command struct used by rasterizer. // Draw command struct used by rasterizer.
...@@ -93,4 +94,4 @@ void rasterizeRender(NVDR_CTX_ARGS, RasterizeGLState& s, cudaStream_t stream, co ...@@ -93,4 +94,4 @@ void rasterizeRender(NVDR_CTX_ARGS, RasterizeGLState& s, cudaStream_t stream, co
void rasterizeCopyResults(NVDR_CTX_ARGS, RasterizeGLState& s, cudaStream_t stream, float** outputPtr, int width, int height, int depth); void rasterizeCopyResults(NVDR_CTX_ARGS, RasterizeGLState& s, cudaStream_t stream, float** outputPtr, int width, int height, int depth);
//------------------------------------------------------------------------ //------------------------------------------------------------------------
#endif // !defined(NVDR_TORCH) || !defined(__CUDACC__) #endif // !(defined(NVDR_TORCH) && defined(__CUDACC__))
This diff is collapsed.
...@@ -18,8 +18,8 @@ from . import plugin_loader ...@@ -18,8 +18,8 @@ from . import plugin_loader
# OpenGL-related linker options depending on platform. # OpenGL-related linker options depending on platform.
def _get_gl_opts(): def _get_gl_opts():
libs = { libs = {
'posix': ['GL', 'GLEW'], 'posix': ['GL', 'EGL'],
'nt': ['gdi32', 'glew32s', 'opengl32', 'user32', 'setgpu'], 'nt': ['gdi32', 'opengl32', 'user32', 'setgpu'],
} }
return ['-l' + x for x in libs[os.name]] return ['-l' + x for x in libs[os.name]]
......
...@@ -156,7 +156,7 @@ def get_plugin(cuda_file, extra_nvcc_options=[]): ...@@ -156,7 +156,7 @@ def get_plugin(cuda_file, extra_nvcc_options=[]):
compile_opts = '' compile_opts = ''
if os.name == 'nt': if os.name == 'nt':
compile_opts += '"%s"' % os.path.join(tf.sysconfig.get_lib(), 'python', '_pywrap_tensorflow_internal.lib') compile_opts += '"%s"' % os.path.join(tf.sysconfig.get_lib(), 'python', '_pywrap_tensorflow_internal.lib')
compile_opts += ' --library-path="%s"' % (os.path.dirname(__file__) + r"\..\lib") # Find glew32s.lib during compilation. compile_opts += ' --library-path="%s"' % (os.path.dirname(__file__) + r"\..\lib") # Find libraries during compilation.
elif os.name == 'posix': elif os.name == 'posix':
compile_opts += '"%s"' % os.path.join(tf.sysconfig.get_lib(), 'python', '_pywrap_tensorflow_internal.so') compile_opts += '"%s"' % os.path.join(tf.sysconfig.get_lib(), 'python', '_pywrap_tensorflow_internal.so')
compile_opts += ' --compiler-options \'-fPIC -D_GLIBCXX_USE_CXX11_ABI=0\'' compile_opts += ' --compiler-options \'-fPIC -D_GLIBCXX_USE_CXX11_ABI=0\''
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ #define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__
#include "../common/framework.h" #include "../common/framework.h"
#include "../common/glutil.cpp"
#include "../common/common.h" #include "../common/common.h"
#include "../common/common.cpp" #include "../common/common.cpp"
......
...@@ -45,14 +45,15 @@ def _get_plugin(): ...@@ -45,14 +45,15 @@ def _get_plugin():
# Linker options. # Linker options.
if os.name == 'posix': if os.name == 'posix':
ldflags = ['-lGL', '-lGLEW', '-lEGL'] ldflags = ['-lGL', '-lEGL']
elif os.name == 'nt': elif os.name == 'nt':
libs = ['gdi32', 'glew32s', 'opengl32', 'user32', 'setgpu'] libs = ['gdi32', 'opengl32', 'user32', 'setgpu']
ldflags = ['/LIBPATH:' + lib_dir] + ['/DEFAULTLIB:' + x for x in libs] ldflags = ['/LIBPATH:' + lib_dir] + ['/DEFAULTLIB:' + x for x in libs]
# List of source files. # List of source files.
source_files = [ source_files = [
'../common/common.cpp', '../common/common.cpp',
'../common/glutil.cpp',
'../common/rasterize.cu', '../common/rasterize.cu',
'../common/rasterize.cpp', '../common/rasterize.cpp',
'../common/interpolate.cu', '../common/interpolate.cu',
......
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