Skip to content

Instantly share code, notes, and snippets.

HMODULE vulkanLib = LoadLibrary("vulkan-1.dll");
if(vulkanLib == null) //no vulkan installed error out
exit(1);
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr) GetProcAddress(vulkanLib, "vkGetInstanceProcAddr");
PFN_vkCreateInstance vkCreateInstance = (FPN_vkCreateInstance) vkGetInstanceProcAddr(null, "vkCreateInstance");
VkInstance instance;
@ratchetfreak
ratchetfreak / syncing_buffers.java
Created February 24, 2016 10:41
syncing mapped buffers using flush
//map buffer with GL_MAP_FLUSH_EXPLICIT_BIT
waitBuffer(gl4, rbWriteIndex);
perMeshPointer.position(rbAlignment * rbWriteIndex);
perMeshPointer.asFloatBuffer().put(perMesh[i].toFa());
perMeshPointer.rewind();
gl4.glFlushMappedBufferRange(GL_UNIFORM_BUFFER, rbAlignment * rbWriteIndex, rbAlignment);
gl4.glBindBufferRange(GL_UNIFORM_BUFFER,
@echo off
REM Debug build:
REM cl -Zi ctime.c /link winmm.lib
REM Release build:
cl -O2 ctime.c /link winmm.lib
@ratchetfreak
ratchetfreak / Pipeline Stages.md
Last active October 22, 2018 17:15
Looking at pipeline stages

A dissemination of pipeline stages and how they interract with barriers and other sync operations in Vulkan™.

In my understanding of pipeline stages they are units of execution that run semi-independently. The vkCmd* commands operate on one or more stages. Copy and clear operations for example run on the TRANSFER stage. Each stage can however can work on multiple commands at a time.

When a synchronization operation is issued like vkCmdPipelineBarrier or vkCmdSetEvent and in subpass dependencies you need to specify a srcStageMask. This signifies which pipeline stages to wait on before doing the sync, in case of vkCmdSetEvent setting the event to signaled. This allows the sync to only wait on certain stages.

The dstStageMask on the other hand specifies which stages need to wait on the sync operation (plus any layout transitions and cache flushes) to complete, the other stages will continue executing. In vkSubmitInfo and vkCmdWaitEvent the mask indicates which stages wait on the semaphore

  • void glEnableVertexAttribArray​(GLuint attribIndex);
  • void glDisableVertexAttribArray​(GLuint attribIndex);
  • void glVertexAttribPointer(GLuint attribIndex, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer);
  • void glVertexAttribFormat(GLuint attribIndex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset);
  • void glVertexAttribBinding(GLuint attribIndex, GLuint bindingIndex);
  • void glBindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset, GLintptr stride);
parameter Details
attribIndex the location for the vertex attribute to which the vertex array will feed data

mitochondrial and y-chromosomal lineage simulator

Simulates a population over several generations, tracking the mitochondrial eve and y-chromosome adam of each individual.

Each generation every female has a chance to produce up to 12 children. Half are male and dropped from the total population. The stop condition for reproduction is experimentally determined to keep the total population stable. No bias is applied to any lineage.

The RNG is a linear shift register based on the highest period shift register listed on wikipedia.

#How to run:

@ratchetfreak
ratchetfreak / vmusage.cpp
Last active June 1, 2023 12:30
proposed callbackless vm-usage code
void foo(){
VMwasm vm;
initVM(&vm);
char* internalBuffer = nullptr;
defer{free(internalBuffer);}
{
size_t len;
char* buffer = readWholeFile(..., &len);
defer{free(buffer);}
@ratchetfreak
ratchetfreak / SpatialPartition.java
Last active October 12, 2023 19:23
spatial partition in O(n) on update and only 2 int arrays extra memory
import java.util.*;
/**
*
* spatial partitioning based on sebastian Lague's video:
* https://www.youtube.com/watch?v=rSKMYc1CQHE
*
* but using cycle sort instead of regular sorting algorithm because I can
*
**/