Blender  V3.3
optix/compat.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2019, NVIDIA Corporation.
3  * Copyright 2019-2022 Blender Foundation. */
4 
5 #pragma once
6 
7 #define OPTIX_DONT_INCLUDE_CUDA
8 #include <optix.h>
9 
10 #define __KERNEL_GPU__
11 #define __KERNEL_CUDA__ /* OptiX kernels are implicitly CUDA kernels too */
12 #define __KERNEL_OPTIX__
13 #define CCL_NAMESPACE_BEGIN
14 #define CCL_NAMESPACE_END
15 
16 #ifndef ATTR_FALLTHROUGH
17 # define ATTR_FALLTHROUGH
18 #endif
19 
20 /* Manual definitions so we can compile without CUDA toolkit. */
21 
22 #ifdef __CUDACC_RTC__
23 typedef unsigned int uint32_t;
24 typedef unsigned long long uint64_t;
25 #else
26 # include <stdint.h>
27 #endif
28 
29 #ifdef CYCLES_CUBIN_CC
30 # define FLT_MIN 1.175494350822287507969e-38f
31 # define FLT_MAX 340282346638528859811704183484516925440.0f
32 # define FLT_EPSILON 1.192092896e-07F
33 #endif
34 
35 #define ccl_device \
36  __device__ __forceinline__ // Function calls are bad for OptiX performance, so inline everything
37 #define ccl_device_inline ccl_device
38 #define ccl_device_forceinline ccl_device
39 #define ccl_device_inline_method ccl_device
40 #define ccl_device_noinline __device__ __noinline__
41 #define ccl_device_noinline_cpu ccl_device
42 #define ccl_global
43 #define ccl_inline_constant __constant__
44 #define ccl_device_constant __constant__ __device__
45 #define ccl_constant const
46 #define ccl_gpu_shared __shared__
47 #define ccl_private
48 #define ccl_may_alias
49 #define ccl_restrict __restrict__
50 #define ccl_loop_no_unroll
51 #define ccl_align(n) __align__(n)
52 
53 /* Zero initialize structs to help the compiler figure out scoping */
54 #define ccl_optional_struct_init = {}
55 
56 /* No assert supported for CUDA */
57 
58 #define kernel_assert(cond)
59 
60 /* GPU thread, block, grid size and index */
61 
62 #define ccl_gpu_thread_idx_x (threadIdx.x)
63 #define ccl_gpu_block_dim_x (blockDim.x)
64 #define ccl_gpu_block_idx_x (blockIdx.x)
65 #define ccl_gpu_grid_dim_x (gridDim.x)
66 #define ccl_gpu_warp_size (warpSize)
67 #define ccl_gpu_thread_mask(thread_warp) uint(0xFFFFFFFF >> (ccl_gpu_warp_size - thread_warp))
68 
69 #define ccl_gpu_global_id_x() (ccl_gpu_block_idx_x * ccl_gpu_block_dim_x + ccl_gpu_thread_idx_x)
70 #define ccl_gpu_global_size_x() (ccl_gpu_grid_dim_x * ccl_gpu_block_dim_x)
71 
72 /* GPU warp synchronization. */
73 
74 #define ccl_gpu_syncthreads() __syncthreads()
75 #define ccl_gpu_ballot(predicate) __ballot_sync(0xFFFFFFFF, predicate)
76 
77 /* GPU texture objects */
78 
79 typedef unsigned long long CUtexObject;
82 
83 template<typename T>
85  const float x,
86  const float y)
87 {
88  return tex2D<T>(texobj, x, y);
89 }
90 
91 template<typename T>
93  const float x,
94  const float y,
95  const float z)
96 {
97  return tex3D<T>(texobj, x, y, z);
98 }
99 
100 /* Half */
101 
102 typedef unsigned short half;
103 
105 {
106  half val;
107  asm("{ cvt.rn.f16.f32 %0, %1;}\n" : "=h"(val) : "f"(f));
108  return val;
109 }
110 
112 {
113  float val;
114  asm("{ cvt.f32.f16 %0, %1;}\n" : "=f"(val) : "h"(h));
115  return val;
116 }
117 
118 /* Types */
119 
120 #include "util/half.h"
121 #include "util/types.h"
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
Definition: half.h:41
CUtexObject ccl_gpu_tex_object_3D
Definition: cuda/compat.h:80
unsigned long long CUtexObject
Definition: cuda/compat.h:78
CUtexObject ccl_gpu_tex_object_2D
Definition: cuda/compat.h:79
#define T
#define __device__
Definition: metal/compat.h:248
ccl_device_forceinline T ccl_gpu_tex_object_read_2D(const ccl_gpu_tex_object_2D texobj, const float x, const float y)
Definition: optix/compat.h:84
#define ccl_device_forceinline
Definition: optix/compat.h:38
__device__ half __float2half(const float f)
Definition: optix/compat.h:104
CUtexObject ccl_gpu_tex_object_3D
Definition: optix/compat.h:81
unsigned short half
Definition: optix/compat.h:102
__device__ float __half2float(const half h)
Definition: optix/compat.h:111
ccl_device_forceinline T ccl_gpu_tex_object_read_3D(const ccl_gpu_tex_object_3D texobj, const float x, const float y, const float z)
Definition: optix/compat.h:92
unsigned long long CUtexObject
Definition: optix/compat.h:79
CUtexObject ccl_gpu_tex_object_2D
Definition: optix/compat.h:80
unsigned int uint32_t
Definition: stdint.h:80
unsigned __int64 uint64_t
Definition: stdint.h:90