Skip to content

Instantly share code, notes, and snippets.

@nlguillemot
nlguillemot / main.cpp
Created April 28, 2017 03:03
stable opengl timestamps with D3D12
#ifdef _WIN32
#include <d3d12.h>
#include <dxgi1_5.h>
#pragma comment(lib, "d3d12.lib")
#pragma comment(lib, "dxgi.lib")
#endif
#ifdef _WIN32
void SetStablePowerState()
@nlguillemot
nlguillemot / tasks.md
Last active February 17, 2018 20:11
Musings on task parallelism

In order to effectively use a multi-core CPU, a decomposition of code into tasks must be made. By decomposing code into tasks, the tasks can be distributed among CPU cores by a scheduler. Tasks can have dependencies on other tasks, meaning that the tasks execute in a partial order. This partial order can be represented as a graph, where each task has predecessors and successors. A task can only execute when all its predecessors have completed.

To implement this, we can explicitly create a graph of tasks, with edges between tasks to identify predecessor/successor relationships. The problem with a general task graph system is that it's not productive to work with. Maybe it's okay for some purposes to have a GUI interface to build a task graph, but that's too tedious for everyday code. Imagine if you had to explicitly create nodes and edges when implementing a single-threaded function call graph, it would be so tedious!

@nlguillemot
nlguillemot / main.cpp
Created August 30, 2015 02:22
BasicGL
#include <Windows.h>
#include <GL/gl.h>
#pragma comment(lib, "OpenGL32.lib")
LRESULT CALLBACK MyWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CLOSE:
@nlguillemot
nlguillemot / p4vsissues.md
Last active August 29, 2015 14:26
P4VS problems I've encountered

From memory...

  • Periodically freezes Visual Studio for a long period of time while refreshing status.
    • Workaround: Set the refresh period to some obscenely huge number (the status of your files is then never refreshed)
  • Tends to give P4 error pop-ups when opening files outside of your project (eg: stdlib headers, files from other projects...)
  • Deleting files from project (while simultaneously marking for delete) gives an error saying the file doesn't exist (but also deletes it. double delete?)
  • Deleting N files from a project sequentially gives N pop-ups asking if you also want to mark for delete
@nlguillemot
nlguillemot / main.cpp
Last active August 29, 2015 14:22
value initialized member struct
#include <iostream>
using namespace std;
struct X
{
int a,b,c;
};
struct Y
@nlguillemot
nlguillemot / output from webcompiler.cloudapp.net
Last active August 29, 2015 14:22
value initializing unions inside a struct
Compiled with /EHsc /nologo /W4
main.cpp
Compilation successful!
Total compilation time: 109ms
0 0 0 0 0 0 0 0 0 0
50790056 50790132 50790220 49536592 -1801320171 -2 49555713 49555747 49683692 6
@nlguillemot
nlguillemot / to_tstring.hpp
Created June 2, 2015 18:07
to_string based on TCHAR
namespace detail
{
template<class T>
std::string to_tstring(CHAR, const T& x) { return std::to_string(x); }
template<class T>
std::wstring to_tstring(WCHAR, const T& x) { return std::to_wstring(x); }
}
template<class T>
auto to_tstring(const T& x)
@nlguillemot
nlguillemot / !What is this?
Last active August 29, 2015 14:20
Transposing a CSV file (with '|' instead of ',')
People these days love to throw GPUs at every problem they can.
Sometimes it works well, other times it's a waste of power.
This program was written to show that you don't need a big high end GPU to parse a CSV file quickly,
in reponse to https://github.com/antonmks/nvParse
Can probably be optimized more. Gotta try running it on a SSD sometime.
Either way, much more competitive than the strawman CPU implementations on the above project page.
@nlguillemot
nlguillemot / main.cpp
Created March 28, 2015 12:27
Polling for changes in a directory
#include <Windows.h>
int main()
{
// Create a file change notification object that can be used to check for file changes.
HANDLE hNotif = FindFirstChangeNotification("C:\\Path\\To\\My\\Directory", TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE);
while (1)
{
// Wait until a file change notification happens.
@nlguillemot
nlguillemot / superbasicgl.cpp
Created March 8, 2015 20:30
super basic GL
#include <windows.h>
#include <GL/gl.h>
#include <cmath>
int lineWidth = 1;
LRESULT CALLBACK MyWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_CLOSE)