create gpu resources with command list. add discard command.
This commit is contained in:
parent
cd48dd53ff
commit
d9898eeab8
@ -69,7 +69,7 @@
|
||||
|
||||
#define FLOOD_DEBUG 0
|
||||
|
||||
#define GPU_DEBUG 1
|
||||
#define GPU_DEBUG 0
|
||||
#define GPU_DEBUG_VALIDATION 0
|
||||
|
||||
#define GPU_SHADER_PRINT 1
|
||||
|
||||
@ -253,128 +253,109 @@ void GC_TickAsync(WaveLaneCtx *lane, AsyncTickCtx *tick)
|
||||
|
||||
WaveSync(lane);
|
||||
|
||||
//////////////////////////////
|
||||
//- Rasterize glyphs
|
||||
|
||||
/* TODO: Process cmds unevenly to account for varying work size */
|
||||
|
||||
if (async->cmds.count > 0)
|
||||
{
|
||||
RngU64 cmd_idxs = WaveIdxRangeFromCount(lane, async->cmds.count);
|
||||
for (u64 cmd_idx = cmd_idxs.min; cmd_idx < cmd_idxs.max; ++cmd_idx)
|
||||
//////////////////////////////
|
||||
//- Rasterize glyphs
|
||||
|
||||
/* TODO: Process cmds unevenly to account for varying work size */
|
||||
|
||||
{
|
||||
GC_Cmd *cmd = &async->cmds.v[cmd_idx];
|
||||
GC_Glyph *glyph = cmd->glyph;
|
||||
ResourceKey resource = glyph->desc.font.r;
|
||||
GC_GlyphDesc desc = glyph->desc;
|
||||
TTF_GlyphResult ttf_result = TTF_RasterizeGlyphFromCodepoint(tick->arena, desc.codepoint, resource, desc.font_size);;
|
||||
glyph->font_size = desc.font_size;
|
||||
glyph->font_ascent = ttf_result.font_ascent;
|
||||
glyph->font_descent = ttf_result.font_descent;
|
||||
glyph->font_cap = ttf_result.font_cap;
|
||||
glyph->advance = ttf_result.advance;
|
||||
glyph->bounds = ttf_result.bounds;
|
||||
cmd->rasterized = ttf_result;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: Only sync first lane? */
|
||||
|
||||
WaveSync(lane);
|
||||
|
||||
////////////////////////////
|
||||
//- Allocate atlas slices
|
||||
|
||||
if (lane->idx == 0)
|
||||
{
|
||||
for (u64 cmd_idx = 0; cmd_idx < async->cmds.count; ++cmd_idx)
|
||||
{
|
||||
GC_Cmd *cmd = &async->cmds.v[cmd_idx];
|
||||
GC_Glyph *glyph = cmd->glyph;
|
||||
GC_GlyphDesc desc = glyph->desc;
|
||||
TTF_GlyphResult ttf_result = cmd->rasterized;
|
||||
|
||||
Vec2I32 image_dims = ttf_result.image_dims;
|
||||
|
||||
/* TODO: Use a more efficient atlas packing algorithm for less wasted space `*/
|
||||
GC_Atlas *atlas = GC.first_atlas;
|
||||
b32 can_use_atlas = 0;
|
||||
Vec2I32 pos_in_atlas = Zi;
|
||||
while (can_use_atlas == 0)
|
||||
RngU64 cmd_idxs = WaveIdxRangeFromCount(lane, async->cmds.count);
|
||||
for (u64 cmd_idx = cmd_idxs.min; cmd_idx < cmd_idxs.max; ++cmd_idx)
|
||||
{
|
||||
/* Create atlas */
|
||||
if (!atlas)
|
||||
{
|
||||
Arena *perm = PermArena();
|
||||
atlas = PushStruct(perm, GC_Atlas);
|
||||
atlas->dims = VEC2I32(1024, 1024);
|
||||
{
|
||||
G_ArenaHandle gpu_perm = G_PermArena();
|
||||
atlas->tex = G_PushTexture2D(
|
||||
gpu_perm,
|
||||
G_Format_R8G8B8A8_Unorm_Srgb,
|
||||
atlas->dims,
|
||||
G_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present,
|
||||
);
|
||||
atlas->tex_ref = G_PushTexture2DRef(gpu_perm, atlas->tex);
|
||||
}
|
||||
SllStackPush(GC.first_atlas, atlas);
|
||||
++GC.atlases_count;
|
||||
}
|
||||
|
||||
/* Determine pos in atlas */
|
||||
pos_in_atlas = atlas->cur_pos;
|
||||
atlas->cur_row_height = MaxI32(atlas->cur_row_height, image_dims.y);
|
||||
if (pos_in_atlas.x + image_dims.x > atlas->dims.x);
|
||||
{
|
||||
atlas->cur_pos.x = 0;
|
||||
atlas->cur_pos.y += atlas->cur_row_height;
|
||||
atlas->cur_row_height = image_dims.y;
|
||||
}
|
||||
atlas->cur_pos.x += image_dims.x;
|
||||
if (atlas->cur_pos.x < atlas->dims.x && atlas->cur_pos.y < atlas->dims.y)
|
||||
{
|
||||
can_use_atlas = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
atlas = 0;
|
||||
}
|
||||
GC_Cmd *cmd = &async->cmds.v[cmd_idx];
|
||||
GC_Glyph *glyph = cmd->glyph;
|
||||
ResourceKey resource = glyph->desc.font.r;
|
||||
GC_GlyphDesc desc = glyph->desc;
|
||||
TTF_GlyphResult ttf_result = TTF_RasterizeGlyphFromCodepoint(tick->arena, desc.codepoint, resource, desc.font_size);;
|
||||
glyph->font_size = desc.font_size;
|
||||
glyph->font_ascent = ttf_result.font_ascent;
|
||||
glyph->font_descent = ttf_result.font_descent;
|
||||
glyph->font_cap = ttf_result.font_cap;
|
||||
glyph->advance = ttf_result.advance;
|
||||
glyph->bounds = ttf_result.bounds;
|
||||
cmd->rasterized = ttf_result;
|
||||
}
|
||||
|
||||
/* Atlas info */
|
||||
glyph->atlas = atlas;
|
||||
glyph->tex_slice = RNG2I32(pos_in_atlas, AddVec2I32(pos_in_atlas, image_dims));
|
||||
glyph->tex_slice_uv.p0.x = (f32)glyph->tex_slice.p0.x / (f32)atlas->dims.x;
|
||||
glyph->tex_slice_uv.p0.y = (f32)glyph->tex_slice.p0.y / (f32)atlas->dims.x;
|
||||
glyph->tex_slice_uv.p1.x = (f32)glyph->tex_slice.p1.x / (f32)atlas->dims.x;
|
||||
glyph->tex_slice_uv.p1.y = (f32)glyph->tex_slice.p1.y / (f32)atlas->dims.x;
|
||||
}
|
||||
}
|
||||
|
||||
WaveSync(lane);
|
||||
/* TODO: Only sync first lane? */
|
||||
|
||||
//////////////////////////////
|
||||
//- Upload glyphs to atlas
|
||||
WaveSync(lane);
|
||||
|
||||
{
|
||||
RngU64 cmd_idxs = WaveIdxRangeFromCount(lane, async->cmds.count);
|
||||
for (u64 cmd_idx = cmd_idxs.min; cmd_idx < cmd_idxs.max; ++cmd_idx)
|
||||
////////////////////////////
|
||||
//- Allocate atlas slices
|
||||
|
||||
if (lane->idx == 0)
|
||||
{
|
||||
GC_Cmd *cmd = &async->cmds.v[cmd_idx];
|
||||
GC_Glyph *glyph = cmd->glyph;
|
||||
ResourceKey resource = glyph->desc.font.r;
|
||||
GC_GlyphDesc desc = glyph->desc;
|
||||
TTF_GlyphResult ttf_result = TTF_RasterizeGlyphFromCodepoint(tick->arena, desc.codepoint, resource, desc.font_size);
|
||||
|
||||
u32 *image_pixels = ttf_result.image_pixels;
|
||||
Vec2I32 image_dims = ttf_result.image_dims;
|
||||
|
||||
i64 completion_target = 0;
|
||||
if (image_dims.x > 0 && image_dims.y > 0)
|
||||
G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_AsyncCopy);
|
||||
for (u64 cmd_idx = 0; cmd_idx < async->cmds.count; ++cmd_idx)
|
||||
{
|
||||
G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_AsyncCopy);
|
||||
{
|
||||
GC_Cmd *cmd = &async->cmds.v[cmd_idx];
|
||||
GC_Glyph *glyph = cmd->glyph;
|
||||
GC_GlyphDesc desc = glyph->desc;
|
||||
TTF_GlyphResult ttf_result = cmd->rasterized;
|
||||
|
||||
Vec2I32 image_dims = ttf_result.image_dims;
|
||||
|
||||
/* TODO: Use a more efficient atlas packing algorithm for less wasted space `*/
|
||||
GC_Atlas *atlas = GC.first_atlas;
|
||||
b32 can_use_atlas = 0;
|
||||
Vec2I32 pos_in_atlas = Zi;
|
||||
while (can_use_atlas == 0)
|
||||
{
|
||||
/* Create atlas */
|
||||
if (!atlas)
|
||||
{
|
||||
Arena *perm = PermArena();
|
||||
atlas = PushStruct(perm, GC_Atlas);
|
||||
atlas->dims = VEC2I32(1024, 1024);
|
||||
{
|
||||
G_ArenaHandle gpu_perm = G_PermArena();
|
||||
atlas->tex = G_PushTexture2D(
|
||||
gpu_perm, cl,
|
||||
G_Format_R8G8B8A8_Unorm_Srgb,
|
||||
atlas->dims,
|
||||
G_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present,
|
||||
);
|
||||
atlas->tex_ref = G_PushTexture2DRef(gpu_perm, atlas->tex);
|
||||
}
|
||||
SllStackPush(GC.first_atlas, atlas);
|
||||
++GC.atlases_count;
|
||||
}
|
||||
|
||||
/* Determine pos in atlas */
|
||||
pos_in_atlas = atlas->cur_pos;
|
||||
atlas->cur_row_height = MaxI32(atlas->cur_row_height, image_dims.y);
|
||||
if (pos_in_atlas.x + image_dims.x > atlas->dims.x);
|
||||
{
|
||||
atlas->cur_pos.x = 0;
|
||||
atlas->cur_pos.y += atlas->cur_row_height;
|
||||
atlas->cur_row_height = image_dims.y;
|
||||
}
|
||||
atlas->cur_pos.x += image_dims.x;
|
||||
if (atlas->cur_pos.x < atlas->dims.x && atlas->cur_pos.y < atlas->dims.y)
|
||||
{
|
||||
can_use_atlas = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
atlas = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Atlas info */
|
||||
glyph->atlas = atlas;
|
||||
glyph->tex_slice = RNG2I32(pos_in_atlas, AddVec2I32(pos_in_atlas, image_dims));
|
||||
glyph->tex_slice_uv.p0.x = (f32)glyph->tex_slice.p0.x / (f32)atlas->dims.x;
|
||||
glyph->tex_slice_uv.p0.y = (f32)glyph->tex_slice.p0.y / (f32)atlas->dims.x;
|
||||
glyph->tex_slice_uv.p1.x = (f32)glyph->tex_slice.p1.x / (f32)atlas->dims.x;
|
||||
glyph->tex_slice_uv.p1.y = (f32)glyph->tex_slice.p1.y / (f32)atlas->dims.x;
|
||||
|
||||
/* Copy to atlas */
|
||||
u32 *image_pixels = ttf_result.image_pixels;
|
||||
if (image_dims.x > 0 && image_dims.y > 0)
|
||||
{
|
||||
G_CopyCpuToTexture(
|
||||
cl,
|
||||
glyph->atlas->tex, VEC3I32(glyph->tex_slice.p0.x, glyph->tex_slice.p0.y, 0),
|
||||
@ -385,15 +366,16 @@ void GC_TickAsync(WaveLaneCtx *lane, AsyncTickCtx *tick)
|
||||
)
|
||||
);
|
||||
}
|
||||
completion_target = G_CommitCommandList(cl);
|
||||
}
|
||||
i64 completion_target = G_CommitCommandList(cl);
|
||||
|
||||
Atomic64Set(&glyph->async_copy_completion_target, completion_target);
|
||||
/* Update completion targets */
|
||||
for (u64 cmd_idx = 0; cmd_idx < async->cmds.count; ++cmd_idx)
|
||||
{
|
||||
GC_Cmd *cmd = &async->cmds.v[cmd_idx];
|
||||
GC_Glyph *glyph = cmd->glyph;
|
||||
Atomic64Set(&glyph->async_copy_completion_target, completion_target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- End tick
|
||||
|
||||
WaveSync(lane);
|
||||
}
|
||||
|
||||
@ -93,12 +93,6 @@ Struct(GC_Run)
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Cmd types
|
||||
|
||||
// Enum(GC_CmdKind)
|
||||
// {
|
||||
// GC_CmdKind_None,
|
||||
// GC_CmdKind_LoadGlyphs
|
||||
// };
|
||||
|
||||
Struct(GC_Cmd)
|
||||
{
|
||||
GC_Glyph *glyph;
|
||||
|
||||
@ -16,14 +16,14 @@ void G_BootstrapCommon(void)
|
||||
{
|
||||
G_ResourceHandle quad_indices = Zi;
|
||||
u16 quad_data[6] = { 0, 1, 2, 0, 2, 3 };
|
||||
quad_indices = G_PushBuffer(gpu_perm, u16, countof(quad_data));
|
||||
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 point sampler */
|
||||
{
|
||||
G_ResourceHandle pt_sampler = G_PushSampler(gpu_perm, .filter = G_Filter_MinMagMipPoint);
|
||||
G_ResourceHandle pt_sampler = G_PushSampler(gpu_perm, cl, .filter = G_Filter_MinMagMipPoint);
|
||||
g->basic_sampler = G_PushSamplerStateRef(gpu_perm, pt_sampler);
|
||||
}
|
||||
|
||||
@ -36,14 +36,18 @@ void G_BootstrapCommon(void)
|
||||
{
|
||||
Panic(Lit("Unexpected noise texture size"));
|
||||
}
|
||||
noise_tex = G_PushTexture3D(gpu_perm,
|
||||
G_Format_R16_Uint,
|
||||
noise_dims,
|
||||
G_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present);
|
||||
G_CopyCpuToTexture(cl,
|
||||
noise_tex, VEC3I32(0, 0, 0),
|
||||
noise_data.text, noise_dims,
|
||||
RNG3I32(VEC3I32(0, 0, 0), noise_dims));
|
||||
noise_tex = G_PushTexture3D(
|
||||
gpu_perm, cl,
|
||||
G_Format_R16_Uint,
|
||||
noise_dims,
|
||||
G_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present
|
||||
);
|
||||
G_CopyCpuToTexture(
|
||||
cl,
|
||||
noise_tex, VEC3I32(0, 0, 0),
|
||||
noise_data.text, noise_dims,
|
||||
RNG3I32(VEC3I32(0, 0, 0), noise_dims)
|
||||
);
|
||||
|
||||
g->basic_noise = G_PushTexture3DRef(gpu_perm, noise_tex);
|
||||
}
|
||||
@ -75,7 +79,7 @@ G_ArenaHandle G_PermArena(void)
|
||||
|
||||
G_ResourceHandle G_PushBufferFromString_(G_ArenaHandle gpu_arena, G_CommandListHandle cl, String src, G_BufferDesc desc)
|
||||
{
|
||||
G_ResourceHandle buffer = G_PushResource(gpu_arena, (G_ResourceDesc) { .kind = G_ResourceKind_Buffer, .buffer = desc });
|
||||
G_ResourceHandle buffer = G_PushResource(gpu_arena, cl, (G_ResourceDesc) { .kind = G_ResourceKind_Buffer, .buffer = desc });
|
||||
G_CopyCpuToBuffer(cl, buffer, 0, src.text, RNGU64(0, src.len));
|
||||
G_MemorySync(
|
||||
cl, buffer,
|
||||
|
||||
@ -524,62 +524,62 @@ void G_ResetArena(G_CommandListHandle cl_handle, G_ArenaHandle arena_handle);
|
||||
|
||||
//- Resource creation
|
||||
|
||||
G_ResourceHandle G_PushResource(G_ArenaHandle arena, G_ResourceDesc desc);
|
||||
G_ResourceHandle G_PushResource(G_ArenaHandle arena, G_CommandListHandle cl, G_ResourceDesc desc);
|
||||
|
||||
#define G_PushBuffer(arena, _type, _count, ...) G_PushResource((arena), \
|
||||
(G_ResourceDesc) { \
|
||||
.kind = G_ResourceKind_Buffer, \
|
||||
.buffer = { \
|
||||
.size = sizeof(_type) * (_count), \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
} \
|
||||
#define G_PushBuffer(arena, cl, _type, _count, ...) G_PushResource((arena), (cl), \
|
||||
(G_ResourceDesc) { \
|
||||
.kind = G_ResourceKind_Buffer, \
|
||||
.buffer = { \
|
||||
.size = sizeof(_type) * (_count), \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
} \
|
||||
)
|
||||
|
||||
#define G_PushTexture1D(arena, _format, _size, _initial_layout, ...) G_PushResource((arena), \
|
||||
(G_ResourceDesc) { \
|
||||
.kind = G_ResourceKind_Texture1D, \
|
||||
.texture = { \
|
||||
.format = (_format), \
|
||||
.dims = VEC3I32((_size), 1, 1), \
|
||||
.initial_layout = (_initial_layout), \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
} \
|
||||
#define G_PushTexture1D(arena, cl, _format, _size, _initial_layout, ...) G_PushResource((arena), (cl), \
|
||||
(G_ResourceDesc) { \
|
||||
.kind = G_ResourceKind_Texture1D, \
|
||||
.texture = { \
|
||||
.format = (_format), \
|
||||
.dims = VEC3I32((_size), 1, 1), \
|
||||
.initial_layout = (_initial_layout), \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
} \
|
||||
)
|
||||
|
||||
#define G_PushTexture2D(arena, _format, _size, _initial_layout, ...) G_PushResource((arena), \
|
||||
(G_ResourceDesc) { \
|
||||
.kind = G_ResourceKind_Texture2D, \
|
||||
.texture = { \
|
||||
.format = (_format), \
|
||||
.dims = VEC3I32((_size).x, (_size).y, 1), \
|
||||
.initial_layout = (_initial_layout), \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
} \
|
||||
#define G_PushTexture2D(arena, cl, _format, _size, _initial_layout, ...) G_PushResource((arena), (cl), \
|
||||
(G_ResourceDesc) { \
|
||||
.kind = G_ResourceKind_Texture2D, \
|
||||
.texture = { \
|
||||
.format = (_format), \
|
||||
.dims = VEC3I32((_size).x, (_size).y, 1), \
|
||||
.initial_layout = (_initial_layout), \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
} \
|
||||
)
|
||||
|
||||
#define G_PushTexture3D(arena, _format, _size, _initial_layout, ...) G_PushResource((arena), \
|
||||
(G_ResourceDesc) { \
|
||||
.kind = G_ResourceKind_Texture3D, \
|
||||
.texture = { \
|
||||
.format = (_format), \
|
||||
.dims = (_size), \
|
||||
.initial_layout = (_initial_layout), \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
} \
|
||||
#define G_PushTexture3D(arena, cl, _format, _size, _initial_layout, ...) G_PushResource((arena), (cl), \
|
||||
(G_ResourceDesc) { \
|
||||
.kind = G_ResourceKind_Texture3D, \
|
||||
.texture = { \
|
||||
.format = (_format), \
|
||||
.dims = (_size), \
|
||||
.initial_layout = (_initial_layout), \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
} \
|
||||
)
|
||||
|
||||
#define G_PushSampler(arena, ...) G_PushResource((arena), \
|
||||
(G_ResourceDesc) { \
|
||||
.kind = G_ResourceKind_Sampler, \
|
||||
.sampler = { \
|
||||
.filter = G_Filter_MinMagMipPoint, \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
} \
|
||||
#define G_PushSampler(arena, cl, ...) G_PushResource((arena), (cl), \
|
||||
(G_ResourceDesc) { \
|
||||
.kind = G_ResourceKind_Sampler, \
|
||||
.sampler = { \
|
||||
.filter = G_Filter_MinMagMipPoint, \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
} \
|
||||
)
|
||||
|
||||
|
||||
@ -753,6 +753,10 @@ void G_Rasterize(G_CommandListHandle cl,
|
||||
|
||||
void G_ClearRenderTarget(G_CommandListHandle cl, G_ResourceHandle render_target, Vec4 color);
|
||||
|
||||
//- Discard
|
||||
|
||||
void G_DiscardRenderTarget(G_CommandListHandle cl, G_ResourceHandle render_target);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookdecl Synchronization
|
||||
|
||||
|
||||
@ -295,26 +295,30 @@ void G_Bootstrap(void)
|
||||
/* Create debug print buffers */
|
||||
if (GPU_SHADER_PRINT)
|
||||
{
|
||||
for (G_QueueKind kind = 0; kind < G_NumQueues; ++kind)
|
||||
for (G_QueueKind queue_kind = 0; queue_kind < G_NumQueues; ++queue_kind)
|
||||
{
|
||||
G_D12_Queue *queue = G_D12_QueueFromKind(kind);
|
||||
if (kind != G_QueueKind_AsyncCopy)
|
||||
G_D12_Queue *queue = G_D12_QueueFromKind(queue_kind);
|
||||
if (queue_kind != G_QueueKind_AsyncCopy)
|
||||
{
|
||||
G_ArenaHandle gpu_perm = G_PermArena();
|
||||
queue->print_buffer_size = GPU_SHADER_PRINT_BUFFER_SIZE;
|
||||
queue->print_buffer = G_PushBuffer(
|
||||
gpu_perm,
|
||||
u8,
|
||||
queue->print_buffer_size,
|
||||
.flags = G_ResourceFlag_AllowShaderReadWrite
|
||||
);
|
||||
queue->print_readback_buffer = G_PushBuffer(
|
||||
gpu_perm,
|
||||
u8,
|
||||
queue->print_buffer_size,
|
||||
.flags = G_ResourceFlag_HostMemory
|
||||
);
|
||||
queue->print_buffer_ref = G_PushRWByteAddressBufferRef(gpu_perm, queue->print_buffer);
|
||||
G_CommandListHandle cl = G_PrepareCommandList(queue_kind);
|
||||
{
|
||||
G_ArenaHandle gpu_perm = G_PermArena();
|
||||
queue->print_buffer_size = GPU_SHADER_PRINT_BUFFER_SIZE;
|
||||
queue->print_buffer = G_PushBuffer(
|
||||
gpu_perm, cl,
|
||||
u8,
|
||||
queue->print_buffer_size,
|
||||
.flags = G_ResourceFlag_AllowShaderReadWrite
|
||||
);
|
||||
queue->print_readback_buffer = G_PushBuffer(
|
||||
gpu_perm, cl,
|
||||
u8,
|
||||
queue->print_buffer_size,
|
||||
.flags = G_ResourceFlag_HostMemory
|
||||
);
|
||||
queue->print_buffer_ref = G_PushRWByteAddressBufferRef(gpu_perm, queue->print_buffer);
|
||||
}
|
||||
G_CommitCommandList(cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -844,10 +848,11 @@ void G_D12_ResetArena(G_D12_CmdList *cl, G_D12_Arena *gpu_arena)
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookimpl Resource
|
||||
|
||||
G_ResourceHandle G_PushResource(G_ArenaHandle arena_handle, G_ResourceDesc desc)
|
||||
G_ResourceHandle G_PushResource(G_ArenaHandle arena_handle, G_CommandListHandle cl_handle, G_ResourceDesc desc)
|
||||
{
|
||||
G_D12_SharedState *g = &G_D12_shared_state;
|
||||
G_D12_Arena *gpu_arena = G_D12_ArenaFromHandle(arena_handle);
|
||||
G_D12_CmdList *cl = G_D12_CmdListFromHandle(cl_handle);
|
||||
G_D12_Resource *resource = 0;
|
||||
HRESULT hr = 0;
|
||||
|
||||
@ -1131,7 +1136,7 @@ G_ResourceHandle G_PushResource(G_ArenaHandle arena_handle, G_ResourceDesc desc)
|
||||
resource->is_texture = 1;
|
||||
resource->texture_format = desc.texture.format;
|
||||
resource->texture_dims = desc.texture.dims;
|
||||
resource->texture_mip_levels = desc.texture.mip_levels;
|
||||
resource->texture_mip_levels = d3d_desc.MipLevels;
|
||||
resource->texture_layout = initial_layout;
|
||||
}
|
||||
|
||||
@ -1607,7 +1612,7 @@ G_D12_StagingRegionNode *G_D12_PushStagingRegion(G_D12_CmdList *cl, u64 size)
|
||||
ring->gpu_arena = G_D12_ArenaFromHandle(gpu_arena_handle);
|
||||
|
||||
G_ResourceHandle resource_handle = G_PushBuffer(
|
||||
gpu_arena_handle,
|
||||
gpu_arena_handle, G_D12_MakeHandle(G_CommandListHandle, cl),
|
||||
u8,
|
||||
new_ring_size,
|
||||
.flags = G_ResourceFlag_HostMemory | G_ResourceFlag_Uncached
|
||||
@ -2321,6 +2326,15 @@ i64 G_CommitCommandList(G_CommandListHandle cl_handle)
|
||||
ID3D12GraphicsCommandList_ClearRenderTargetView(d3d_cl, rtv_handle, clear_color, 0, 0);
|
||||
cmd_idx += 1;
|
||||
} break;
|
||||
|
||||
//- Discard rtv
|
||||
|
||||
case G_D12_CmdKind_DiscardRtv:
|
||||
{
|
||||
G_D12_Resource *resource = cmd->discard_rtv.render_target;
|
||||
ID3D12GraphicsCommandList_DiscardResource(d3d_cl, resource->d3d_resource, 0);
|
||||
cmd_idx += 1;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2652,6 +2666,16 @@ void G_ClearRenderTarget(G_CommandListHandle cl_handle, G_ResourceHandle resourc
|
||||
cmd->clear_rtv.color = color;
|
||||
}
|
||||
|
||||
//- Discard
|
||||
|
||||
void G_DiscardRenderTarget(G_CommandListHandle cl_handle, G_ResourceHandle resource_handle)
|
||||
{
|
||||
G_D12_CmdList *cl = G_D12_CmdListFromHandle(cl_handle);
|
||||
G_D12_Cmd *cmd = G_D12_PushCmd(cl);
|
||||
cmd->kind = G_D12_CmdKind_DiscardRtv;
|
||||
cmd->discard_rtv.render_target = G_D12_ResourceFromHandle(resource_handle);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookimpl Synchronization
|
||||
|
||||
|
||||
@ -291,6 +291,7 @@ Enum(G_D12_CmdKind)
|
||||
G_D12_CmdKind_Compute,
|
||||
G_D12_CmdKind_Rasterize,
|
||||
G_D12_CmdKind_ClearRtv,
|
||||
G_D12_CmdKind_DiscardRtv,
|
||||
};
|
||||
|
||||
Struct(G_D12_Cmd)
|
||||
@ -355,6 +356,11 @@ Struct(G_D12_Cmd)
|
||||
G_D12_Resource *render_target;
|
||||
Vec4 color;
|
||||
} clear_rtv;
|
||||
|
||||
struct
|
||||
{
|
||||
G_D12_Resource *render_target;
|
||||
} discard_rtv;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -53,15 +53,24 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
V.world = PushStruct(V.world_arena, S_World);
|
||||
V.player_key = S_RandKey();
|
||||
|
||||
u8 *tiles = PushBytes(perm, world_size * world_size * 4, alignof(S_TileKind));
|
||||
Vec2I32 tiles_dims = VEC2I32(world_size * 2, world_size * 2);
|
||||
u8 *tiles = PushBytes(perm, tiles_dims.x * tiles_dims.y, alignof(S_TileKind));
|
||||
G_ResourceHandle gpu_tiles = Zi;
|
||||
G_Texture2DRef gpu_tiles_ref = Zi;
|
||||
{
|
||||
G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_Direct);
|
||||
{
|
||||
gpu_tiles = G_PushTexture2D(
|
||||
gpu_perm, cl,
|
||||
G_Format_R8_Uint,
|
||||
tiles_dims,
|
||||
G_Layout_DirectQueue_ShaderRead_ShaderReadWrite_CopyRead_CopyWrite
|
||||
);
|
||||
gpu_tiles_ref = G_PushTexture2DRef(gpu_perm, gpu_tiles);
|
||||
}
|
||||
G_CommitCommandList(cl);
|
||||
}
|
||||
|
||||
G_ResourceHandle gpu_tiles = G_PushTexture2D(
|
||||
gpu_perm,
|
||||
G_Format_R8_Uint,
|
||||
VEC2I32(world_size, world_size),
|
||||
G_Layout_DirectQueue_ShaderRead_ShaderReadWrite_CopyRead_CopyWrite
|
||||
);
|
||||
G_Texture2DRef gpu_tiles_ref = G_PushTexture2DRef(gpu_perm, gpu_tiles);
|
||||
|
||||
for (u32 i = 0; i < countof(V.frames); ++i)
|
||||
{
|
||||
@ -272,7 +281,12 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
}
|
||||
if (is_dirty)
|
||||
{
|
||||
G_CopyCpuToBuffer(frame->cl, gpu_tiles, 0, tiles, RNGU64(0, sizeof(tiles)));
|
||||
G_CopyCpuToTexture(
|
||||
frame->cl,
|
||||
gpu_tiles, VEC3I32(0, 0, 0),
|
||||
tiles, VEC3I32(tiles_dims.x, tiles_dims.y, 1),
|
||||
RNG3I32(VEC3I32(0, 0, 0), VEC3I32(tiles_dims.x, tiles_dims.y, 1))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -788,10 +802,10 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
/* Target */
|
||||
G_ResourceHandle draw_target = G_PushTexture2D(
|
||||
frame->gpu_arena,
|
||||
frame->gpu_arena, frame->cl,
|
||||
G_Format_R16G16B16A16_Float,
|
||||
frame->draw_dims,
|
||||
G_Layout_DirectQueue_ShaderReadWrite,
|
||||
G_Layout_DirectQueue_RenderTargetWrite,
|
||||
.flags = G_ResourceFlag_AllowShaderReadWrite | G_ResourceFlag_AllowRenderTarget
|
||||
);
|
||||
G_Texture2DRef draw_target_ro = G_PushTexture2DRef(frame->gpu_arena, draw_target);
|
||||
@ -839,9 +853,16 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
/* Sync */
|
||||
G_DumbGlobalMemorySync(frame->cl);
|
||||
|
||||
//////////////////////////////
|
||||
//- Discard pass
|
||||
|
||||
G_DiscardRenderTarget(frame->cl, draw_target);
|
||||
|
||||
//////////////////////////////
|
||||
//- Backdrop pass
|
||||
|
||||
G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_ShaderReadWrite);
|
||||
|
||||
/* Backdrop pass */
|
||||
{
|
||||
G_Compute(frame->cl, V_BackdropCS, V_BackdropCSThreadSizeFromTexSize(frame->draw_dims));
|
||||
|
||||
@ -1367,7 +1367,7 @@ void UI_EndFrame(UI_Frame *frame)
|
||||
|
||||
/* Target */
|
||||
G_ResourceHandle draw_target = G_PushTexture2D(
|
||||
frame->gpu_arena,
|
||||
frame->gpu_arena, frame->cl,
|
||||
G_Format_R16G16B16A16_Float,
|
||||
monitor_size,
|
||||
G_Layout_DirectQueue_RenderTargetWrite,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user