131 lines
4.5 KiB
C
131 lines
4.5 KiB
C
GPU_SharedUtilState GPU_shared_util_state = ZI;
|
|
ThreadLocal GPU_ArenaHandle GPU_t_perm_arena = ZI;
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Startup
|
|
|
|
void GPU_StartupCommon(void)
|
|
{
|
|
GPU_SharedUtilState *g = &GPU_shared_util_state;
|
|
|
|
GPU_ArenaHandle gpu_perm = GPU_PermArena();
|
|
|
|
/* Init point sampler */
|
|
{
|
|
GPU_ResourceHandle pt_sampler = GPU_PushSampler(gpu_perm, (GPU_SamplerDesc) { .filter = GPU_Filter_MinMagMipPoint });
|
|
g->pt_sampler = GPU_PushSamplerStateHandle(gpu_perm, pt_sampler);
|
|
}
|
|
|
|
GPU_CommandListHandle cl = GPU_PrepareCommandList(GPU_QueueKind_Direct);
|
|
{
|
|
/* Init quad index buffer */
|
|
{
|
|
u16 quad_data[6] = { 0, 1, 2, 0, 2, 3 };
|
|
GPU_ResourceHandle quad_indices = GPU_PushBuffer(gpu_perm, u16, countof(quad_data));
|
|
GPU_CopyCpuToBuffer(cl, quad_indices, 0, quad_data, RNGU64(0, sizeof(quad_data)));
|
|
g->quad_indices.resource = quad_indices;
|
|
g->quad_indices.index_size = sizeof(quad_data[0]);
|
|
g->quad_indices.index_count = countof(quad_data);
|
|
}
|
|
|
|
/* TODO: Init noise texture */
|
|
{
|
|
String noise_data = DataFromResource(ResourceKeyFromStore(&GPU_Resources, Lit("noise_128x128x64_16.dat")));
|
|
Vec3I32 noise_dims = VEC3I32(128, 128, 64);
|
|
if (noise_data.len != noise_dims.x * noise_dims.y * noise_dims.z * 2)
|
|
{
|
|
Panic(Lit("Unexpected noise texture size"));
|
|
}
|
|
GPU_ResourceHandle noise_tex = GPU_PushTexture3D(gpu_perm,
|
|
GPU_Format_R16_Uint,
|
|
noise_dims,
|
|
GPU_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present);
|
|
GPU_CopyCpuToTexture(cl,
|
|
noise_tex, VEC3I32(0, 0, 0),
|
|
noise_data.text, noise_dims,
|
|
RNG3I32(VEC3I32(0, 0, 0), noise_dims));
|
|
g->noise_tex = GPU_PushTexture3DHandle(gpu_perm, noise_tex);
|
|
}
|
|
}
|
|
GPU_CommitCommandList(cl);
|
|
|
|
GPU_SyncAllQueues(GPU_QueueKind_Direct);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GPU_CommandListHandle cl = GPU_PrepareCommandList();
|
|
// {
|
|
// /* Init noise texture */
|
|
// String noise_data = DataFromResource(ResourceKeyFromStore(&GPU_Resources, Lit("noise_128x128x64_16.dat")));
|
|
// Vec3I32 noise_dims = VEC3I32(128, 128, 64);
|
|
// GPU_ResourceHandle noise_tex = ZI;
|
|
// {
|
|
// if (noise_data.len != noise_dims.x * noise_dims.y * noise_dims.z * 2)
|
|
// {
|
|
// Panic(Lit("Unexpected noise texture size"));
|
|
// }
|
|
// noise_tex = GPU_PushTexture3D(gpu_perm, noise_dims, GPU_Format_R16_Uint, GPU_AccessKind_CopyWrite);
|
|
// GPU_CopyResourceFromCpu(cl, noise_tex, noise_data);
|
|
// }
|
|
|
|
// /* Init quad index buffer */
|
|
// GPU_ResourceHandle quad_indices = ZI;
|
|
// {
|
|
// u16 quad_data[6] = { 0, 1, 2, 0, 2, 3 };
|
|
// quad_indices = GPU_PushBuffer(gpu_perm, u16, GPU_AccessKind_CopyWrite);
|
|
// GPU_CopyResourceFromCpu(cl, quad_indices, StringFromArray(quad_data));
|
|
// }
|
|
|
|
// g->noise_tex = GPU_PushTexture3DPtr(gpu_perm, noise_tex);
|
|
// g->quad_indices = GPU_PushIndexBufferPtr(gpu_perm, quad_indices, u16);
|
|
|
|
// /* FIXME: Block other queues until common startup finishes here */
|
|
// GPU_SyncAccess(cl, noise_tex, GPU_AccessKind_AnyRead);
|
|
// GPU_SyncAccess(cl, quad_indices, GPU_AccessKind_AnyRead);
|
|
// }
|
|
// GPU_CommitCommandList(cl, GPU_QueueKind_Direct);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Arena helpers
|
|
|
|
GPU_ArenaHandle GPU_PermArena(void)
|
|
{
|
|
GPU_ArenaHandle perm = GPU_t_perm_arena;
|
|
if (GPU_IsArenaNil(perm))
|
|
{
|
|
GPU_t_perm_arena = GPU_AcquireArena();
|
|
perm = GPU_t_perm_arena;
|
|
}
|
|
return perm;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Cpu -> Gpu copy helpers
|
|
|
|
void GPU_CopyResourceFromCpu(GPU_CommandListHandle cl, GPU_ResourceHandle dst, String src)
|
|
{
|
|
/* TODO */
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Common resource helpers
|
|
|
|
SamplerStateHandle GPU_GetCommonPointSampler(void)
|
|
{
|
|
return GPU_shared_util_state.pt_sampler;
|
|
}
|
|
|
|
GPU_IndexBufferDesc GPU_GetCommonQuadIndices(void)
|
|
{
|
|
return GPU_shared_util_state.quad_indices;
|
|
}
|
|
|
|
Texture3DHandle GPU_GetCommonNoise(void)
|
|
{
|
|
return GPU_shared_util_state.noise_tex;
|
|
}
|