Skip to content

Instantly share code, notes, and snippets.

@Hurleyworks
Hurleyworks / gist:ade3f81cc8c97c65d8b7c192de9890fa
Created March 12, 2023 18:59
Creating host versions of some built-in Cuda functions from https://github.com/shocker-0x15/OptiX_Utility and commented by ChatGPT
#pragma once
// Define types and functions on the host corresponding to CUDA built-ins.
#if !defined(__CUDACC__) || defined(OPTIXU_Platform_CodeCompletion)
// This code defines a struct named "int2" that contains two 32-bit integers named "x" and "y".
// The line "struct alignas (8) int2" specifies that the struct should be aligned on an 8-byte boundary in memory.
// This can be used to optimize memory access performance in certain situations.
// The code also provides two constructors for the struct. The first constructor takes a
// single 32-bit integer "v" and initializes both "x" and "y" to that value.
taken from https://github.com/shocker-0x15/OptiX_Utility
class Timer {
CUcontext m_context;
CUevent m_startEvent;
CUevent m_endEvent;
bool m_startIsValid;
bool m_endIsValid;
public:
@Hurleyworks
Hurleyworks / gist:6fb983964304496d3b9eee800e639fd4
Created October 2, 2021 02:43
some Yocto-gl functions converted to cuda
// tracing algorithms. Yocto/Shading is implemented in `yocto_shading.h`.
//
//
// LICENSE:
//
// Copyright (c) 2016 -- 2020 Fabio Pellacini
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@Hurleyworks
Hurleyworks / gist:6573dd5ebb9ccf306e1184a9d5e30154
Created October 7, 2020 18:38
Can't create CallableProgramGroup
#pragma once
#include "bare_bones_shared.h"
using namespace Shared;
using namespace BarebonesShared;
RT_PIPELINE_LAUNCH_PARAMETERS PipelineLaunchParameters plp;
@Hurleyworks
Hurleyworks / gist:0471f8f1bf47bfe0d3667b367804acb5
Created November 18, 2019 01:54
Optix7 mis-aligned address problem
size_t byteOffset = 0;
// indices
indices.data = deviceBuffer + byteOffset;
indices.byte_stride = static_cast<uint16_t>(byteStride);
indices.count = static_cast<uint32_t>(tris.size());
indices.elmt_byte_size = static_cast<uint16_t>(sizeof(uint32_t));
uintptr_t number = (uintptr_t)indices.data;
struct PickingParams
{
OptixTraversableHandle sceneAccel;
float4* accum_buffer;
uchar4* frame_buffer;
CUdeviceptr pickBuffer; // CUDA device pointer with room for at least two unsigned int.
// 4-byte aligned
uint32_t subframe_index;
int picking;
@Hurleyworks
Hurleyworks / gist:a5798887b4e679fb8f0943615e8ed331
Created September 25, 2019 18:26
Optix7 pick ray programs
struct PickParams
{
int picking;
float3 rayOrigin;
float3 rayDir;
int32_t pickData[2];
OptixTraversableHandle sceneAccel;
};
enum RayType
@Hurleyworks
Hurleyworks / gist:3f3c060b41b8e2f5cb0530b14a3d6107
Created January 22, 2018 20:41
Optix Motion blur problem
// compute previous pose
void IOptixEngine::srt_previous(float * key, ItemHandle item)
{
Eigen::Vector3f p = item->spaceTime().previousWorldTransform.translation();
Eigen::Vector3f s = item->spaceTime().scale;
// model bounds works, world bounds does not!
Eigen::AlignedBox3f bbox = item->spaceTime().modelBound;
Eigen::Vector3f pivot = bbox.center();