resourceless-gpu api wip
This commit is contained in:
parent
df5902ca92
commit
7e97b54fe5
@ -12,40 +12,35 @@ void G_BootstrapCommon(void)
|
|||||||
{
|
{
|
||||||
// Init quad index buffer
|
// Init quad index buffer
|
||||||
{
|
{
|
||||||
G_ResourceHandle quad_indices = Zi;
|
u16 quad_indices[6] = { 0, 1, 2, 0, 2, 3 };
|
||||||
u16 quad_data[6] = { 0, 1, 2, 0, 2, 3 };
|
G.quad_indices = G_PushBufferFromCpu(cl, gpu_perm, quad_indices, u16, countof(quad_indices));
|
||||||
quad_indices = G_PushBuffer(gpu_perm, cl, u16, countof(quad_data));
|
|
||||||
G_CopyCpuToBuffer(cl, quad_indices, 0, quad_data, RNGU64(0, sizeof(quad_data)));
|
|
||||||
G.quad_indices = G_IdxBuff16(quad_indices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init blank texture
|
// Init blank texture
|
||||||
{
|
{
|
||||||
G_ResourceHandle blank_tex = G_PushTexture2D(
|
G.blank_tex = G_PushTexture2D(
|
||||||
gpu_perm, cl,
|
cl, gpu_perm,
|
||||||
|
G_TextureLayout_Common,
|
||||||
G_Format_R8G8B8A8_Unorm,
|
G_Format_R8G8B8A8_Unorm,
|
||||||
VEC2I32(8, 8),
|
VEC2I32(8, 8),
|
||||||
G_Layout_Common,
|
.flags = G_MemoryFlag_Zero,
|
||||||
.flags = G_ResourceFlag_ZeroMemory,
|
|
||||||
.name = Lit("Blank texture")
|
.name = Lit("Blank texture")
|
||||||
);
|
);
|
||||||
G.blank_tex = G_PushTexture2DRef(gpu_perm, blank_tex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init noise texture
|
// Init noise texture
|
||||||
{
|
{
|
||||||
G_ResourceHandle noise_tex = Zi;
|
|
||||||
String noise_data = DataFromResource(ResourceKeyFromStore(&G_Resources, Lit("noise_128x128x64_16.dat")));
|
String noise_data = DataFromResource(ResourceKeyFromStore(&G_Resources, Lit("noise_128x128x64_16.dat")));
|
||||||
Vec3I32 noise_dims = VEC3I32(128, 128, 64);
|
Vec3I32 noise_dims = VEC3I32(128, 128, 64);
|
||||||
if (noise_data.len != noise_dims.x * noise_dims.y * noise_dims.z * 2)
|
if (noise_data.len != noise_dims.x * noise_dims.y * noise_dims.z * 2)
|
||||||
{
|
{
|
||||||
Panic(Lit("Unexpected noise texture size"));
|
Panic(Lit("Unexpected noise texture size"));
|
||||||
}
|
}
|
||||||
noise_tex = G_PushTexture3D(
|
G_Texture3DRef noise_tex = G_PushTexture3D(
|
||||||
gpu_perm, cl,
|
cl, gpu_perm,
|
||||||
|
G_TextureLayout_Common,
|
||||||
G_Format_R16_Uint,
|
G_Format_R16_Uint,
|
||||||
noise_dims,
|
noise_dims,
|
||||||
G_Layout_Common,
|
|
||||||
.name = Lit("Noise texture")
|
.name = Lit("Noise texture")
|
||||||
);
|
);
|
||||||
G_CopyCpuToTexture(
|
G_CopyCpuToTexture(
|
||||||
@ -72,63 +67,63 @@ void G_BootstrapCommon(void)
|
|||||||
{
|
{
|
||||||
G_Filter filter = G_Filter_MinMagMipPoint;
|
G_Filter filter = G_Filter_MinMagMipPoint;
|
||||||
G_AddressMode address_mode = G_AddressMode_Clamp;
|
G_AddressMode address_mode = G_AddressMode_Clamp;
|
||||||
G_ResourceHandle sampler_res = G_PushSampler(gpu_perm, cl, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
G_ResourceHandle sampler_res = G_PushSampler(cl, gpu_perm, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
||||||
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
||||||
} break;
|
} break;
|
||||||
case G_BasicSamplerKind_PointWrap:
|
case G_BasicSamplerKind_PointWrap:
|
||||||
{
|
{
|
||||||
G_Filter filter = G_Filter_MinMagMipPoint;
|
G_Filter filter = G_Filter_MinMagMipPoint;
|
||||||
G_AddressMode address_mode = G_AddressMode_Wrap;
|
G_AddressMode address_mode = G_AddressMode_Wrap;
|
||||||
G_ResourceHandle sampler_res = G_PushSampler(gpu_perm, cl, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
G_ResourceHandle sampler_res = G_PushSampler(cl, gpu_perm, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
||||||
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
||||||
} break;
|
} break;
|
||||||
case G_BasicSamplerKind_PointMirror:
|
case G_BasicSamplerKind_PointMirror:
|
||||||
{
|
{
|
||||||
G_Filter filter = G_Filter_MinMagMipPoint;
|
G_Filter filter = G_Filter_MinMagMipPoint;
|
||||||
G_AddressMode address_mode = G_AddressMode_Mirror;
|
G_AddressMode address_mode = G_AddressMode_Mirror;
|
||||||
G_ResourceHandle sampler_res = G_PushSampler(gpu_perm, cl, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
G_ResourceHandle sampler_res = G_PushSampler(cl, gpu_perm, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
||||||
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
||||||
} break;
|
} break;
|
||||||
case G_BasicSamplerKind_BilinearClamp:
|
case G_BasicSamplerKind_BilinearClamp:
|
||||||
{
|
{
|
||||||
G_Filter filter = G_Filter_MinMagLinearMipPoint;
|
G_Filter filter = G_Filter_MinMagLinearMipPoint;
|
||||||
G_AddressMode address_mode = G_AddressMode_Clamp;
|
G_AddressMode address_mode = G_AddressMode_Clamp;
|
||||||
G_ResourceHandle sampler_res = G_PushSampler(gpu_perm, cl, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
G_ResourceHandle sampler_res = G_PushSampler(cl, gpu_perm, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
||||||
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
||||||
} break;
|
} break;
|
||||||
case G_BasicSamplerKind_BilinearWrap:
|
case G_BasicSamplerKind_BilinearWrap:
|
||||||
{
|
{
|
||||||
G_Filter filter = G_Filter_MinMagLinearMipPoint;
|
G_Filter filter = G_Filter_MinMagLinearMipPoint;
|
||||||
G_AddressMode address_mode = G_AddressMode_Wrap;
|
G_AddressMode address_mode = G_AddressMode_Wrap;
|
||||||
G_ResourceHandle sampler_res = G_PushSampler(gpu_perm, cl, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
G_ResourceHandle sampler_res = G_PushSampler(cl, gpu_perm, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
||||||
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
||||||
} break;
|
} break;
|
||||||
case G_BasicSamplerKind_BilinearMirror:
|
case G_BasicSamplerKind_BilinearMirror:
|
||||||
{
|
{
|
||||||
G_Filter filter = G_Filter_MinMagLinearMipPoint;
|
G_Filter filter = G_Filter_MinMagLinearMipPoint;
|
||||||
G_AddressMode address_mode = G_AddressMode_Mirror;
|
G_AddressMode address_mode = G_AddressMode_Mirror;
|
||||||
G_ResourceHandle sampler_res = G_PushSampler(gpu_perm, cl, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
G_ResourceHandle sampler_res = G_PushSampler(cl, gpu_perm, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
||||||
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
||||||
} break;
|
} break;
|
||||||
case G_BasicSamplerKind_TrilinearClamp:
|
case G_BasicSamplerKind_TrilinearClamp:
|
||||||
{
|
{
|
||||||
G_Filter filter = G_Filter_MinMagMipLinear;
|
G_Filter filter = G_Filter_MinMagMipLinear;
|
||||||
G_AddressMode address_mode = G_AddressMode_Clamp;
|
G_AddressMode address_mode = G_AddressMode_Clamp;
|
||||||
G_ResourceHandle sampler_res = G_PushSampler(gpu_perm, cl, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
G_ResourceHandle sampler_res = G_PushSampler(cl, gpu_perm, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
||||||
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
||||||
} break;
|
} break;
|
||||||
case G_BasicSamplerKind_TrilinearWrap:
|
case G_BasicSamplerKind_TrilinearWrap:
|
||||||
{
|
{
|
||||||
G_Filter filter = G_Filter_MinMagMipLinear;
|
G_Filter filter = G_Filter_MinMagMipLinear;
|
||||||
G_AddressMode address_mode = G_AddressMode_Wrap;
|
G_AddressMode address_mode = G_AddressMode_Wrap;
|
||||||
G_ResourceHandle sampler_res = G_PushSampler(gpu_perm, cl, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
G_ResourceHandle sampler_res = G_PushSampler(cl, gpu_perm, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
||||||
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
||||||
} break;
|
} break;
|
||||||
case G_BasicSamplerKind_TrilinearMirror:
|
case G_BasicSamplerKind_TrilinearMirror:
|
||||||
{
|
{
|
||||||
G_Filter filter = G_Filter_MinMagMipLinear;
|
G_Filter filter = G_Filter_MinMagMipLinear;
|
||||||
G_AddressMode address_mode = G_AddressMode_Mirror;
|
G_AddressMode address_mode = G_AddressMode_Mirror;
|
||||||
G_ResourceHandle sampler_res = G_PushSampler(gpu_perm, cl, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
G_ResourceHandle sampler_res = G_PushSampler(cl, gpu_perm, .filter = filter, .x = address_mode, .y = address_mode, .z = address_mode);
|
||||||
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
sampler = G_PushSamplerStateRef(gpu_perm, sampler_res);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
@ -155,10 +150,10 @@ G_ArenaHandle G_PermArena(void)
|
|||||||
|
|
||||||
//- Push resource from cpu
|
//- Push resource from cpu
|
||||||
|
|
||||||
G_ResourceHandle G_PushBufferFromCpuCopy_(G_ArenaHandle gpu_arena, G_CommandListHandle cl, String src, G_BufferDesc desc)
|
G_BufferRef G_PushBufferFromCpu_(G_CommandListHandle cl, G_ArenaHandle gpu_arena, void *src, G_BufferDesc desc)
|
||||||
{
|
{
|
||||||
G_ResourceHandle buffer = G_PushResource(gpu_arena, cl, (G_ResourceDesc) { .kind = G_ResourceKind_Buffer, .buffer = desc });
|
G_BufferRef buffer = G_PushBuffer(cl, gpu_arena, desc);
|
||||||
G_CopyCpuToBuffer(cl, buffer, 0, src.text, RNGU64(0, src.len));
|
G_CopyCpuToBuffer(cl, buffer, 0, src, RNGU64(0, desc.count * desc.stride));
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,13 +223,13 @@ Vec3I32 G_GroupCountFromThreadCount(ComputeShaderDesc cs, Vec3I32 threads)
|
|||||||
|
|
||||||
//- Viewport / scissor
|
//- Viewport / scissor
|
||||||
|
|
||||||
Rng3 G_ViewportFromTexture(G_ResourceHandle texture)
|
Rng3 G_ViewportFromTexture(G_Texture2DRef texture)
|
||||||
{
|
{
|
||||||
Vec2I32 dims = G_Count2D(texture);
|
Vec2I32 dims = G_Count2D(texture);
|
||||||
return RNG3(VEC3(0, 0, 0), VEC3(dims.x, dims.y, 1));
|
return RNG3(VEC3(0, 0, 0), VEC3(dims.x, dims.y, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
Rng2 G_ScissorFromTexture(G_ResourceHandle texture)
|
Rng2 G_ScissorFromTexture(G_Texture2DRef texture)
|
||||||
{
|
{
|
||||||
Vec2I32 dims = G_Count2D(texture);
|
Vec2I32 dims = G_Count2D(texture);
|
||||||
return RNG2(VEC2(0, 0), VEC2(dims.x, dims.y));
|
return RNG2(VEC2(0, 0), VEC2(dims.x, dims.y));
|
||||||
@ -258,7 +253,7 @@ G_Texture2DRef G_BlankTexture2D(void)
|
|||||||
return G.blank_tex;
|
return G.blank_tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
G_Texture3DRef G_BasicNoiseTexture(void)
|
G_Texture3DRef G_BasicNoise3D(void)
|
||||||
{
|
{
|
||||||
return G.basic_noise;
|
return G.basic_noise_tex;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,10 +4,10 @@
|
|||||||
Struct(G_Ctx)
|
Struct(G_Ctx)
|
||||||
{
|
{
|
||||||
// Common shared resources
|
// Common shared resources
|
||||||
G_IndexBufferDesc quad_indices;
|
G_BufferRef quad_indices;
|
||||||
G_Texture2DRef blank_tex;
|
G_Texture2DRef blank_tex;
|
||||||
G_Texture3DRef basic_noise;
|
G_Texture2DRef basic_noise_tex;
|
||||||
G_SamplerStateRef basic_samplers[G_BasicSamplerKind_COUNT];
|
G_SamplerRef basic_samplers[G_BasicSamplerKind_COUNT];
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(G_ThreadLocalCtx)
|
Struct(G_ThreadLocalCtx)
|
||||||
@ -27,27 +27,37 @@ void G_BootstrapCommon(void);
|
|||||||
//~ Utils
|
//~ Utils
|
||||||
|
|
||||||
//- Arena
|
//- Arena
|
||||||
|
|
||||||
G_ArenaHandle G_PermArena(void);
|
G_ArenaHandle G_PermArena(void);
|
||||||
|
|
||||||
//- Push resource from cpu
|
//- Push resource from cpu
|
||||||
G_ResourceHandle G_PushBufferFromCpuCopy_(G_ArenaHandle gpu_arena, G_CommandListHandle cl, String src, G_BufferDesc desc);
|
|
||||||
#define G_PushBufferFromCpuCopy(_arena, _cl, _src, ...) \
|
G_BufferRef G_PushBufferFromCpu_(G_CommandListHandle cl, G_ArenaHandle gpu_arena, void *src, G_BufferDesc desc);
|
||||||
G_PushBufferFromCpuCopy_((_arena), (_cl), (_src), (G_BufferDesc) { .size = (_src).len, __VA_ARGS__ })
|
|
||||||
|
#define G_PushBufferFromCpu(_cl, _gpu_arena, _src, _type, _count, ...) \
|
||||||
|
G_PushBufferFromCpu_((_cl), (_gpu_arena), (_src), (G_BufferDesc) { .count = _count, .stride = sizeof(_type) })
|
||||||
|
|
||||||
|
#define G_PushBufferFromCpuArena(_cl, _gpu_arena, _cpu_arena, _type, ...) \
|
||||||
|
G_PushBufferFromCpu_((_cl), (_gpu_arena), ArenaFirst((_cpu_arena), _type), ArenaCount((_cpu_arena), (_count)), __VA_ARGS__)
|
||||||
|
|
||||||
//- Mip
|
//- Mip
|
||||||
|
|
||||||
i32 G_DimsFromMip1D(i32 mip0_dims, i32 mip);
|
i32 G_DimsFromMip1D(i32 mip0_dims, i32 mip);
|
||||||
Vec2I32 G_DimsFromMip2D(Vec2I32 mip0_dims, i32 mip);
|
Vec2I32 G_DimsFromMip2D(Vec2I32 mip0_dims, i32 mip);
|
||||||
Vec3I32 G_DimsFromMip3D(Vec3I32 mip0_dims, i32 mip);
|
Vec3I32 G_DimsFromMip3D(Vec3I32 mip0_dims, i32 mip);
|
||||||
|
|
||||||
//- Thread count
|
//- Thread count
|
||||||
|
|
||||||
Vec3I32 G_GroupCountFromThreadCount(ComputeShaderDesc cs, Vec3I32 threads);
|
Vec3I32 G_GroupCountFromThreadCount(ComputeShaderDesc cs, Vec3I32 threads);
|
||||||
|
|
||||||
//- Viewport / scissor
|
//- Viewport / scissor
|
||||||
Rng3 G_ViewportFromTexture(G_ResourceHandle texture);
|
|
||||||
Rng2 G_ScissorFromTexture(G_ResourceHandle texture);
|
Rng3 G_ViewportFromTexture(G_Texture2DRef texture);
|
||||||
|
Rng2 G_ScissorFromTexture(G_Texture2DRef texture);
|
||||||
|
|
||||||
//- Shared resources
|
//- Shared resources
|
||||||
G_SamplerStateRef G_BasicSamplerFromKind(G_BasicSamplerKind kind);
|
|
||||||
|
G_SamplerRef G_BasicSamplerFromKind(G_BasicSamplerKind kind);
|
||||||
G_IndexBufferDesc G_QuadIndices(void);
|
G_IndexBufferDesc G_QuadIndices(void);
|
||||||
G_Texture2DRef G_BlankTexture2D(void);
|
G_Texture2DRef G_BlankTexture2D(void);
|
||||||
G_Texture3DRef G_BasicNoiseTexture(void);
|
G_Texture2DRef G_BasicNoise3D(void);
|
||||||
|
|||||||
@ -191,20 +191,20 @@ Enum(G_Format)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Texture layout types
|
//~ Texture layout types
|
||||||
|
|
||||||
Enum(G_Layout)
|
Enum(G_TextureLayout)
|
||||||
{
|
{
|
||||||
|
// Supports present, shader-read, and copy-read/write in any queue family.
|
||||||
|
// Transitionable from G_TextureLayout_Family in non-copy queue.
|
||||||
|
G_TextureLayout_Common,
|
||||||
|
|
||||||
|
// Supports any access in the current queue family.
|
||||||
|
// Transitionable from G_TextureLayout_Common in non-copy queue.
|
||||||
|
G_TextureLayout_Family,
|
||||||
|
|
||||||
// Supports any read access with up to 1 write access to non overlapping regions from any queue.
|
// Supports any read access with up to 1 write access to non overlapping regions from any queue.
|
||||||
// Cannot be transitioned to/from.
|
// Cannot be transitioned to/from.
|
||||||
// Depth-stencil textures cannot use this layout.
|
// Depth-stencil textures cannot use this layout.
|
||||||
G_Layout_Simultaneous,
|
G_TextureLayout_Simultaneous,
|
||||||
|
|
||||||
// Supports present, shader-read, and copy-read/write in any queue kind.
|
|
||||||
// Transitionable from `G_Layout_Exclusive` in non-copy queue.
|
|
||||||
G_Layout_Common,
|
|
||||||
|
|
||||||
// Supports any access in the current queue kind.
|
|
||||||
// Transitionable from `G_Layout_Common` in non-copy queue.
|
|
||||||
G_Layout_Exclusive,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -287,42 +287,43 @@ Enum(G_ComparisonFunc)
|
|||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Resource types
|
//~ Memory types
|
||||||
|
|
||||||
Enum(G_ResourceKind)
|
Enum(G_MemoryKind)
|
||||||
{
|
{
|
||||||
G_ResourceKind_Buffer,
|
G_MemoryKind_Buffer,
|
||||||
G_ResourceKind_Texture1D,
|
G_MemoryKind_Texture1D,
|
||||||
G_ResourceKind_Texture2D,
|
G_MemoryKind_Texture2D,
|
||||||
G_ResourceKind_Texture3D,
|
G_MemoryKind_Texture3D,
|
||||||
G_ResourceKind_Sampler,
|
G_MemoryKind_Sampler,
|
||||||
};
|
};
|
||||||
|
|
||||||
Enum(G_ResourceFlag)
|
Enum(G_MemoryFlag)
|
||||||
{
|
{
|
||||||
G_ResourceFlag_None = 0,
|
G_MemoryFlag_None = 0,
|
||||||
G_ResourceFlag_AllowShaderReadWrite = (1 << 1),
|
G_MemoryFlag_Zero = (1 << 0),
|
||||||
G_ResourceFlag_AllowRenderTarget = (1 << 2),
|
G_MemoryFlag_AllowTextureRW = (1 << 1),
|
||||||
G_ResourceFlag_AllowDepthStencil = (1 << 3),
|
G_MemoryFlag_AllowTextureDraw = (1 << 2),
|
||||||
G_ResourceFlag_ZeroMemory = (1 << 4),
|
G_MemoryFlag_AllowTextureDepthStencil = (1 << 3),
|
||||||
G_ResourceFlag_HostMemory = (1 << 5), // Resource will be mapped into the cpu's address space
|
G_MemoryFlag_HostCached = (1 << 4), // Will be mapped to write-back Cpu memory
|
||||||
G_ResourceFlag_Uncached = (1 << 6), // Cpu writes will be combined & reads will be uncached
|
G_MemoryFlag_HostUncached = (1 << 5), // Will be mapped to write-combined Cpu memory
|
||||||
G_ResourceFlag_ForceNoReuse = (1 << 7),
|
G_MemoryFlag_ForceNoReuse = (1 << 6),
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(G_BufferDesc)
|
Struct(G_BufferDesc)
|
||||||
{
|
{
|
||||||
G_ResourceFlag flags;
|
G_MemoryFlag flags;
|
||||||
u64 size;
|
u64 stride;
|
||||||
|
u64 count;
|
||||||
String name;
|
String name;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(G_TextureDesc)
|
Struct(G_TextureDesc)
|
||||||
{
|
{
|
||||||
G_ResourceFlag flags;
|
G_MemoryFlag flags;
|
||||||
G_Format format;
|
G_Format format;
|
||||||
Vec3I32 dims;
|
Vec3I32 dims;
|
||||||
G_Layout initial_layout;
|
G_TextureLayout initial_layout;
|
||||||
Vec4 clear_color;
|
Vec4 clear_color;
|
||||||
i32 max_mips; // Will be clamped to range [1, max mips]
|
i32 max_mips; // Will be clamped to range [1, max mips]
|
||||||
String name;
|
String name;
|
||||||
@ -330,7 +331,7 @@ Struct(G_TextureDesc)
|
|||||||
|
|
||||||
Struct(G_SamplerDesc)
|
Struct(G_SamplerDesc)
|
||||||
{
|
{
|
||||||
G_ResourceFlag flags;
|
G_MemoryFlag flags;
|
||||||
G_Filter filter;
|
G_Filter filter;
|
||||||
G_AddressMode x;
|
G_AddressMode x;
|
||||||
G_AddressMode y;
|
G_AddressMode y;
|
||||||
@ -344,25 +345,14 @@ Struct(G_SamplerDesc)
|
|||||||
String name;
|
String name;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(G_ResourceDesc)
|
Struct(G_MemoryDesc)
|
||||||
{
|
{
|
||||||
G_ResourceKind kind;
|
G_MemoryKind kind;
|
||||||
G_BufferDesc buffer;
|
G_BufferDesc buffer;
|
||||||
G_TextureDesc texture;
|
G_TextureDesc texture;
|
||||||
G_SamplerDesc sampler;
|
G_SamplerDesc sampler;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
//~ Ref types
|
|
||||||
|
|
||||||
Struct(G_RefDesc)
|
|
||||||
{
|
|
||||||
G_RefKind kind;
|
|
||||||
u64 element_size;
|
|
||||||
u64 element_offset;
|
|
||||||
RngI32 mips; // Inclusive range of texture mip indices to reference
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Draw types
|
//~ Draw types
|
||||||
|
|
||||||
@ -428,72 +418,134 @@ void G_ReleaseArena(G_CommandListHandle cl_handle, G_ArenaHandle arena);
|
|||||||
void G_ResetArena(G_CommandListHandle cl_handle, G_ArenaHandle arena_handle);
|
void G_ResetArena(G_CommandListHandle cl_handle, G_ArenaHandle arena_handle);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ @hookdecl Resource
|
//~ @hookdecl Memory
|
||||||
|
|
||||||
|
G_BaseDescriptorIndex G_PushMemory(G_CommandListHandle cl, G_ArenaHandle gpu_arena, G_MemoryDesc desc);
|
||||||
|
|
||||||
|
#define G_PushBuffer(_cl, _arena, _count, _type, ...) ((G_BufferRef) { .v = G_PushMemory((cl), (_arena), \
|
||||||
|
(G_MemoryDesc) { \
|
||||||
|
.kind = G_MemoryKind_Buffer, \
|
||||||
|
.buffer = { \
|
||||||
|
.count = (_count), \
|
||||||
|
.stride = sizeof(_type), \
|
||||||
|
__VA_ARGS__ \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
)})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define G_PushTexture1D(_cl, _arena, _initial_layout, _format, _dims, ...) ((G_Texture1DRef) { .v = G_PushMemory((cl), (_arena), \
|
||||||
|
(G_MemoryDesc) { \
|
||||||
|
.kind = G_MemoryKind_Texture1D, \
|
||||||
|
.texture = { \
|
||||||
|
.format = (_format), \
|
||||||
|
.dims = VEC3I32((_dims).x, 1, 1), \
|
||||||
|
.initial_layout = (_initial_layout), \
|
||||||
|
__VA_ARGS__ \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
)})
|
||||||
|
|
||||||
|
|
||||||
|
#define G_PushTexture2D(_cl, _arena, _initial_layout, _format, _dims, ...) ((G_Texture2DRef) { .v = G_PushMemory((cl), (_arena), \
|
||||||
|
(G_MemoryDesc) { \
|
||||||
|
.kind = G_MemoryKind_Texture2D, \
|
||||||
|
.texture = { \
|
||||||
|
.format = (_format), \
|
||||||
|
.dims = VEC3I32((_dims).x, (_dims).y, 1), \
|
||||||
|
.initial_layout = (_initial_layout), \
|
||||||
|
__VA_ARGS__ \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
)})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define G_PushTexture3D(_cl, _arena, _initial_layout, _format, _dims, ...) ((G_Texture3DRef) { .v = G_PushMemory((cl), (_arena), \
|
||||||
|
(G_MemoryDesc) { \
|
||||||
|
.kind = G_MemoryKind_Texture3D, \
|
||||||
|
.texture = { \
|
||||||
|
.format = (_format), \
|
||||||
|
.dims = VEC3I32((_dims).x, (_dims).y, (_dims.z)), \
|
||||||
|
.initial_layout = (_initial_layout), \
|
||||||
|
__VA_ARGS__ \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
)})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//- Resource creation
|
//- Resource creation
|
||||||
|
|
||||||
G_ResourceHandle G_PushResource(G_ArenaHandle arena, G_CommandListHandle cl, G_ResourceDesc desc);
|
// G_ResourceHandle G_PushResource(G_ArenaHandle arena, G_CommandListHandle cl, G_ResourceDesc desc);
|
||||||
|
|
||||||
#define G_PushBuffer(arena, cl, _type, _count, ...) G_PushResource((arena), (cl), \
|
// #define G_PushBuffer(arena, cl, _type, _count, ...) G_PushResource((arena), (cl), \
|
||||||
(G_ResourceDesc) { \
|
// (G_ResourceDesc) { \
|
||||||
.kind = G_ResourceKind_Buffer, \
|
// .kind = G_ResourceKind_Buffer, \
|
||||||
.buffer = { \
|
// .buffer = { \
|
||||||
.size = sizeof(_type) * (_count), \
|
// .size = sizeof(_type) * (_count), \
|
||||||
__VA_ARGS__ \
|
// __VA_ARGS__ \
|
||||||
} \
|
// } \
|
||||||
} \
|
// } \
|
||||||
)
|
// )
|
||||||
|
|
||||||
#define G_PushTexture1D(arena, cl, _format, _size, _initial_layout, ...) G_PushResource((arena), (cl), \
|
// #define G_PushTexture1D(arena, cl, _format, _size, _initial_layout, ...) G_PushResource((arena), (cl), \
|
||||||
(G_ResourceDesc) { \
|
// (G_ResourceDesc) { \
|
||||||
.kind = G_ResourceKind_Texture1D, \
|
// .kind = G_ResourceKind_Texture1D, \
|
||||||
.texture = { \
|
// .texture = { \
|
||||||
.format = (_format), \
|
// .format = (_format), \
|
||||||
.dims = VEC3I32((_size), 1, 1), \
|
// .dims = VEC3I32((_size), 1, 1), \
|
||||||
.initial_layout = (_initial_layout), \
|
// .initial_layout = (_initial_layout), \
|
||||||
__VA_ARGS__ \
|
// __VA_ARGS__ \
|
||||||
} \
|
// } \
|
||||||
} \
|
// } \
|
||||||
)
|
// )
|
||||||
|
|
||||||
#define G_PushTexture2D(arena, cl, _format, _size, _initial_layout, ...) G_PushResource((arena), (cl), \
|
// #define G_PushTexture2D(arena, cl, _format, _size, _initial_layout, ...) G_PushResource((arena), (cl), \
|
||||||
(G_ResourceDesc) { \
|
// (G_ResourceDesc) { \
|
||||||
.kind = G_ResourceKind_Texture2D, \
|
// .kind = G_ResourceKind_Texture2D, \
|
||||||
.texture = { \
|
// .texture = { \
|
||||||
.format = (_format), \
|
// .format = (_format), \
|
||||||
.dims = VEC3I32((_size).x, (_size).y, 1), \
|
// .dims = VEC3I32((_size).x, (_size).y, 1), \
|
||||||
.initial_layout = (_initial_layout), \
|
// .initial_layout = (_initial_layout), \
|
||||||
__VA_ARGS__ \
|
// __VA_ARGS__ \
|
||||||
} \
|
// } \
|
||||||
} \
|
// } \
|
||||||
)
|
// )
|
||||||
|
|
||||||
#define G_PushTexture3D(arena, cl, _format, _size, _initial_layout, ...) G_PushResource((arena), (cl), \
|
// #define G_PushTexture3D(arena, cl, _format, _size, _initial_layout, ...) G_PushResource((arena), (cl), \
|
||||||
(G_ResourceDesc) { \
|
// (G_ResourceDesc) { \
|
||||||
.kind = G_ResourceKind_Texture3D, \
|
// .kind = G_ResourceKind_Texture3D, \
|
||||||
.texture = { \
|
// .texture = { \
|
||||||
.format = (_format), \
|
// .format = (_format), \
|
||||||
.dims = (_size), \
|
// .dims = (_size), \
|
||||||
.initial_layout = (_initial_layout), \
|
// .initial_layout = (_initial_layout), \
|
||||||
__VA_ARGS__ \
|
// __VA_ARGS__ \
|
||||||
} \
|
// } \
|
||||||
} \
|
// } \
|
||||||
)
|
// )
|
||||||
|
|
||||||
#define G_PushSampler(arena, cl, ...) G_PushResource((arena), (cl), \
|
// #define G_PushSampler(arena, cl, ...) G_PushResource((arena), (cl), \
|
||||||
(G_ResourceDesc) { \
|
// (G_ResourceDesc) { \
|
||||||
.kind = G_ResourceKind_Sampler, \
|
// .kind = G_ResourceKind_Sampler, \
|
||||||
.sampler = { \
|
// .sampler = { \
|
||||||
.filter = G_Filter_MinMagMipPoint, \
|
// .filter = G_Filter_MinMagMipPoint, \
|
||||||
__VA_ARGS__ \
|
// __VA_ARGS__ \
|
||||||
} \
|
// } \
|
||||||
} \
|
// } \
|
||||||
)
|
// )
|
||||||
|
|
||||||
//- Index buffer helpers
|
//- Index buffer helpers
|
||||||
|
|
||||||
#define G_IdxBuff16(_res) ((G_IndexBufferDesc) { .resource = (_res), .stride = 2, .count = (G_CountBuffer((_res), i16)) })
|
// #define G_IdxBuff16(_res) ((G_IndexBufferDesc) { .resource = (_res), .stride = 2, .count = (G_CountBuffer((_res), i16)) })
|
||||||
#define G_IdxBuff32(_res) ((G_IndexBufferDesc) { .resource = (_res), .stride = 4, .count = (G_CountBuffer((_res), i32)) })
|
// #define G_IdxBuff32(_res) ((G_IndexBufferDesc) { .resource = (_res), .stride = 4, .count = (G_CountBuffer((_res), i32)) })
|
||||||
|
|
||||||
//- Render target helpers
|
//- Render target helpers
|
||||||
|
|
||||||
@ -520,49 +572,49 @@ void *G_HostPointerFromResource(G_ResourceHandle resource);
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ @hookdecl Shader resource reference
|
//~ @hookdecl Shader resource reference
|
||||||
|
|
||||||
u32 G_PushRef(G_ArenaHandle arena, G_ResourceHandle resource, G_RefDesc desc);
|
// u32 G_PushRef(G_ArenaHandle arena, G_ResourceHandle resource, G_RefDesc desc);
|
||||||
|
|
||||||
#define G_PushStructuredBufferRef(arena, resource, type, ...) (G_StructuredBufferRef) { \
|
// #define G_PushStructuredBufferRef(arena, resource, type, ...) (G_StructuredBufferRef) { \
|
||||||
.v = G_PushRef( \
|
// .v = G_PushRef( \
|
||||||
(arena), (resource), \
|
// (arena), (resource), \
|
||||||
(G_RefDesc) { .kind = G_RefKind_StructuredBuffer, .element_size = sizeof(type), __VA_ARGS__ } \
|
// (G_RefDesc) { .kind = G_RefKind_StructuredBuffer, .element_size = sizeof(type), __VA_ARGS__ } \
|
||||||
) \
|
// ) \
|
||||||
}
|
// }
|
||||||
|
|
||||||
#define G_PushByteAddressBufferRef(arena, resource, ...) (G_ByteAddressBufferRef) { \
|
// #define G_PushByteAddressBufferRef(arena, resource, ...) (G_ByteAddressBufferRef) { \
|
||||||
.v = G_PushRef( \
|
// .v = G_PushRef( \
|
||||||
(arena), (resource), \
|
// (arena), (resource), \
|
||||||
(G_RefDesc) { .kind = G_RefKind_ByteAddressBuffer, __VA_ARGS__ } \
|
// (G_RefDesc) { .kind = G_RefKind_ByteAddressBuffer, __VA_ARGS__ } \
|
||||||
) \
|
// ) \
|
||||||
}
|
// }
|
||||||
|
|
||||||
#define G_PushTexture1DRef(arena, resource, ...) (G_Texture1DRef) { \
|
// #define G_PushTexture1DRef(arena, resource, ...) (G_Texture1DRef) { \
|
||||||
.v = G_PushRef( \
|
// .v = G_PushRef( \
|
||||||
(arena), (resource), \
|
// (arena), (resource), \
|
||||||
(G_RefDesc) { .kind = G_RefKind_Texture1D, .mips.max = G_MaxMips, __VA_ARGS__ } \
|
// (G_RefDesc) { .kind = G_RefKind_Texture1D, .mips.max = G_MaxMips, __VA_ARGS__ } \
|
||||||
) \
|
// ) \
|
||||||
}
|
// }
|
||||||
|
|
||||||
#define G_PushTexture2DRef(arena, resource, ...) (G_Texture2DRef) { \
|
// #define G_PushTexture2DRef(arena, resource, ...) (G_Texture2DRef) { \
|
||||||
.v = G_PushRef( \
|
// .v = G_PushRef( \
|
||||||
(arena), (resource), \
|
// (arena), (resource), \
|
||||||
(G_RefDesc) { .kind = G_RefKind_Texture2D, .mips.max = G_MaxMips, __VA_ARGS__ } \
|
// (G_RefDesc) { .kind = G_RefKind_Texture2D, .mips.max = G_MaxMips, __VA_ARGS__ } \
|
||||||
) \
|
// ) \
|
||||||
}
|
// }
|
||||||
|
|
||||||
#define G_PushTexture3DRef(arena, resource, ...) (G_Texture3DRef) { \
|
// #define G_PushTexture3DRef(arena, resource, ...) (G_Texture3DRef) { \
|
||||||
.v = G_PushRef( \
|
// .v = G_PushRef( \
|
||||||
(arena), (resource), \
|
// (arena), (resource), \
|
||||||
(G_RefDesc) { .kind = G_RefKind_Texture3D, .mips.max = G_MaxMips, __VA_ARGS__ } \
|
// (G_RefDesc) { .kind = G_RefKind_Texture3D, .mips.max = G_MaxMips, __VA_ARGS__ } \
|
||||||
) \
|
// ) \
|
||||||
}
|
// }
|
||||||
|
|
||||||
#define G_PushSamplerStateRef(arena, resource, ...) (G_SamplerStateRef) { \
|
// #define G_PushSamplerStateRef(arena, resource, ...) (G_SamplerStateRef) { \
|
||||||
.v = G_PushRef( \
|
// .v = G_PushRef( \
|
||||||
(arena), (resource), \
|
// (arena), (resource), \
|
||||||
(G_RefDesc) { .kind = G_RefKind_SamplerState, __VA_ARGS__ } \
|
// (G_RefDesc) { .kind = G_RefKind_SamplerState, __VA_ARGS__ } \
|
||||||
) \
|
// ) \
|
||||||
}
|
// }
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ @hookdecl Command
|
//~ @hookdecl Command
|
||||||
@ -585,7 +637,7 @@ void G_SetConstantEx(G_CommandListHandle cl, i32 slot, void *src_32bit, u32 size
|
|||||||
//- Barrier
|
//- Barrier
|
||||||
|
|
||||||
void G_Sync(G_CommandListHandle cl);
|
void G_Sync(G_CommandListHandle cl);
|
||||||
void G_SyncLayout(G_CommandListHandle cl, G_ResourceHandle resource, G_Layout layout);
|
void G_SyncLayout(G_CommandListHandle cl, G_ResourceHandle resource, G_TextureLayout layout);
|
||||||
|
|
||||||
//- Zone
|
//- Zone
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -1,22 +1,13 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Ref types
|
//~ Gpu memory reference types
|
||||||
|
|
||||||
Enum(G_RefKind)
|
typedef u32 G_BaseDescriptorIndex;
|
||||||
{
|
|
||||||
G_RefKind_StructuredBuffer,
|
|
||||||
G_RefKind_ByteAddressBuffer,
|
|
||||||
G_RefKind_Texture1D,
|
|
||||||
G_RefKind_Texture2D,
|
|
||||||
G_RefKind_Texture3D,
|
|
||||||
G_RefKind_SamplerState,
|
|
||||||
};
|
|
||||||
|
|
||||||
Struct(G_StructuredBufferRef) { u32 v; };
|
Struct(G_BufferRef) { G_BaseDescriptorIndex v; };
|
||||||
Struct(G_ByteAddressBufferRef) { u32 v; };
|
Struct(G_Texture1DRef) { G_BaseDescriptorIndex v; };
|
||||||
Struct(G_Texture1DRef) { u32 v; };
|
Struct(G_Texture2DRef) { G_BaseDescriptorIndex v; };
|
||||||
Struct(G_Texture2DRef) { u32 v; };
|
Struct(G_Texture3DRef) { G_BaseDescriptorIndex v; };
|
||||||
Struct(G_Texture3DRef) { u32 v; };
|
Struct(G_SamplerRef) { G_BaseDescriptorIndex v; };
|
||||||
Struct(G_SamplerStateRef) { u32 v; };
|
|
||||||
|
|
||||||
#define G_IsRefNil(r) ((r).v == 0)
|
#define G_IsRefNil(r) ((r).v == 0)
|
||||||
|
|
||||||
@ -52,7 +43,7 @@ Struct(G_SamplerStateRef) { u32 v; };
|
|||||||
StaticAssert(G_NumGeneralPurposeConstants == 24);
|
StaticAssert(G_NumGeneralPurposeConstants == 24);
|
||||||
StaticAssert(G_NumReservedConstants >= 3);
|
StaticAssert(G_NumReservedConstants >= 3);
|
||||||
|
|
||||||
G_ForceDeclConstant(G_ByteAddressBufferRef, G_ShaderConst_PrintBufferRef, 24);
|
G_ForceDeclConstant(G_BufferRef, G_ShaderConst_PrintBuffer, 24);
|
||||||
G_ForceDeclConstant(b32, G_ShaderConst_TweakB32, 25);
|
G_ForceDeclConstant(b32, G_ShaderConst_TweakB32, 25);
|
||||||
G_ForceDeclConstant(f32, G_ShaderConst_TweakF32, 26);
|
G_ForceDeclConstant(f32, G_ShaderConst_TweakF32, 26);
|
||||||
|
|
||||||
@ -85,31 +76,70 @@ Enum(G_BasicSamplerKind)
|
|||||||
#if IsGpu
|
#if IsGpu
|
||||||
// NOTE: Uniform dereferencing is faster than Non-Uniform on AMD hardware
|
// NOTE: Uniform dereferencing is faster than Non-Uniform on AMD hardware
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//- Scalar/Uniform dereference
|
//- Scalar/Uniform dereference
|
||||||
SamplerState G_SDeref(G_SamplerStateRef r) { return SamplerDescriptorHeap[r.v]; }
|
template<typename T> StructuredBuffer<T> G_SDeref(G_BufferRef r) { return ResourceDescriptorHeap[r.v + 0]; }
|
||||||
template<typename T> StructuredBuffer<T> G_SDeref(G_StructuredBufferRef r) { return ResourceDescriptorHeap[r.v]; }
|
template<typename T> RWStructuredBuffer<T> G_SDerefRW(G_BufferRef r) { return ResourceDescriptorHeap[r.v + 1]; }
|
||||||
ByteAddressBuffer G_SDeref(G_ByteAddressBufferRef r) { return ResourceDescriptorHeap[r.v]; }
|
ByteAddressBuffer G_SDerefRaw(G_BufferRef r) { return ResourceDescriptorHeap[r.v + 2]; }
|
||||||
template<typename T> Texture1D<T> G_SDeref(G_Texture1DRef r) { return ResourceDescriptorHeap[r.v]; }
|
RWByteAddressBuffer G_SDerefRawRW(G_BufferRef r) { return ResourceDescriptorHeap[r.v + 3]; }
|
||||||
template<typename T> Texture2D<T> G_SDeref(G_Texture2DRef r) { return ResourceDescriptorHeap[r.v]; }
|
template<typename T> Texture1D<T> G_SDeref(G_Texture1DRef r, u32 mip=0) { return ResourceDescriptorHeap[r.v + (mip * 2) + 0]; }
|
||||||
template<typename T> Texture3D<T> G_SDeref(G_Texture3DRef r) { return ResourceDescriptorHeap[r.v]; }
|
template<typename T> Texture2D<T> G_SDeref(G_Texture2DRef r, u32 mip=0) { return ResourceDescriptorHeap[r.v + (mip * 2) + 0]; }
|
||||||
template<typename T> RWStructuredBuffer<T> G_SDerefRW(G_StructuredBufferRef r) { return ResourceDescriptorHeap[r.v + 1]; }
|
template<typename T> Texture3D<T> G_SDeref(G_Texture3DRef r, u32 mip=0) { return ResourceDescriptorHeap[r.v + (mip * 2) + 0]; }
|
||||||
RWByteAddressBuffer G_SDerefRW(G_ByteAddressBufferRef r) { return ResourceDescriptorHeap[r.v + 1]; }
|
template<typename T> RWTexture1D<T> G_SDerefRW(G_Texture1DRef r, u32 mip=0) { return ResourceDescriptorHeap[r.v + (mip * 2) + 1]; }
|
||||||
template<typename T> RWTexture1D<T> G_SDerefRW(G_Texture1DRef r) { return ResourceDescriptorHeap[r.v + 1]; }
|
template<typename T> RWTexture2D<T> G_SDerefRW(G_Texture2DRef r, u32 mip=0) { return ResourceDescriptorHeap[r.v + (mip * 2) + 1]; }
|
||||||
template<typename T> RWTexture2D<T> G_SDerefRW(G_Texture2DRef r) { return ResourceDescriptorHeap[r.v + 1]; }
|
template<typename T> RWTexture3D<T> G_SDerefRW(G_Texture3DRef r, u32 mip=0) { return ResourceDescriptorHeap[r.v + (mip * 2) + 1]; }
|
||||||
template<typename T> RWTexture3D<T> G_SDerefRW(G_Texture3DRef r) { return ResourceDescriptorHeap[r.v + 1]; }
|
SamplerState G_SDeref(G_SamplerRef r) { return SamplerDescriptorHeap[r.v]; }
|
||||||
|
|
||||||
//- Vector/Non-Uniform dereference
|
//- Vector/Non-Uniform dereference
|
||||||
SamplerState G_VDeref(G_SamplerStateRef r) { return SamplerDescriptorHeap[NonUniformResourceIndex(r.v)]; }
|
template<typename T> StructuredBuffer<T> G_VDeref(G_BufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 0)]; }
|
||||||
template<typename T> StructuredBuffer<T> G_VDeref(G_StructuredBufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v)]; }
|
template<typename T> RWStructuredBuffer<T> G_VDerefRW(G_BufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; }
|
||||||
ByteAddressBuffer G_VDeref(G_ByteAddressBufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v)]; }
|
ByteAddressBuffer G_VDerefRaw(G_BufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 2)]; }
|
||||||
template<typename T> Texture1D<T> G_VDeref(G_Texture1DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v)]; }
|
RWByteAddressBuffer G_VDerefRawRW(G_BufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 3)]; }
|
||||||
template<typename T> Texture2D<T> G_VDeref(G_Texture2DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v)]; }
|
template<typename T> Texture1D<T> G_VDeref(G_Texture1DRef r, u32 mip=0) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + (mip * 2) + 0)]; }
|
||||||
template<typename T> Texture3D<T> G_VDeref(G_Texture3DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v)]; }
|
template<typename T> Texture2D<T> G_VDeref(G_Texture2DRef r, u32 mip=0) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + (mip * 2) + 0)]; }
|
||||||
template<typename T> RWStructuredBuffer<T> G_VDerefRW(G_StructuredBufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; }
|
template<typename T> Texture3D<T> G_VDeref(G_Texture3DRef r, u32 mip=0) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + (mip * 2) + 0)]; }
|
||||||
RWByteAddressBuffer G_VDerefRW(G_ByteAddressBufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; }
|
template<typename T> RWTexture1D<T> G_VDerefRW(G_Texture1DRef r, u32 mip=0) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + (mip * 2) + 1)]; }
|
||||||
template<typename T> RWTexture1D<T> G_VDerefRW(G_Texture1DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; }
|
template<typename T> RWTexture2D<T> G_VDerefRW(G_Texture2DRef r, u32 mip=0) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + (mip * 2) + 1)]; }
|
||||||
template<typename T> RWTexture2D<T> G_VDerefRW(G_Texture2DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; }
|
template<typename T> RWTexture3D<T> G_VDerefRW(G_Texture3DRef r, u32 mip=0) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + (mip * 2) + 1)]; }
|
||||||
template<typename T> RWTexture3D<T> G_VDerefRW(G_Texture3DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; }
|
SamplerState G_VDeref(G_SamplerRef r) { return SamplerDescriptorHeap[NonUniformResourceIndex(r.v)]; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// //- Scalar/Uniform dereference
|
||||||
|
// ByteAddressBuffer G_SDerefRaw(G_BufferRef r) { return ResourceDescriptorHeap[r.v + 2]; }
|
||||||
|
// RWByteAddressBuffer G_SDerefRawRW(G_BufferRef r) { return ResourceDescriptorHeap[r.v + 3]; }
|
||||||
|
// template<typename T> StructuredBuffer<T> G_SDeref(G_BufferRef r) { return ResourceDescriptorHeap[r.v + 0]; }
|
||||||
|
// template<typename T> RWStructuredBuffer<T> G_SDerefRW(G_BufferRef r) { return ResourceDescriptorHeap[r.v + 1]; }
|
||||||
|
// template<typename T> Texture1D<T> G_SDeref(G_Texture1DRef r) { return ResourceDescriptorHeap[r.v + 0]; }
|
||||||
|
// template<typename T> Texture2D<T> G_SDeref(G_Texture2DRef r) { return ResourceDescriptorHeap[r.v + 0]; }
|
||||||
|
// template<typename T> Texture3D<T> G_SDeref(G_Texture3DRef r) { return ResourceDescriptorHeap[r.v + 0]; }
|
||||||
|
// template<typename T> RWTexture1D<T> G_SDerefRW(G_Texture1DRef r) { return ResourceDescriptorHeap[r.v + 1]; }
|
||||||
|
// template<typename T> RWTexture2D<T> G_SDerefRW(G_Texture2DRef r) { return ResourceDescriptorHeap[r.v + 1]; }
|
||||||
|
// template<typename T> RWTexture3D<T> G_SDerefRW(G_Texture3DRef r) { return ResourceDescriptorHeap[r.v + 1]; }
|
||||||
|
// SamplerState G_SDeref(G_SamplerStateRef r) { return SamplerDescriptorHeap[r.v]; }
|
||||||
|
|
||||||
|
// //- Vector/Non-Uniform dereference
|
||||||
|
// ByteAddressBuffer G_VDerefRaw(G_BufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 2)]; }
|
||||||
|
// RWByteAddressBuffer G_VDerefRawRW(G_BufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 3)]; }
|
||||||
|
// template<typename T> StructuredBuffer<T> G_VDeref(G_BufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 0)]; }
|
||||||
|
// template<typename T> RWStructuredBuffer<T> G_VDerefRW(G_BufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; }
|
||||||
|
// template<typename T> Texture1D<T> G_VDeref(G_Texture1DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 0)]; }
|
||||||
|
// template<typename T> Texture2D<T> G_VDeref(G_Texture2DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 0)]; }
|
||||||
|
// template<typename T> Texture3D<T> G_VDeref(G_Texture3DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 0)]; }
|
||||||
|
// template<typename T> RWTexture1D<T> G_VDerefRW(G_Texture1DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; }
|
||||||
|
// template<typename T> RWTexture2D<T> G_VDerefRW(G_Texture2DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; }
|
||||||
|
// template<typename T> RWTexture3D<T> G_VDerefRW(G_Texture3DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; }
|
||||||
|
// SamplerState G_VDeref(G_SamplerStateRef r) { return SamplerDescriptorHeap[NonUniformResourceIndex(r.v)]; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -225,7 +255,7 @@ Struct(G_FmtArg)
|
|||||||
|
|
||||||
void G_CommitPrint(G_TempPrintBuffer buff)
|
void G_CommitPrint(G_TempPrintBuffer buff)
|
||||||
{
|
{
|
||||||
RWByteAddressBuffer rw = G_SDerefRW(G_ShaderConst_PrintBufferRef);
|
RWByteAddressBuffer rw = G_SDerefRawRW(G_ShaderConst_PrintBuffer);
|
||||||
|
|
||||||
if (buff.overflowed)
|
if (buff.overflowed)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -400,15 +400,6 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
Vec2I32 cells_dims = VEC2I32(P_CellsPitch, P_CellsPitch);
|
Vec2I32 cells_dims = VEC2I32(P_CellsPitch, P_CellsPitch);
|
||||||
|
|
||||||
//- Init gpu state
|
//- Init gpu state
|
||||||
G_ResourceHandle gpu_tiles_res = Zi;
|
|
||||||
G_ResourceHandle gpu_particles_res = Zi;
|
|
||||||
G_ResourceHandle gpu_particle_cell_resources[V_ParticleLayer_COUNT];
|
|
||||||
G_ResourceHandle gpu_particle_density_resources[V_ParticleLayer_COUNT];
|
|
||||||
G_ResourceHandle gpu_stains_res = Zi;
|
|
||||||
G_ResourceHandle gpu_dry_stains_res = Zi;
|
|
||||||
G_ResourceHandle gpu_drynesses_res = Zi;
|
|
||||||
G_ResourceHandle gpu_occluders_res = Zi;
|
|
||||||
|
|
||||||
G_Texture2DRef gpu_tiles = Zi;
|
G_Texture2DRef gpu_tiles = Zi;
|
||||||
G_StructuredBufferRef gpu_particles = Zi;
|
G_StructuredBufferRef gpu_particles = Zi;
|
||||||
G_Texture2DRef gpu_particle_cells[V_ParticleLayer_COUNT];
|
G_Texture2DRef gpu_particle_cells[V_ParticleLayer_COUNT];
|
||||||
@ -421,106 +412,85 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_Direct);
|
G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_Direct);
|
||||||
{
|
{
|
||||||
//- Init tile map texture
|
//- Init tile map texture
|
||||||
{
|
gpu_tiles = G_PushTexture2DZero(
|
||||||
gpu_tiles_res = G_PushTexture2D(
|
cl,
|
||||||
gpu_perm, cl,
|
gpu_perm,
|
||||||
|
G_TextureLayout_Family,
|
||||||
G_Format_R8_Uint,
|
G_Format_R8_Uint,
|
||||||
tiles_dims,
|
tiles_dims,
|
||||||
G_Layout_Exclusive,
|
|
||||||
.flags = G_ResourceFlag_ZeroMemory,
|
|
||||||
.name = Lit("Tiles")
|
.name = Lit("Tiles")
|
||||||
);
|
);
|
||||||
gpu_tiles = G_PushTexture2DRef(gpu_perm, gpu_tiles_res);
|
|
||||||
}
|
|
||||||
//- Init particle buffer
|
//- Init particle buffer
|
||||||
{
|
gpu_particles = G_PushBufferZero(
|
||||||
gpu_particles_res = G_PushBuffer(
|
cl,
|
||||||
gpu_perm, cl,
|
gpu_perm,
|
||||||
V_Particle,
|
V_Particle,
|
||||||
V_ParticlesCap,
|
V_ParticlesCap,
|
||||||
.flags = G_ResourceFlag_ZeroMemory | G_ResourceFlag_AllowShaderReadWrite,
|
|
||||||
.name = Lit("Particles")
|
.name = Lit("Particles")
|
||||||
);
|
);
|
||||||
gpu_particles = G_PushStructuredBufferRef(gpu_perm, gpu_particles_res, V_Particle);
|
|
||||||
}
|
|
||||||
//- Init particle textures
|
//- Init particle textures
|
||||||
for (V_ParticleLayer layer = 0; layer < V_ParticleLayer_COUNT; ++layer)
|
for (V_ParticleLayer layer = 0; layer < V_ParticleLayer_COUNT; ++layer)
|
||||||
{
|
{
|
||||||
{
|
gpu_particle_cells[layer] = G_PushTexture2DZero(
|
||||||
G_ResourceHandle cells_res = G_PushTexture2D(
|
cl,
|
||||||
gpu_perm, cl,
|
gpu_perm,
|
||||||
|
G_TextureLayout_Family,
|
||||||
G_Format_R32_Uint,
|
G_Format_R32_Uint,
|
||||||
cells_dims,
|
cells_dims,
|
||||||
G_Layout_Exclusive,
|
.flags = G_TextureFlag_AllowRW,
|
||||||
.flags = G_ResourceFlag_ZeroMemory | G_ResourceFlag_AllowShaderReadWrite,
|
|
||||||
.name = StringF(perm, "Particle cells - layer %F", FmtSint(layer))
|
.name = StringF(perm, "Particle cells - layer %F", FmtSint(layer))
|
||||||
);
|
);
|
||||||
G_Texture2DRef cells = G_PushTexture2DRef(gpu_perm, cells_res);
|
gpu_particle_densities[layer] = G_PushTexture2DZero(
|
||||||
gpu_particle_cell_resources[layer] = cells_res;
|
cl,
|
||||||
gpu_particle_cells[layer] = cells;
|
gpu_perm,
|
||||||
}
|
G_TextureLayout_Family,
|
||||||
{
|
|
||||||
G_ResourceHandle densities_res = G_PushTexture2D(
|
|
||||||
gpu_perm, cl,
|
|
||||||
G_Format_R32_Uint,
|
G_Format_R32_Uint,
|
||||||
cells_dims,
|
cells_dims,
|
||||||
G_Layout_Exclusive,
|
.flags = G_TextureFlag_AllowRW,
|
||||||
.flags = G_ResourceFlag_ZeroMemory | G_ResourceFlag_AllowShaderReadWrite,
|
|
||||||
.name = StringF(perm, "Particle densities - layer %F", FmtSint(layer))
|
.name = StringF(perm, "Particle densities - layer %F", FmtSint(layer))
|
||||||
);
|
);
|
||||||
G_Texture2DRef densities = G_PushTexture2DRef(gpu_perm, densities_res);
|
|
||||||
gpu_particle_density_resources[layer] = densities_res;
|
|
||||||
gpu_particle_densities[layer] = densities;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//- Init stains texture
|
//- Init stains texture
|
||||||
{
|
gpu_stains = G_PushTexture2DZero(
|
||||||
gpu_stains_res = G_PushTexture2D(
|
cl,
|
||||||
gpu_perm, cl,
|
gpu_perm,
|
||||||
|
G_TextureLayout_Family,
|
||||||
G_Format_R16G16B16A16_Float,
|
G_Format_R16G16B16A16_Float,
|
||||||
cells_dims,
|
cells_dims,
|
||||||
G_Layout_Exclusive,
|
.flags = G_TextureFlag_AllowRW,
|
||||||
.flags = G_ResourceFlag_ZeroMemory | G_ResourceFlag_AllowShaderReadWrite,
|
|
||||||
.name = Lit("Stains")
|
.name = Lit("Stains")
|
||||||
);
|
);
|
||||||
gpu_stains = G_PushTexture2DRef(gpu_perm, gpu_stains_res);
|
|
||||||
}
|
|
||||||
//- Init dry stains texture
|
//- Init dry stains texture
|
||||||
{
|
gpu_dry_stains = G_PushTexture2DZero(
|
||||||
gpu_dry_stains_res = G_PushTexture2D(
|
|
||||||
gpu_perm, cl,
|
gpu_perm, cl,
|
||||||
|
G_TextureLayout_Family,
|
||||||
G_Format_R16G16B16A16_Float,
|
G_Format_R16G16B16A16_Float,
|
||||||
cells_dims,
|
cells_dims,
|
||||||
G_Layout_Exclusive,
|
.flags = G_TextureFlag_AllowRW,
|
||||||
.flags = G_ResourceFlag_ZeroMemory | G_ResourceFlag_AllowShaderReadWrite,
|
|
||||||
.name = Lit("Dry stains")
|
.name = Lit("Dry stains")
|
||||||
);
|
);
|
||||||
gpu_dry_stains = G_PushTexture2DRef(gpu_perm, gpu_dry_stains_res);
|
|
||||||
}
|
|
||||||
//- Init dryness texture
|
//- Init dryness texture
|
||||||
{
|
gpu_drynesses = G_PushTexture2DZero(
|
||||||
gpu_drynesses_res = G_PushTexture2D(
|
cl,
|
||||||
gpu_perm, cl,
|
gpu_perm,
|
||||||
|
G_TextureLayout_Family,
|
||||||
G_Format_R32_Float,
|
G_Format_R32_Float,
|
||||||
cells_dims,
|
cells_dims,
|
||||||
G_Layout_Exclusive,
|
.flags = G_TextureFlag_AllowRW,
|
||||||
.flags = G_ResourceFlag_ZeroMemory | G_ResourceFlag_AllowShaderReadWrite,
|
|
||||||
.name = Lit("Drynesses")
|
.name = Lit("Drynesses")
|
||||||
);
|
);
|
||||||
gpu_drynesses = G_PushTexture2DRef(gpu_perm, gpu_drynesses_res);
|
|
||||||
}
|
|
||||||
//- Init occluders texture
|
//- Init occluders texture
|
||||||
{
|
gpu_occluders = G_PushTexture2DZero(
|
||||||
gpu_occluders_res = G_PushTexture2D(
|
cl,
|
||||||
gpu_perm, cl,
|
gpu_perm,
|
||||||
|
G_TextureLayout_Family,
|
||||||
G_Format_R32_Uint,
|
G_Format_R32_Uint,
|
||||||
cells_dims,
|
cells_dims,
|
||||||
G_Layout_Exclusive,
|
.flags = G_TextureFlag_AllowRW,
|
||||||
.flags = G_ResourceFlag_ZeroMemory | G_ResourceFlag_AllowShaderReadWrite,
|
.name = Lit("Occluders")
|
||||||
.name = Lit("Occluders cells")
|
|
||||||
);
|
);
|
||||||
gpu_occluders = G_PushTexture2DRef(gpu_perm, gpu_occluders_res);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
G_CommitCommandList(cl);
|
G_CommitCommandList(cl);
|
||||||
}
|
}
|
||||||
@ -5142,104 +5112,90 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
// LogDebugF("Uploading tiles to gpu");
|
// LogDebugF("Uploading tiles to gpu");
|
||||||
G_CopyCpuToTexture(
|
G_CopyCpuToTexture(
|
||||||
cl,
|
cl,
|
||||||
gpu_tiles_res, VEC3I32(0, 0, 0),
|
gpu_tiles, VEC3I32(0, 0, 0),
|
||||||
frame->local_world->tiles, VEC3I32(tiles_dims.x, tiles_dims.y, 1),
|
frame->local_world->tiles, VEC3I32(tiles_dims.x, tiles_dims.y, 1),
|
||||||
RNG3I32(VEC3I32(0, 0, 0), VEC3I32(tiles_dims.x, tiles_dims.y, 1))
|
RNG3I32(VEC3I32(0, 0, 0), VEC3I32(tiles_dims.x, tiles_dims.y, 1))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Screen texture
|
// Screen texture
|
||||||
G_ResourceHandle screen_target = G_PushTexture2D(
|
frame->screen = G_PushTexture2D(
|
||||||
gpu_frame_arena, cl,
|
cl, gpu_frame_arena,
|
||||||
G_Format_R16G16B16A16_Float,
|
G_Format_R16G16B16A16_Float,
|
||||||
frame->screen_dims,
|
frame->screen_dims,
|
||||||
G_Layout_Exclusive,
|
G_TextureLayout_Family,
|
||||||
.flags = G_ResourceFlag_AllowShaderReadWrite | G_ResourceFlag_AllowRenderTarget,
|
.flags = G_TextureFlag_AllowRW | G_ResourceFlag_AllowRenderTarget,
|
||||||
.name = StringF(frame->arena, "Screen target [%F]", FmtSint(frame->tick))
|
.name = StringF(frame->arena, "Screen target [%F]", FmtSint(frame->tick))
|
||||||
);
|
);
|
||||||
Rng3 screen_viewport = RNG3(VEC3(0, 0, 0), VEC3(frame->screen_dims.x, frame->screen_dims.y, 1));
|
Rng3 screen_viewport = RNG3(VEC3(0, 0, 0), VEC3(frame->screen_dims.x, frame->screen_dims.y, 1));
|
||||||
Rng2 screen_scissor = RNG2(VEC2(screen_viewport.p0.x, screen_viewport.p0.y), VEC2(screen_viewport.p1.x, screen_viewport.p1.y));
|
Rng2 screen_scissor = RNG2(VEC2(screen_viewport.p0.x, screen_viewport.p0.y), VEC2(screen_viewport.p1.x, screen_viewport.p1.y));
|
||||||
frame->screen = G_PushTexture2DRef(gpu_frame_arena, screen_target);
|
|
||||||
|
|
||||||
// Albedo texture
|
// Albedo texture
|
||||||
G_ResourceHandle albedo_target = G_PushTexture2D(
|
frame->albedo = G_PushTexture2D(
|
||||||
gpu_frame_arena, cl,
|
cl, gpu_frame_arena,
|
||||||
G_Format_R16G16B16A16_Float,
|
G_Format_R16G16B16A16_Float,
|
||||||
frame->screen_dims,
|
frame->screen_dims,
|
||||||
G_Layout_Exclusive,
|
G_TextureLayout_Family,
|
||||||
.flags = G_ResourceFlag_AllowRenderTarget,
|
.flags = G_ResourceFlag_AllowRenderTarget,
|
||||||
.name = StringF(frame->arena, "Albedo target [%F]", FmtSint(frame->tick))
|
.name = StringF(frame->arena, "Albedo target [%F]", FmtSint(frame->tick))
|
||||||
);
|
);
|
||||||
frame->albedo = G_PushTexture2DRef(gpu_frame_arena, albedo_target);
|
|
||||||
|
|
||||||
// Backdrop texture
|
// Backdrop texture
|
||||||
G_ResourceHandle backdrop_target = G_PushTexture2D(
|
frame->backdrop_chain = G_PushTexture2D(
|
||||||
gpu_frame_arena, cl,
|
cl, gpu_frame_arena,
|
||||||
G_Format_R16G16B16A16_Float,
|
G_Format_R16G16B16A16_Float,
|
||||||
G_DimsFromMip2D(G_Count2D(screen_target), 1),
|
G_DimsFromMip2D(G_Count2D(screen_target), 1),
|
||||||
G_Layout_Exclusive,
|
G_TextureLayout_Family,
|
||||||
.flags = G_ResourceFlag_AllowShaderReadWrite,
|
.flags = G_TextureFlag_AllowRW,
|
||||||
.name = StringF(frame->arena, "Backdrop target [%F]", FmtSint(frame->tick)),
|
.name = StringF(frame->arena, "Backdrop target [%F]", FmtSint(frame->tick)),
|
||||||
.max_mips = 4
|
.max_mips = 4
|
||||||
);
|
);
|
||||||
for (i32 mip_idx = 0; mip_idx < G_CountMips(backdrop_target); ++mip_idx)
|
|
||||||
{
|
|
||||||
frame->backdrop_mips[mip_idx] = G_PushTexture2DRef(gpu_frame_arena, backdrop_target, .mips = RNGI32(mip_idx, mip_idx));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bloom texture
|
// Bloom texture
|
||||||
// TODO: We can re-use backdrop mip chain for this
|
// TODO: We can re-use backdrop mip chain for this
|
||||||
G_ResourceHandle bloom_target = G_PushTexture2D(
|
frame->bloom_chain = G_PushTexture2D(
|
||||||
gpu_frame_arena, cl,
|
cl, gpu_frame_arena,
|
||||||
G_Format_R16G16B16A16_Float,
|
G_Format_R16G16B16A16_Float,
|
||||||
G_DimsFromMip2D(G_Count2D(screen_target), 1),
|
G_DimsFromMip2D(G_Count2D(screen_target), 1),
|
||||||
G_Layout_Exclusive,
|
G_TextureLayout_Family,
|
||||||
.flags = G_ResourceFlag_AllowShaderReadWrite,
|
.flags = G_TextureFlag_AllowRW,
|
||||||
.name = StringF(frame->arena, "Bloom target [%F]", FmtSint(frame->tick)),
|
.name = StringF(frame->arena, "Bloom target [%F]", FmtSint(frame->tick)),
|
||||||
.max_mips = G_MaxMips
|
.max_mips = G_MaxMips
|
||||||
);
|
);
|
||||||
for (i32 mip_idx = 0; mip_idx < G_CountMips(bloom_target); ++mip_idx)
|
|
||||||
{
|
|
||||||
frame->bloom_mips[mip_idx] = G_PushTexture2DRef(gpu_frame_arena, bloom_target, .mips = RNGI32(mip_idx, mip_idx));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shade texture
|
// Shade texture
|
||||||
G_ResourceHandle shade_target = G_PushTexture2D(
|
frame->shade = G_PushTexture2D(
|
||||||
gpu_frame_arena, cl,
|
cl, gpu_frame_arena,
|
||||||
|
G_TextureLayout_Family,
|
||||||
G_Format_R16G16B16A16_Float,
|
G_Format_R16G16B16A16_Float,
|
||||||
frame->shade_dims,
|
frame->shade_dims,
|
||||||
G_Layout_Exclusive,
|
.flags = G_TextureFlag_AllowRW,
|
||||||
.flags = G_ResourceFlag_AllowShaderReadWrite,
|
|
||||||
.name = StringF(frame->arena, "Shade target [%F]", FmtSint(frame->tick))
|
.name = StringF(frame->arena, "Shade target [%F]", FmtSint(frame->tick))
|
||||||
);
|
);
|
||||||
Rng3 shade_viewport = RNG3(VEC3(0, 0, 0), VEC3(frame->shade_dims.x, frame->shade_dims.y, 1));
|
Rng3 shade_viewport = RNG3(VEC3(0, 0, 0), VEC3(frame->shade_dims.x, frame->shade_dims.y, 1));
|
||||||
Rng2 shade_scissor = RNG2(VEC2(shade_viewport.p0.x, shade_viewport.p0.y), VEC2(shade_viewport.p1.x, shade_viewport.p1.y));
|
Rng2 shade_scissor = RNG2(VEC2(shade_viewport.p0.x, shade_viewport.p0.y), VEC2(shade_viewport.p1.x, shade_viewport.p1.y));
|
||||||
frame->shade = G_PushTexture2DRef(gpu_frame_arena, shade_target);
|
|
||||||
|
|
||||||
// Quad buffers
|
// Quad buffers
|
||||||
G_ResourceHandle quads_buff = G_PushBufferFromCpuCopy(
|
frame->quads = G_PushBufferFromCpuArena(
|
||||||
gpu_frame_arena, cl,
|
cl, gpu_frame_arena,
|
||||||
StringFromArena(frame->quads_arena),
|
frame->quads_arena, V_GpuQuad,
|
||||||
.name = StringF(frame->arena, "quads [%F]", FmtSint(frame->tick))
|
.name = StringF(frame->arena, "quads [%F]", FmtSint(frame->tick))
|
||||||
);
|
);
|
||||||
frame->quads = G_PushStructuredBufferRef(gpu_frame_arena, quads_buff, V_Quad);
|
|
||||||
|
|
||||||
// Debug shape buffers
|
// Debug shape buffers
|
||||||
G_ResourceHandle dverts_buff = G_PushBufferFromCpuCopy(
|
frame->dverts = G_PushBufferFromCpuArena(
|
||||||
gpu_frame_arena, cl,
|
cl, gpu_frame_arena,
|
||||||
StringFromArena(frame->dverts_arena),
|
frame->dverts_arena, V_DVert,
|
||||||
.name = StringF(frame->arena, "dverts [%F]", FmtSint(frame->tick))
|
.name = StringF(frame->arena, "dverts [%F]", FmtSint(frame->tick))
|
||||||
);
|
);
|
||||||
G_ResourceHandle dvert_idxs_buff = G_PushBufferFromCpuCopy(
|
frame->dvert_idxs = G_PushBufferFromCpu(
|
||||||
gpu_frame_arena, cl,
|
cl, gpu_frame_arena,
|
||||||
StringFromArena(frame->dvert_idxs_arena),
|
frame->dvert_idxs_arena, u32,
|
||||||
.name = StringF(frame->arena, "dvert idxs [%F]", FmtSint(frame->tick))
|
.name = StringF(frame->arena, "dvert idxs [%F]", FmtSint(frame->tick))
|
||||||
);
|
);
|
||||||
frame->dverts = G_PushStructuredBufferRef(gpu_frame_arena, dverts_buff, V_DVert);
|
|
||||||
G_IndexBufferDesc dvert_idxs_ib = G_IdxBuff32(dvert_idxs_buff);
|
|
||||||
|
|
||||||
// Particles
|
// Particles
|
||||||
G_ResourceHandle gpu_emitters = Zi;
|
G_BufferRef gpu_emitters = Zi;
|
||||||
{
|
{
|
||||||
// Flatten emitters list
|
// Flatten emitters list
|
||||||
V_Emitter *flattened_emitters = PushStructsNoZero(frame->arena, V_Emitter, frame->emitters_count);
|
V_Emitter *flattened_emitters = PushStructsNoZero(frame->arena, V_Emitter, frame->emitters_count);
|
||||||
@ -5251,8 +5207,8 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
++emitter_idx;
|
++emitter_idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gpu_emitters = G_PushBufferFromCpuCopy(
|
frame->emitters = G_PushBufferFromCpu(
|
||||||
gpu_frame_arena, cl,
|
cl, gpu_frame_arena,
|
||||||
StringFromStructs(flattened_emitters, frame->emitters_count),
|
StringFromStructs(flattened_emitters, frame->emitters_count),
|
||||||
.name = StringF(frame->arena, "emitters [%F]", FmtSint(frame->tick))
|
.name = StringF(frame->arena, "emitters [%F]", FmtSint(frame->tick))
|
||||||
);
|
);
|
||||||
@ -5260,12 +5216,11 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
frame->emitters = G_PushStructuredBufferRef(gpu_frame_arena, gpu_emitters, V_Emitter);
|
frame->emitters = G_PushStructuredBufferRef(gpu_frame_arena, gpu_emitters, V_Emitter);
|
||||||
|
|
||||||
// Upload gpu frame
|
// Upload gpu frame
|
||||||
G_ResourceHandle gpu_frame_res = G_PushBufferFromCpuCopy(
|
G_BufferRef gpu_frame = G_PushBufferFromCpu(
|
||||||
gpu_frame_arena, cl,
|
cl, gpu_frame_arena,
|
||||||
StringFromStruct(&frame->shared_frame),
|
StringFromStruct(&frame->shared_frame),
|
||||||
.name = StringF(frame->arena, "Gpu frame [%F]", FmtSint(frame->tick))
|
.name = StringF(frame->arena, "Gpu frame [%F]", FmtSint(frame->tick))
|
||||||
);
|
);
|
||||||
G_StructuredBufferRef gpu_frame = G_PushStructuredBufferRef(gpu_frame_arena, gpu_frame_res, V_SharedFrame);
|
|
||||||
|
|
||||||
// Set initial constants
|
// Set initial constants
|
||||||
V_GpuFlag gpu_flags = V_GpuFlag_None;
|
V_GpuFlag gpu_flags = V_GpuFlag_None;
|
||||||
@ -5330,14 +5285,14 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
|
|
||||||
G_ZoneDF(cl, "Quads & emitters")
|
G_ZoneDF(cl, "Quads & emitters")
|
||||||
{
|
{
|
||||||
G_ClearRenderTarget(cl, albedo_target, VEC4(0, 0, 0, 0), 0);
|
G_ClearRenderTarget(cl, frame->albedo, VEC4(0, 0, 0, 0), 0);
|
||||||
|
|
||||||
// Draw quads
|
// Draw quads
|
||||||
G_Draw(
|
G_Draw(
|
||||||
cl,
|
cl,
|
||||||
V_QuadVS, V_QuadPS,
|
V_QuadVS, V_QuadPS,
|
||||||
G_CountBuffer(quads_buff, V_Quad), G_QuadIndices(),
|
G_CountBuffer(quads_buff, V_Quad), G_QuadIndices(),
|
||||||
1, &G_Rt(albedo_target, G_BlendMode_CompositeStraightAlpha),
|
1, &G_Rt(frame->albedo, G_BlendMode_CompositeStraightAlpha),
|
||||||
screen_viewport, screen_scissor,
|
screen_viewport, screen_scissor,
|
||||||
G_DrawMode_TriangleList
|
G_DrawMode_TriangleList
|
||||||
);
|
);
|
||||||
@ -5435,13 +5390,12 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
//- Debug shapes pass
|
//- Debug shapes pass
|
||||||
|
|
||||||
G_ZoneDF(cl, "Debug shapes")
|
G_ZoneDF(cl, "Debug shapes")
|
||||||
if (dvert_idxs_ib.count > 0)
|
|
||||||
{
|
{
|
||||||
G_Draw(
|
G_Draw(
|
||||||
cl,
|
cl,
|
||||||
V_DVertVS, V_DVertPS,
|
V_DVertVS, V_DVertPS,
|
||||||
1, dvert_idxs_ib,
|
1, frame->dvert_idxs,
|
||||||
1, &G_Rt(screen_target, G_BlendMode_CompositeStraightAlpha),
|
1, &G_Rt(frame->screen, G_BlendMode_CompositeStraightAlpha),
|
||||||
screen_viewport, screen_scissor,
|
screen_viewport, screen_scissor,
|
||||||
G_DrawMode_TriangleList
|
G_DrawMode_TriangleList
|
||||||
);
|
);
|
||||||
|
|||||||
@ -343,20 +343,20 @@ Struct(V_SharedFrame)
|
|||||||
|
|
||||||
//- Gpu data
|
//- Gpu data
|
||||||
|
|
||||||
G_SamplerStateRef basic_samplers[G_BasicSamplerKind_COUNT];
|
G_SamplerRef basic_samplers[G_BasicSamplerKind_COUNT];
|
||||||
|
|
||||||
V_TileDesc tile_descs[P_TileKind_COUNT];
|
V_TileDesc tile_descs[P_TileKind_COUNT];
|
||||||
G_Texture2DRef tiles;
|
G_Texture2DRef tiles;
|
||||||
|
|
||||||
f32 backdrop_parallax;
|
f32 backdrop_parallax;
|
||||||
G_Texture2DRef backdrop_src;
|
G_Texture2DRef backdrop_src;
|
||||||
G_Texture2DRef backdrop_mips[G_MaxMips];
|
G_Texture2DRef backdrop_chain;
|
||||||
|
|
||||||
G_Texture2DRef screen;
|
G_Texture2DRef screen;
|
||||||
G_Texture2DRef shade;
|
G_Texture2DRef shade;
|
||||||
G_Texture2DRef albedo;
|
G_Texture2DRef albedo;
|
||||||
|
|
||||||
G_Texture2DRef bloom_mips[G_MaxMips];
|
G_Texture2DRef bloom_chain;
|
||||||
|
|
||||||
u32 emitters_count;
|
u32 emitters_count;
|
||||||
G_StructuredBufferRef emitters;
|
G_StructuredBufferRef emitters;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Constant types
|
//~ Constant types
|
||||||
|
|
||||||
G_DeclConstant(G_StructuredBufferRef, UI_GpuConst_Params, 0);
|
G_DeclConstant(G_SamplerRef, UI_GpuConst_Params, 0);
|
||||||
G_DeclConstant(b32, UI_GpuConst_DebugDraw, 1);
|
G_DeclConstant(b32, UI_GpuConst_DebugDraw, 1);
|
||||||
|
|
||||||
Struct(UI_GpuParams)
|
Struct(UI_GpuParams)
|
||||||
@ -13,7 +13,7 @@ Struct(UI_GpuParams)
|
|||||||
|
|
||||||
Vec2 cursor_pos;
|
Vec2 cursor_pos;
|
||||||
|
|
||||||
G_StructuredBufferRef rects;
|
G_SamplerRef rects;
|
||||||
G_SamplerStateRef sampler;
|
G_SamplerStateRef sampler;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user