Skip to content

Instantly share code, notes, and snippets.

@junjie1475
junjie1475 / m3_explore.md
Last active December 3, 2024 13:52
m3_explore

Note: This is for my own educational purpose only(WIP)

Many people have already posted different kinds of microbenchmarking method for testing the size limits of various structures(e.g ROB, PRF). I recommend you to look at Henry Wong's blog post and also Maynard Handley's PDFs first. I got my idea from them and many others!

I found a slightly different variant based on them

Get the tools ready

Testing on Apple platform is always a hassle, and for my method we have to have a way to access the Performance counters directly in our microbenchmark. Dougall made a Kext for this purpose, basically what it does is to provide access to the configuration registers and so we can set the PMCs available for userspace access. And to make my life easier, I made a kext to pin the microbenchmark to

@FilipSivak
FilipSivak / ue4_open_editor_utility_by_cpp.cpp
Created May 9, 2021 07:53
Unreal - open editor utility widget by C++
#include "EditorUtilityWidgetBlueprint.h"
#include "EditorUtilitySubsystem.h"
UObject * Blueprint = UEditorAssetLibrary::LoadAsset(FString(TEXT("EditorUtilityWidgetBlueprint'/Game/EditorUtilities/MyWidget.MyWidget'")));
if(IsValid(Blueprint)) {
UEditorUtilityWidgetBlueprint* EditorWidget = Cast<UEditorUtilityWidgetBlueprint>(Blueprint);
if (IsValid(EditorWidget)) {
UEditorUtilitySubsystem* EditorUtilitySubsystem = GEditor->GetEditorSubsystem<UEditorUtilitySubsystem>();
EditorUtilitySubsystem->SpawnAndRegisterTab(EditorWidget);
}
@DuncanF
DuncanF / gist:353509dd397ea5f292fa52d1b9b5133d
Created January 29, 2020 10:43
Unity lockless (no GPU readback) marching cubes via Graphics.DrawProceduralIndirect - some slight faffing because compute shader must append full triangle (3 verts) at a time to render correctly, but this means the appendbuffer count is 3 times smaller than it needs to be, so we have to invoke a very short compute shader (FixupIndirectArgs) just…
MarchingCubesGPU.cs:
...
// DrawProceduralIndirect
ComputeBuffer argsBuffer;
[StructLayout(LayoutKind.Sequential)]
struct DrawCallArgBuffer
{
public const int size =
sizeof(int) +
sizeof(int) +
@CarlLee
CarlLee / Bloom.shader
Last active August 27, 2024 02:43
UE4 bloom for unity
Shader "Hidden/Bloom"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl"
struct appdata
@distantcam
distantcam / JobHelper.cs
Last active August 17, 2023 15:54
Unity Job system with async
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Unity.Jobs;
public static class JobHelper
{
@cdwfs
cdwfs / vk_cpu_gpu_timestamp.cpp
Last active December 12, 2021 06:01
Vulkan function to get a pair of timestamps (one CPU, one GPU) corresponding to (very nearly) the same point in absolute wall time.
struct CpuGpuTimestampInfo {
VkDevice device;
VkQueue queue;
uint32_t queue_family_index;
float timestamp_period; // Copy from VkPhysicalDeviceLimits::timestampPeriod
uint32_t timestamp_valid_bits; // Copy from VkQueueFamilyProperties::timestampValidBits
};
VkResult GetCpuGpuTimestamp(const CpuGpuTimestampInfo *info,
std::chrono::high_resolution_clock::time_point *out_cpu_time, uint64_t *out_gpu_time) {
if (info->timestamp_valid_bits == 0) {
@phi-lira
phi-lira / UniversalPipelineTemplateShader.shader
Last active October 21, 2025 16:44
Template shader to use as guide to create Universal Pipeline ready shaders. This shader works with Universal Render Pipeline 7.1.x and above.
// When creating shaders for Universal Render Pipeline you can you the ShaderGraph which is super AWESOME!
// However, if you want to author shaders in shading language you can use this teamplate as a base.
// Please note, this shader does not necessarily match perfomance of the built-in URP Lit shader.
// This shader works with URP 7.1.x and above
Shader "Universal Render Pipeline/Custom/Physically Based Example"
{
Properties
{
// Specular vs Metallic workflow
[HideInInspector] _WorkflowMode("WorkflowMode", Float) = 1.0
@Leandros
Leandros / links.md
Last active November 24, 2025 08:08
Writing a Modern Rendering Engine
@appetizermonster
appetizermonster / MergeSort.cs
Last active January 21, 2021 12:52
MergeSort for C# (Optimized for Unity3D)
using System;
using System.Collections.Generic;
internal static class MergeSort<T> {
public static void Sort (List<T> list, Comparison<T> comparison) {
if (list.Count <= 1)
return;
var mid = list.Count / 2;