Skip to content

Instantly share code, notes, and snippets.

@borisbat
borisbat / README.md
Created August 7, 2026 13:02
MoltenVK argbuf compute store-loss repro: SPIR-V kernels (7 fail / 2 pass)

MoltenVK argument-buffers compute store-loss repro — SPIR-V kernels

Nine compute kernels from the dasLLAMA test suite (daslang-generated SPIR-V, disassembled with spirv-dis; spirv-as rebuilds the binaries). All nine pass spirv-val (default and --target-env vulkan1.2). On Apple M1 Max, macOS 26.5.2, MoltenVK 1.4.2 (brew), with Metal argument buffers enabled (MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=1, the Apple Silicon default) the seven kernels marked FAIL dispatch without any error but none of their device stores land; with MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=0 all nine produce correct results. Fences signal and buffer copies in the same submission run in both cases.

// this will split the work between all available threads
// if chunk_count is -1, default number of chunks will be computed
void JobQue::parallel_for ( int from, int to, const JobChunk & chunk, int chunk_count, int step )
{
if ( from >= to )
return;
// so the idea here is that if say 1 thread is busy
// we don't pay 2x time. smaller chunks are more evenly distributed
if ( chunk_count==-1 )
chunk_count = mThreadCount * 4;
@borisbat
borisbat / gist:8308442
Created January 7, 2014 22:54
Tangent space
mat3 cotangent_frame( vec3 N, vec3 p, vec2 uv )
{
// get edge vectors of the pixel triangle
vec3 dp1 = dFdx( p );
vec3 dp2 = dFdy( p );
vec2 duv1 = dFdx( uv );
vec2 duv2 = dFdy( uv );
// solve the linear system
vec3 dp2perp = cross( dp2, N );
@borisbat
borisbat / gist:7314207
Created November 5, 2013 05:10
instanceNodes
///////////////////////////////////////////
// parse library_visual_scenes (nodes) here
void importDaeNodeArray ( const pugi::xpath_node_set & nodes, vector<NodePtr> & outNodes, const WeakNodePtr & parent )
{
using namespace pugi;
if ( nodes.size()==0 )
return;
outNodes.resize(nodes.size());
for ( unsigned int ni=0; ni<nodes.size(); ni++ )
vec3 finalColor = vec3( 0.0 );
float steps = 0.0;
int initialSteps = max ( 4, g_Steps / 3 );
int maxEstSteps = 32;
float kFactor = 2.0 / g_Steps;
// do initial steps
for ( int i=0; i<initialSteps; ++i )
vec3 finalColor = vec3( 0.0 );
float steps = 0.0;
int initialSteps = max ( 4, g_Steps / 3 );
int maxEstSteps = 32;
float factor = max ( 1.0, length(g_light_color.rgb)/length(vec3(1.0)) );
float tolerance = 1.0 / ( (g_Steps * 4.0 + initialSteps) * factor );
// do initial steps
for ( int i=0; i<initialSteps; ++i )
@borisbat
borisbat / gist:5890068
Last active December 19, 2015 03:28
Simple storage.
#include <iostream>
#include <vector>
#include <functional>
#include <initializer_list>
#define USE_EMPLACE 1
#define USE_UREF 1
using namespace std;
class Report
{
public:
Report() : i_am_dead(false) { cout << " Report();" << endl; }
Report(const Report & ) { cout << " Report(const Report&);" << endl; };
Report(Report && h) { cout << " Report(&&);" << endl; h.i_am_dead = true; }
Report & operator = (const Report&) { cout << " Report::=(const Report&);" << endl; return *this; };
~Report() { cout << " ~Report() i_am_dead=" << i_am_dead << endl; }
bool i_am_dead;
};
class Report
{
public:
Report() { cout << "Report();" << endl; }
Report(const Report & ) { cout << "Report(const & Report);" << endl; };
Report(Report &&) { cout << "Report(&&);" << endl; }
Report & operator = (const Report &) { cout << "Report::=(const Report &);" << endl; return *this; };
};
template <typename Tc, typename T>
@borisbat
borisbat / gist:5836110
Last active December 18, 2015 19:49
C++11 STL
#include <iostream>
#include <vector>
#include <functional>
#include <initializer_list>
#include <string>
using namespace std;
template <typename TT>
class RArray : protected vector<TT>