Skip to content

Instantly share code, notes, and snippets.

@iaomw
Last active September 16, 2022 16:36
Show Gist options
  • Save iaomw/8f1a67edc66dfbf449183f7af7573f66 to your computer and use it in GitHub Desktop.
Save iaomw/8f1a67edc66dfbf449183f7af7573f66 to your computer and use it in GitHub Desktop.
Onez API draft
#include <string>
// Pseudocode
namespace onez {
struct Device {
std::string description;
std::vector<Display> connedtedDisplays;
bool supportRayTracing;
bool supportMeshShader;
bool supportTessellation;
bool supportBindlessResource;
bool supportUnboundedResource;
bool supportGPUDrivenPipeline;
bool privateVRAM; // unified memory
uint maximumVRAM;
uint availableVRAM();
uint alocatedVRAM(this app);
};
enum ResourceType {
CPUGPUShared, GPUPrivate, Temp
};
enum AccessType {
Read, Write, RenderTarget
};
class TextureDescription {
uint miplevel;
uint layer, width, height;
TextureFormat formate; // RGBA32 RGBA16 BGRA8, etc
ResourceType rType;
AccessType aType;
}
class Texture {
uint _id;
TextureDescription description
}
class TextureView {
Texture *ref;
uint offsetX, offsetY;
uint width, height;
}
struct TextureSampler {
enum FilterType { Linear, Nearest };
FilterType magFilter, minfilter;
}
struct Buffer {
uint _id;
uint sizeInByte;
void* payload;
ResourceType rType;
AccessType aType;
}
struct BufferView {
Buffer *ref;
uint offset;
uint sizeInByte;
}
enum struct ShaderType {
Vertex, Fragment,
Geometry, Compute, Mesh,
TessellationControl, TessellationEvaluation
};
struct ShaderProgram {
std::string fileURL;
ShaderType sType;
void* payload;
std::map<uint, std::tuple<std::string, DataType>> bindingPoints
}
struct ShaderLibrary {
std::string url;
bool precompiled;
void* payload;
std::vector<ShaderProgram> shaderList;
};
struct BindingGroup {
BindingGroup* extra;
std::vector<uint> bindingPoints;
std::vector<uint> resourceID;
std::vector<DataType> typeInfo;
}
class PipelineState {}
class RasterizatePipelineState: PipelineState {
uint sampleCount;
std::string debugLable;
Viewport vport;
std::vector<Texture> renderTargets;
std::vector<LoadAction> loadActions;
std::vector<StoreAction> storeActions;
std::vector<BlendAction> blendActions;
ShaderProgram* vertexShader, fragmentShader;
drawPrimitive();
drawIndexedPrimitive();
multiDrawIndirect(bool GPUDriven);
};
template <typename T>
class DataCopyingPipelineState<T> : PipelineState { // GPU to CPU, CPU to GPU, GPU_A to GPU_B
T source, destination;
};
DataCopyingPipelineState<Buffer>;
DataCopyingPipelineState<Texture>;
class ComputatingPipelineState : PipelineState {
uint3 dispatchSize;
uint3 groupSize;
ShaderProgram* kernel;
}
class RayTracingPipelineState : PipelineState {
enum HitTestType { Nearst, Any };
HitTestType hitType;
Buffer* rayListBuffer
Buffer* hitListBuffer;
Buffer* bvhListBuffer;
ShaderProgram* customHitKernel; // optional: sphere, curve, SDF
}
struct CommandEncoder {
int addPipelineState(PipelineState* state, BindingGroup* group);
int work(bool syncnize) {
// Any work items in PipelineState
}
}
struct CommandBuffer {};
}
@iaomw
Copy link
Author

iaomw commented Sep 16, 2022

@iaomw
Copy link
Author

iaomw commented Sep 16, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment