Skip to content

Instantly share code, notes, and snippets.

View garettbass's full-sized avatar
🤓

Garett Bass garettbass

🤓
View GitHub Profile
@rorydriscoll
rorydriscoll / FullScreenQuad.hlsl
Created December 19, 2011 05:52
A vertex shader that uses the vertex ID to generate a full-screen quad. Don't bind vertex buffer, index buffer or input layout. Just render three vertices!
struct Output
{
float4 position_cs : SV_POSITION;
float2 texcoord : TEXCOORD;
};
Output main(uint id: SV_VertexID)
{
Output output;
@yohhoy
yohhoy / threads.h
Last active July 25, 2024 06:15
C11 <threads.h> emulation library
/*
* C11 <threads.h> emulation library
*
* (C) Copyright yohhoy 2012.
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef EMULATED_THREADS_H_INCLUDED_
#define EMULATED_THREADS_H_INCLUDED_
@jboner
jboner / latency.txt
Last active July 25, 2024 11:30
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@garethjenkins
garethjenkins / gist:3027840
Created July 1, 2012 10:26
enumerate displays using CGGetActiveDisplayList
CGDirectDisplayID displays[MAX_DISPLAYS];
uint32_t numDisplays;
uint32_t i;
CGGetActiveDisplayList(MAX_DISPLAYS, displays, &numDisplays);
for(i=0; i<numDisplays; i++)
{
CGDisplayModeRef mode;
CFIndex index, count;
@rasmuskl
rasmuskl / fnv64a1.cs
Created September 26, 2012 07:39
FNV 1a 64-bit C# non-cryptographic hash
// FNV-1a (64-bit) non-cryptographic hash function.
// Adapted from: http://github.com/jakedouglas/fnv-java
public ulong HashFNV1a(byte[] bytes)
{
const ulong fnv64Offset = 14695981039346656037;
const ulong fnv64Prime = 0x100000001b3;
ulong hash = fnv64Offset;
for (var i = 0; i < bytes.Length; i++)
{
@h2oota
h2oota / msvcc.sh
Created February 18, 2013 04:37
# GCC-compatible wrapper for cl.exe and ml.exe. Arguments are given in GCC # format and translated into something sensible for cl or ml.
#!/bin/sh
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
@tom-seddon
tom-seddon / gist:5171093
Created March 15, 2013 16:19
backtrace/backtrace_symbols for Win32.
#ifdef _MSC_VER
struct Frame
{
struct Frame *caller;
void *ret;
};
int backtrace(void **array,int size)
{
struct Frame *frame;
@adamjs
adamjs / gl_texture_surface.cc
Created September 7, 2013 02:02
Implementation of OpenGL Texture Surface (used with SDL-based WebFlow sample in the Awesomium SDK)
#include "gl_texture_surface.h"
#include <iostream>
#include <cstring>
#include <cstdlib>
GLRAMTextureSurface::GLRAMTextureSurface(int width, int height) : texture_id_(0),
buffer_(0), bpp_(4), rowspan_(0), width_(width), height_(height) {
rowspan_ = width_ * bpp_;
buffer_ = new unsigned char[rowspan_ * height_];
needs_update_ = false;
@macton
macton / cpuid_features.c
Last active November 5, 2023 02:04
Print cpuid features
// This file: https://gist.github.com/macton/4dd5fec2113be284796e
// See: Intel Intrinsics Guide https://software.intel.com/sites/landingpage/IntrinsicsGuide/
// See: CPUID Explorer http://www.flounder.com/cpuid_explorer1.htm
// See: Playing with cpuid http://newbiz.github.io/cpp/2010/12/20/Playing-with-cpuid.html
// See: MSDN __cpuid, __cpuidex http://msdn.microsoft.com/en-us/library/hskdteyh.aspx
// See: Notes on MMX/SSE and a searchable table of intrinsics. http://www.taffysoft.com/pages/20120418-01.html
// See: AMD CPUID Specification http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/25481.pdf
#if defined(__GNUC__)
#include <stdint.h>
@Cody-Duncan
Cody-Duncan / gist:d85740563ceea99f6619
Created August 1, 2014 04:30
DirectX11 Generate Input Layout from Vertex Shader using D3DReflect.
//Function Creates an input layout from the vertex shader, after compilation.
//Input layout can be reused with any vertex shaders that use the same input layout.
HRESULT CreateInputLayoutDescFromVertexShaderSignature( ID3DBlob* pShaderBlob, ID3D11Device* pD3DDevice, ID3D11InputLayout** pInputLayout, int* inputLayoutByteLength )
{
// Reflect shader info
ID3D11ShaderReflection* pVertexShaderReflection = nullptr;
HRESULT hr = S_OK;
if ( FAILED( D3DReflect( pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), IID_ID3D11ShaderReflection, (void**) &pVertexShaderReflection ) ) )
{