diff --git a/src/glyph_cache/glyph_cache.c b/src/glyph_cache/glyph_cache.c index f0de7b5d..e7653b5a 100644 --- a/src/glyph_cache/glyph_cache.c +++ b/src/glyph_cache/glyph_cache.c @@ -312,14 +312,13 @@ void GC_TickAsync(WaveLaneCtx *lane, AsyncFrameLaneCtx *base_async_lane_frame) atlas->dims = VEC2I32(1024, 1024); { G_ArenaHandle gpu_perm = G_PermArena(); - atlas->tex_res = G_PushTexture2D( - gpu_perm, cl, + atlas->tex = G_PushTexture2D( + cl, gpu_perm, + G_TextureLayout_Simultaneous, G_Format_R8G8B8A8_Unorm_Srgb, atlas->dims, - G_Layout_Simultaneous, .name = Lit("Glyph atlas") ); - atlas->tex = G_PushTexture2DRef(gpu_perm, atlas->tex_res); } SllStackPush(GC.first_atlas, atlas); ++GC.atlases_count; @@ -358,7 +357,7 @@ void GC_TickAsync(WaveLaneCtx *lane, AsyncFrameLaneCtx *base_async_lane_frame) { G_CopyCpuToTexture( cl, - glyph->atlas->tex_res, VEC3I32(glyph->atlas_slice.p0.x, glyph->atlas_slice.p0.y, 0), + glyph->atlas->tex, VEC3I32(glyph->atlas_slice.p0.x, glyph->atlas_slice.p0.y, 0), image_pixels, VEC3I32(image_dims.x, image_dims.y, 1), RNG3I32( VEC3I32(0, 0, 0), diff --git a/src/glyph_cache/glyph_cache.h b/src/glyph_cache/glyph_cache.h index be1e9cfb..4f07baa7 100644 --- a/src/glyph_cache/glyph_cache.h +++ b/src/glyph_cache/glyph_cache.h @@ -14,8 +14,7 @@ Struct(GC_Atlas) GC_Atlas *next; Vec2I32 dims; - G_ResourceHandle tex_res; - G_Texture2DRef tex; + G_TextureRef tex; Vec2I32 cur_pos; i32 cur_row_height; }; @@ -68,7 +67,7 @@ Struct(GC_RunRect) f32 baseline_pos; // Horizontal distance from start of baseline f32 advance; - G_Texture2DRef tex; + G_TextureRef tex; Rng2I32 tex_slice; Rng2 tex_slice_uv; }; diff --git a/src/gpu/gpu_common.c b/src/gpu/gpu_common.c index 7436e0ea..025d48aa 100644 --- a/src/gpu/gpu_common.c +++ b/src/gpu/gpu_common.c @@ -34,7 +34,7 @@ void G_BootstrapCommon(void) // Init noise texture { String noise_data = DataFromResource(ResourceKeyFromStore(&G_Resources, Lit("noise_128x128x64_16.dat"))); - Vec3I32 noise_dims = VEC3I32(128, 128, 64); + Vec3I32 noise_dims = G_BasicNoiseDims; if (noise_data.len != noise_dims.x * noise_dims.y * noise_dims.z * 2) { Panic(Lit("Unexpected noise texture size")); diff --git a/src/gpu/gpu_core.h b/src/gpu/gpu_core.h index ff4903aa..29c6500e 100644 --- a/src/gpu/gpu_core.h +++ b/src/gpu/gpu_core.h @@ -399,13 +399,6 @@ Struct(G_RenderTargetDesc) i32 mip; }; -#define G_IB(_count, _buffer) ((G_IndexBufferDesc) { .count = (_count), .buffer = (_buffer), __VA_ARGS__ }) -Struct(G_IndexBufferDesc) -{ - u64 count; - G_BufferRef buffer; -}; - //////////////////////////////////////////////////////////// //~ Statistic types @@ -441,87 +434,81 @@ G_BaseDescriptorIndex G_PushMemory(G_CommandListHandle cl, G_ArenaHandle gpu_are //- Buffer memory -#define G_PushStruct(_cl, _arena, _type, ...) G_PushStructs((_cl), (_arena), (_type), 1, __VA_ARGS__) -#define G_PushStructs(_cl, _arena, _type, _count, ...) ((G_BufferRef) { .v = G_PushMemory((_cl), (_arena), \ - (G_MemoryDesc) { \ - .kind = G_MemoryKind_Buffer, \ - .buffer = { \ - .count = (_count), \ - .stride = sizeof(_type), \ - __VA_ARGS__ \ - } \ - } \ +#define G_PushStruct(_cl, _arena, _type, ...) G_PushStructs((_cl), (_arena), (_type), 1, __VA_ARGS__) +#define G_PushStructFromCpu(_cl, _arena, _src, ...) G_PushStructsFromCpu((_cl), (_arena), (_src), 1, __VA_ARGS__) + +#define G_PushStructs(_cl, _arena, _type, _count, ...) ( \ + (G_BufferRef) { .v = G_PushMemory((_cl), (_arena), (G_MemoryDesc) { \ + .kind = G_MemoryKind_Buffer, \ + .buffer = { \ + .count = (_count), \ + .stride = sizeof(_type), \ + __VA_ARGS__ \ + } \ + } \ )}) -#define G_PushStructFromCpu(_cl, _arena, _src, ...) G_PushStructsFromCpu((_cl), (_arena), (_src), 1, __VA_ARGS__) -#define G_PushStructsFromCpu(_cl, _arena, _src, _count, ...) ((G_BufferRef) { .v = G_PushMemory((_cl), (_arena), \ - (G_MemoryDesc) { \ - .kind = G_MemoryKind_Buffer, \ - .buffer = { \ - .count = (_count), \ - .stride = sizeof(*_src), \ - .cpu_src = (_src), \ - __VA_ARGS__ \ - } \ - } \ +#define G_PushStructsFromCpu(_cl, _arena, _src, _count, ...) ( \ + (G_BufferRef) { .v = G_PushMemory((_cl), (_arena), (G_MemoryDesc) { \ + .kind = G_MemoryKind_Buffer, \ + .buffer = { \ + .count = (_count), \ + .stride = sizeof(*_src), \ + .cpu_src = (_src), \ + __VA_ARGS__ \ + } \ + } \ )}) - //- Texture memory -#define G_PushTexture1D(_cl, _arena, _initial_layout, _format, _dims, ...) ((G_TextureRef) { .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_PushTexture1D(_cl, _arena, _initial_layout, _format, _dims, ...) ( \ + (G_TextureRef) { .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_TextureRef) { .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_PushTexture2D(_cl, _arena, _initial_layout, _format, _dims, ...) ( \ + (G_TextureRef) { .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_TextureRef) { .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__ \ - } \ - } \ +#define G_PushTexture3D(_cl, _arena, _initial_layout, _format, _dims, ...) ( \ + (G_TextureRef) { .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__ \ + } \ + } \ )}) - - - //- Sampler memory -#define G_PushSampler(_cl, _arena, ...) ((G_SamplerRef) { .v = G_PushMemory((_cl), (_arena), \ - (G_MemoryDesc) { \ - .kind = G_MemoryKind_Sampler, \ - .sampler = { \ - .filter = G_Filter_MinMagMipPoint, \ - __VA_ARGS__ \ - } \ - } \ +#define G_PushSampler(_cl, _arena, ...) ( \ + (G_SamplerRef) { .v = G_PushMemory((_cl), (_arena), (G_MemoryDesc) { \ + .kind = G_MemoryKind_Sampler, \ + .sampler = { \ + .filter = G_Filter_MinMagMipPoint, \ + __VA_ARGS__ \ + } \ + } \ )}) //- Count @@ -552,11 +539,11 @@ i64 G_CommitCommandList(G_CommandListHandle cl); void G_SetConstantEx(G_CommandListHandle cl, i32 slot, void *src_32bit, u32 size); -#define G_SetConstant(cl, name, value) do { \ - CAT(__ShaderConstantType_,name) __src; \ - __src.v = value; \ - G_SetConstantEx((cl), (name), &__src, sizeof(__src)); \ - } while (0) +#define G_SetConstant(cl, name, value) do { \ + CAT(__ShaderConstantType_,name) __src; \ + __src.v = value; \ + G_SetConstantEx((cl), (name), &__src, sizeof(__src)); \ +} while (0) //- Barrier @@ -617,11 +604,12 @@ G_QueueCompletions G_CompletionTargetsFromQueues(G_QueueMask queue_mask); void G_QueueSyncEx(G_QueueBarrierDesc desc); -#define G_QueueSync(completion_mask, ...) \ +#define G_QueueSync(completion_mask, ...) ( \ G_QueueSyncEx((G_QueueBarrierDesc) { \ .completions = G_CompletionTargetsFromQueues(completion_mask), \ __VA_ARGS__ \ - }) + }) \ +) #define G_QueueSyncGpu(completion_mask, wait_mask) G_QueueSync((completion_mask), .wait_queues = (wait_mask)) #define G_QueueSyncCpu(completion_mask) G_QueueSync((completion_mask), .wait_cpu = 1); diff --git a/src/gpu/gpu_dx12/gpu_dx12_core.c b/src/gpu/gpu_dx12/gpu_dx12_core.c index d436d5d5..befb180b 100644 --- a/src/gpu/gpu_dx12/gpu_dx12_core.c +++ b/src/gpu/gpu_dx12/gpu_dx12_core.c @@ -1206,9 +1206,7 @@ void G_D12_ReleaseDescriptor(G_D12_Descriptor *descriptor) { G_D12_DescriptorHeap *heap = descriptor->heap; G_D12_DescriptorList *free_descriptors = &heap->free_descriptors_table.descriptors_by_bundle_count[descriptor->bundle_count]; - Atomic64Set(&descriptor->current_resource_ptr, 0); - Lock lock = LockE(&heap->mutex); { DllQueuePush(free_descriptors->first, free_descriptors->last, descriptor); @@ -1460,59 +1458,62 @@ G_BaseDescriptorIndex G_PushMemory(G_CommandListHandle cl_handle, G_ArenaHandle ////////////////////////////// //- Allocate D3D12 resource - if ((is_buffer || is_texture) && !resource->d3d_resource) + if (!can_reuse) { - D3D12_CLEAR_VALUE *clear_value_arg = 0; - if (d3d_desc.Flags & (D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)) + if (is_buffer || is_texture) { - clear_value_arg = &clear_value; - } - - D3D12_BARRIER_LAYOUT d3d_initial_layout = D3D12_BARRIER_LAYOUT_UNDEFINED; - if (is_texture) - { - d3d_initial_layout = D3D12_BARRIER_LAYOUT_COMMON; - if (memory_desc.texture.initial_layout == G_TextureLayout_Family) + D3D12_CLEAR_VALUE *clear_value_arg = 0; + if (d3d_desc.Flags & (D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)) { - switch (queue_kind) + clear_value_arg = &clear_value; + } + + D3D12_BARRIER_LAYOUT d3d_initial_layout = D3D12_BARRIER_LAYOUT_UNDEFINED; + if (is_texture) + { + d3d_initial_layout = D3D12_BARRIER_LAYOUT_COMMON; + if (memory_desc.texture.initial_layout == G_TextureLayout_Family) { - case G_QueueKind_Direct: d3d_initial_layout = D3D12_BARRIER_LAYOUT_DIRECT_QUEUE_COMMON; break; - case G_QueueKind_AsyncCompute: d3d_initial_layout = D3D12_BARRIER_LAYOUT_COMPUTE_QUEUE_COMMON; break; + switch (queue_kind) + { + case G_QueueKind_Direct: d3d_initial_layout = D3D12_BARRIER_LAYOUT_DIRECT_QUEUE_COMMON; break; + case G_QueueKind_AsyncCompute: d3d_initial_layout = D3D12_BARRIER_LAYOUT_COMPUTE_QUEUE_COMMON; break; + } } } - } - HRESULT hr = ID3D12Device10_CreateCommittedResource3( - G_D12.device, - &heap_props, - heap_flags, - &resource->d3d_desc, - d3d_initial_layout, - clear_value_arg, - 0, // pProtectedSession - 0, // NumCastableFormats - 0, // pCastableFormats - &IID_ID3D12Resource, - (void **)&resource->d3d_resource - ); - Atomic64FetchAdd(&G_D12.cumulative_nonreuse_count, 1); - resource->uid = Atomic64FetchAdd(&G_D12.resource_creation_gen.v, d3d_desc.MipLevels); + HRESULT hr = ID3D12Device10_CreateCommittedResource3( + G_D12.device, + &heap_props, + heap_flags, + &resource->d3d_desc, + d3d_initial_layout, + clear_value_arg, + 0, // pProtectedSession + 0, // NumCastableFormats + 0, // pCastableFormats + &IID_ID3D12Resource, + (void **)&resource->d3d_resource + ); + if (!SUCCEEDED(hr)) + { + // TODO: Don't panic + Panic(Lit("Failed to allocate D3D12 resource")); + } - // Queue initial Rtv/Dsv discard - if ( - !AnyBit(flags, G_MemoryFlag_Zero) && - AnyBit(d3d_desc.Flags, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL) - ) - { - G_D12_Cmd *cmd = G_D12_PushCmd(cl); - cmd->kind = G_D12_CmdKind_Discard; - cmd->discard.resource = resource; - } + Atomic64FetchAdd(&G_D12.cumulative_nonreuse_count, 1); + resource->uid = Atomic64FetchAdd(&G_D12.resource_creation_gen.v, d3d_desc.MipLevels); - if (!SUCCEEDED(hr)) - { - // TODO: Don't panic - Panic(Lit("Failed to allocate D3D12 resource")); + // Queue initial Rtv/Dsv discard + if ( + !AnyBit(flags, G_MemoryFlag_Zero) && + AnyBit(d3d_desc.Flags, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL) + ) + { + G_D12_Cmd *cmd = G_D12_PushCmd(cl); + cmd->kind = G_D12_CmdKind_Discard; + cmd->discard.resource = resource; + } } if (is_buffer) @@ -1811,8 +1812,8 @@ G_BaseDescriptorIndex G_PushMemory(G_CommandListHandle cl_handle, G_ArenaHandle if ( - is_texture && can_reuse && + is_texture && memory_desc.texture.initial_layout == G_TextureLayout_Common && queue_kind != G_QueueKind_AsyncCopy ) @@ -1821,6 +1822,13 @@ G_BaseDescriptorIndex G_PushMemory(G_CommandListHandle cl_handle, G_ArenaHandle } + + + + + + + ////////////////////////////// //- Upload initial data diff --git a/src/gpu/gpu_shared.cgh b/src/gpu/gpu_shared.cgh index 8e3fed34..5c867925 100644 --- a/src/gpu/gpu_shared.cgh +++ b/src/gpu/gpu_shared.cgh @@ -76,21 +76,25 @@ Enum(G_BasicSamplerKind) G_BasicSamplerKind_COUNT }; +//////////////////////////////////////////////////////////// +//~ Basic noise + +#define G_BasicNoiseDims VEC3I32(128, 128, 64) + +//////////////////////////////////////////////////////////// +//~ Index buffers + +#define G_IB(_count, _buffer) ((G_IndexBufferDesc) { .count = (_count), .buffer = (_buffer), __VA_ARGS__ }) +Struct(G_IndexBufferDesc) +{ + u64 count; + G_BufferRef buffer; +}; + //////////////////////////////////////////////////////////// //~ Resource dereference #if IsGpu - // NOTE: Uniform dereferencing is faster than Non-Uniform on AMD hardware - - - - - - - - - - //- Scalar/Uniform dereference (faster on AMD hardware) template StructuredBuffer G_UniformDeref(G_BufferRef r) { return ResourceDescriptorHeap[r.v + 0]; } template RWStructuredBuffer G_UniformDerefRW(G_BufferRef r) { return ResourceDescriptorHeap[r.v + 1]; } @@ -116,36 +120,6 @@ Enum(G_BasicSamplerKind) template RWTexture2D G_DynamicDerefRW2D(G_TextureRef r, u32 mip=0) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + (mip * 2) + 1)]; } template RWTexture3D G_DynamicDerefRW3D(G_TextureRef r, u32 mip=0) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + (mip * 2) + 1)]; } SamplerState G_DynamicDeref(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 StructuredBuffer G_SDeref(G_BufferRef r) { return ResourceDescriptorHeap[r.v + 0]; } - // template RWStructuredBuffer G_SDerefRW(G_BufferRef r) { return ResourceDescriptorHeap[r.v + 1]; } - // template Texture1D G_SDeref(G_Texture1DRef r) { return ResourceDescriptorHeap[r.v + 0]; } - // template Texture2D G_SDeref(G_Texture2DRef r) { return ResourceDescriptorHeap[r.v + 0]; } - // template Texture3D G_SDeref(G_Texture3DRef r) { return ResourceDescriptorHeap[r.v + 0]; } - // template RWTexture1D G_SDerefRW(G_Texture1DRef r) { return ResourceDescriptorHeap[r.v + 1]; } - // template RWTexture2D G_SDerefRW(G_Texture2DRef r) { return ResourceDescriptorHeap[r.v + 1]; } - // template RWTexture3D 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 StructuredBuffer G_VDeref(G_BufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 0)]; } - // template RWStructuredBuffer G_VDerefRW(G_BufferRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; } - // template Texture1D G_VDeref(G_Texture1DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 0)]; } - // template Texture2D G_VDeref(G_Texture2DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 0)]; } - // template Texture3D G_VDeref(G_Texture3DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 0)]; } - // template RWTexture1D G_VDerefRW(G_Texture1DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; } - // template RWTexture2D G_VDerefRW(G_Texture2DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; } - // template RWTexture3D G_VDerefRW(G_Texture3DRef r) { return ResourceDescriptorHeap[NonUniformResourceIndex(r.v + 1)]; } - // SamplerState G_VDeref(G_SamplerStateRef r) { return SamplerDescriptorHeap[NonUniformResourceIndex(r.v)]; } #endif //////////////////////////////////////////////////////////// diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index 7dd84fa1..682a4b3d 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -400,95 +400,89 @@ void V_TickForever(WaveLaneCtx *lane) Vec2I32 cells_dims = VEC2I32(P_CellsPitch, P_CellsPitch); //- Init gpu state - G_Texture2DRef gpu_tiles = Zi; - G_StructuredBufferRef gpu_particles = Zi; - G_Texture2DRef gpu_particle_cells[V_ParticleLayer_COUNT]; - G_Texture2DRef gpu_particle_densities[V_ParticleLayer_COUNT]; - G_Texture2DRef gpu_stains = Zi; - G_Texture2DRef gpu_dry_stains = Zi; - G_Texture2DRef gpu_drynesses = Zi; - G_Texture2DRef gpu_occluders = Zi; + G_TextureRef gpu_tiles = Zi; + G_BufferRef gpu_particles = Zi; + G_TextureRef gpu_particle_cells[V_ParticleLayer_COUNT]; + G_TextureRef gpu_particle_densities[V_ParticleLayer_COUNT]; + G_TextureRef gpu_stains = Zi; + G_TextureRef gpu_dry_stains = Zi; + G_TextureRef gpu_drynesses = Zi; + G_TextureRef gpu_occluders = Zi; { G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_Direct); { //- Init tile map texture - gpu_tiles = G_PushTexture2DZero( - cl, - gpu_perm, + gpu_tiles = G_PushTexture2D( + cl, gpu_perm, G_TextureLayout_Family, G_Format_R8_Uint, tiles_dims, + .flags = G_MemoryFlag_Zero, .name = Lit("Tiles") ); //- Init particle buffer - gpu_particles = G_PushBufferZero( - cl, - gpu_perm, - V_Particle, - V_ParticlesCap, + gpu_particles = G_PushStructs( + cl, gpu_perm, + V_Particle, V_ParticlesCap, + .flags = G_MemoryFlag_Zero, .name = Lit("Particles") ); //- Init particle textures for (V_ParticleLayer layer = 0; layer < V_ParticleLayer_COUNT; ++layer) { - gpu_particle_cells[layer] = G_PushTexture2DZero( - cl, - gpu_perm, + gpu_particle_cells[layer] = G_PushTexture2D( + cl, gpu_perm, G_TextureLayout_Family, G_Format_R32_Uint, cells_dims, - .flags = G_TextureFlag_AllowRW, + .flags = G_MemoryFlag_Zero | G_MemoryFlag_AllowTextureRW, .name = StringF(perm, "Particle cells - layer %F", FmtSint(layer)) ); - gpu_particle_densities[layer] = G_PushTexture2DZero( - cl, - gpu_perm, + gpu_particle_densities[layer] = G_PushTexture2D( + cl, gpu_perm, G_TextureLayout_Family, G_Format_R32_Uint, cells_dims, - .flags = G_TextureFlag_AllowRW, + .flags = G_MemoryFlag_Zero | G_MemoryFlag_AllowTextureRW, .name = StringF(perm, "Particle densities - layer %F", FmtSint(layer)) ); } //- Init stains texture - gpu_stains = G_PushTexture2DZero( - cl, - gpu_perm, + gpu_stains = G_PushTexture2D( + cl, gpu_perm, G_TextureLayout_Family, G_Format_R16G16B16A16_Float, cells_dims, - .flags = G_TextureFlag_AllowRW, + .flags = G_MemoryFlag_Zero | G_MemoryFlag_AllowTextureRW, .name = Lit("Stains") ); //- Init dry stains texture - gpu_dry_stains = G_PushTexture2DZero( - gpu_perm, cl, + gpu_dry_stains = G_PushTexture2D( + cl, gpu_perm, G_TextureLayout_Family, G_Format_R16G16B16A16_Float, cells_dims, - .flags = G_TextureFlag_AllowRW, + .flags = G_MemoryFlag_Zero | G_MemoryFlag_AllowTextureRW, .name = Lit("Dry stains") ); //- Init dryness texture - gpu_drynesses = G_PushTexture2DZero( - cl, - gpu_perm, + gpu_drynesses = G_PushTexture2D( + cl, gpu_perm, G_TextureLayout_Family, G_Format_R32_Float, cells_dims, - .flags = G_TextureFlag_AllowRW, + .flags = G_MemoryFlag_Zero | G_MemoryFlag_AllowTextureRW, .name = Lit("Drynesses") ); //- Init occluders texture - gpu_occluders = G_PushTexture2DZero( - cl, - gpu_perm, + gpu_occluders = G_PushTexture2D( + cl, gpu_perm, G_TextureLayout_Family, G_Format_R32_Uint, cells_dims, - .flags = G_TextureFlag_AllowRW, + .flags = G_MemoryFlag_Zero | G_MemoryFlag_AllowTextureRW, .name = Lit("Occluders") ); } @@ -5121,10 +5115,10 @@ void V_TickForever(WaveLaneCtx *lane) // Screen texture frame->screen = G_PushTexture2D( cl, gpu_frame_arena, + G_TextureLayout_Family, G_Format_R16G16B16A16_Float, frame->screen_dims, - G_TextureLayout_Family, - .flags = G_TextureFlag_AllowRW | G_ResourceFlag_AllowRenderTarget, + .flags = G_MemoryFlag_AllowTextureRW | G_MemoryFlag_AllowTextureDraw, .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)); @@ -5133,20 +5127,20 @@ void V_TickForever(WaveLaneCtx *lane) // Albedo texture frame->albedo = G_PushTexture2D( cl, gpu_frame_arena, + G_TextureLayout_Family, G_Format_R16G16B16A16_Float, frame->screen_dims, - G_TextureLayout_Family, - .flags = G_ResourceFlag_AllowRenderTarget, + .flags = G_MemoryFlag_AllowTextureDraw, .name = StringF(frame->arena, "Albedo target [%F]", FmtSint(frame->tick)) ); // Backdrop texture frame->backdrop_chain = G_PushTexture2D( cl, gpu_frame_arena, - G_Format_R16G16B16A16_Float, - G_DimsFromMip2D(G_Count2D(screen_target), 1), G_TextureLayout_Family, - .flags = G_TextureFlag_AllowRW, + G_Format_R16G16B16A16_Float, + G_DimsFromMip2D(G_Count2D(frame->screen), 1), + .flags = G_MemoryFlag_AllowTextureRW, .name = StringF(frame->arena, "Backdrop target [%F]", FmtSint(frame->tick)), .max_mips = 4 ); @@ -5155,10 +5149,10 @@ void V_TickForever(WaveLaneCtx *lane) // TODO: We can re-use backdrop mip chain for this frame->bloom_chain = G_PushTexture2D( cl, gpu_frame_arena, - G_Format_R16G16B16A16_Float, - G_DimsFromMip2D(G_Count2D(screen_target), 1), G_TextureLayout_Family, - .flags = G_TextureFlag_AllowRW, + G_Format_R16G16B16A16_Float, + G_DimsFromMip2D(G_Count2D(frame->screen), 1), + .flags = G_MemoryFlag_AllowTextureRW, .name = StringF(frame->arena, "Bloom target [%F]", FmtSint(frame->tick)), .max_mips = G_MaxMips ); @@ -5169,28 +5163,35 @@ void V_TickForever(WaveLaneCtx *lane) G_TextureLayout_Family, G_Format_R16G16B16A16_Float, frame->shade_dims, - .flags = G_TextureFlag_AllowRW, + .flags = G_MemoryFlag_AllowTextureRW, .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)); Rng2 shade_scissor = RNG2(VEC2(shade_viewport.p0.x, shade_viewport.p0.y), VEC2(shade_viewport.p1.x, shade_viewport.p1.y)); // Quad buffers - frame->quads = G_PushBufferFromCpuArena( + u64 quads_count = ArenaCount(frame->quads_arena, V_Quad); + V_Quad *quads = ArenaFirst(frame->quads_arena, V_Quad); + frame->quads = G_PushStructsFromCpu( cl, gpu_frame_arena, - frame->quads_arena, V_GpuQuad, + quads, quads_count, .name = StringF(frame->arena, "quads [%F]", FmtSint(frame->tick)) ); - // Debug shape buffers - frame->dverts = G_PushBufferFromCpuArena( + // Debug verts + u64 dverts_count = ArenaCount(frame->dverts_arena, V_DVert); + V_DVert *dverts = ArenaFirst(frame->dverts_arena, V_DVert); + frame->dverts = G_PushStructsFromCpu( cl, gpu_frame_arena, - frame->dverts_arena, V_DVert, + dverts, dverts_count, .name = StringF(frame->arena, "dverts [%F]", FmtSint(frame->tick)) ); - frame->dvert_idxs = G_PushBufferFromCpu( + + // Debug vert indices + frame->dvert_idxs.count = ArenaCount(frame->dvert_idxs_arena, u32); + frame->dvert_idxs.buffer = G_PushStructsFromCpu( cl, gpu_frame_arena, - frame->dvert_idxs_arena, u32, + ArenaFirst(frame->dvert_idxs_arena, u32), frame->dvert_idxs.count, .name = StringF(frame->arena, "dvert idxs [%F]", FmtSint(frame->tick)) ); @@ -5207,18 +5208,17 @@ void V_TickForever(WaveLaneCtx *lane) ++emitter_idx; } } - frame->emitters = G_PushBufferFromCpu( + frame->emitters = G_PushStructsFromCpu( cl, gpu_frame_arena, - StringFromStructs(flattened_emitters, frame->emitters_count), + flattened_emitters, frame->emitters_count, .name = StringF(frame->arena, "emitters [%F]", FmtSint(frame->tick)) ); } - frame->emitters = G_PushStructuredBufferRef(gpu_frame_arena, gpu_emitters, V_Emitter); // Upload gpu frame - G_BufferRef gpu_frame = G_PushBufferFromCpu( + G_BufferRef gpu_frame = G_PushStructFromCpu( cl, gpu_frame_arena, - StringFromStruct(&frame->shared_frame), + &frame->shared_frame, .name = StringF(frame->arena, "Gpu frame [%F]", FmtSint(frame->tick)) ); @@ -5226,7 +5226,7 @@ void V_TickForever(WaveLaneCtx *lane) V_GpuFlag gpu_flags = V_GpuFlag_None; G_SetConstant(cl, V_GpuConst_Flags, gpu_flags); G_SetConstant(cl, V_GpuConst_Frame, gpu_frame); - G_SetConstant(cl, V_GpuConst_NoiseTex, G_BasicNoiseTexture()); + G_SetConstant(cl, V_GpuConst_NoiseTex, G_BasicNoise3D()); // Sync G_Sync(cl); @@ -5251,13 +5251,13 @@ void V_TickForever(WaveLaneCtx *lane) // Backdrop passes { - i32 mips_count = G_CountMips(backdrop_target); + i32 mips_count = G_CountMips(frame->backdrop_chain); G_SetConstant(cl, V_GpuConst_MipsCount, mips_count); //- Downsample for (i32 mip_idx = 0; mip_idx < mips_count; ++mip_idx) { - Vec2I32 down_dims = G_DimsFromMip2D(G_Count2D(backdrop_target), mip_idx); + Vec2I32 down_dims = G_DimsFromMip2D(G_Count2D(frame->backdrop_chain), mip_idx); G_SetConstant(cl, V_GpuConst_MipIdx, mip_idx); G_Compute2D(cl, V_BackdropDownCS, down_dims); @@ -5268,7 +5268,7 @@ void V_TickForever(WaveLaneCtx *lane) //- Upsample for (i32 mip_idx = mips_count - 2; mip_idx >= 0; --mip_idx) { - Vec2I32 up_dims = G_DimsFromMip2D(G_Count2D(backdrop_target), mip_idx); + Vec2I32 up_dims = G_DimsFromMip2D(G_Count2D(frame->backdrop_chain), mip_idx); G_SetConstant(cl, V_GpuConst_MipIdx, mip_idx); G_Compute2D(cl, V_BackdropUpCS, up_dims); @@ -5291,8 +5291,8 @@ void V_TickForever(WaveLaneCtx *lane) G_Draw( cl, V_QuadVS, V_QuadPS, - G_CountBuffer(quads_buff, V_Quad), G_QuadIndices(), - 1, &G_Rt(frame->albedo, G_BlendMode_CompositeStraightAlpha), + quads_count, G_QuadIndices(), + 1, &G_RT(frame->albedo, G_BlendMode_CompositeStraightAlpha), screen_viewport, screen_scissor, G_DrawMode_TriangleList ); @@ -5344,7 +5344,7 @@ void V_TickForever(WaveLaneCtx *lane) //- Bloom passes { - i32 mips_count = G_CountMips(bloom_target) + 1; + i32 mips_count = G_CountMips(frame->bloom_chain) + 1; G_SetConstant(cl, V_GpuConst_MipsCount, mips_count); // NOTE: Because bloom mip chain starts at half screen size, mip_idx 0 @@ -5355,7 +5355,7 @@ void V_TickForever(WaveLaneCtx *lane) G_ZoneDF(cl, "Bloom down") for (i32 mip_idx = 1; mip_idx < mips_count; ++mip_idx) { - Vec2I32 down_dims = G_DimsFromMip2D(G_Count2D(screen_target), mip_idx); + Vec2I32 down_dims = G_DimsFromMip2D(G_Count2D(frame->screen), mip_idx); G_SetConstant(cl, V_GpuConst_MipIdx, mip_idx); G_Compute2D(cl, V_BloomDownCS, down_dims); @@ -5367,7 +5367,7 @@ void V_TickForever(WaveLaneCtx *lane) G_ZoneDF(cl, "Bloom up") for (i32 mip_idx = mips_count - 2; mip_idx >= 0; --mip_idx) { - Vec2I32 up_dims = G_DimsFromMip2D(G_Count2D(screen_target), mip_idx); + Vec2I32 up_dims = G_DimsFromMip2D(G_Count2D(frame->screen), mip_idx); G_SetConstant(cl, V_GpuConst_MipIdx, mip_idx); G_Compute2D(cl, V_BloomUpCS, up_dims); @@ -5395,7 +5395,7 @@ void V_TickForever(WaveLaneCtx *lane) cl, V_DVertVS, V_DVertPS, 1, frame->dvert_idxs, - 1, &G_Rt(frame->screen, G_BlendMode_CompositeStraightAlpha), + 1, &G_RT(frame->screen, G_BlendMode_CompositeStraightAlpha), screen_viewport, screen_scissor, G_DrawMode_TriangleList ); diff --git a/src/pp/pp_vis/pp_vis_gpu.g b/src/pp/pp_vis/pp_vis_gpu.g index 3bcae044..a22dd613 100644 --- a/src/pp/pp_vis/pp_vis_gpu.g +++ b/src/pp/pp_vis/pp_vis_gpu.g @@ -3,9 +3,8 @@ f32 V_RandFromPos(Vec3 pos) { - Texture3D noise3d = G_SDeref(V_GpuConst_NoiseTex); - // TODO: Compile-time noise dims - u32 noise = noise3d[(Vec3U32)pos % countof(noise3d)]; + Texture3D noise3d = G_UniformDeref3D(V_GpuConst_NoiseTex); + u32 noise = noise3d[(Vec3U32)pos % G_BasicNoiseDims]; f32 rand = Norm16(noise); return rand; } @@ -58,10 +57,10 @@ Vec4 V_ColorFromParticle(V_ParticleDesc desc, u32 particle_idx, u32 density) //- Prepare shade ComputeShader(V_PrepareShadeCS) { - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - RWTexture2D shade = G_SDerefRW(frame.shade); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + RWTexture2D shade = G_UniformDerefRW2D(frame.shade); Vec2 shade_pos = SV_DispatchThreadID + 0.5; - if (all(shade_pos < countof(shade))) + if (all(shade_pos < G_Count2D(shade))) { // Clear shade shade[shade_pos] = 0; @@ -71,12 +70,12 @@ ComputeShader(V_PrepareShadeCS) //- Prepare cells ComputeShader(V_PrepareCellsCS) { - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - Texture2D tiles = G_SDeref(frame.tiles); - RWTexture2D stains = G_SDerefRW(frame.stains); - RWTexture2D dry_stains = G_SDerefRW(frame.dry_stains); - RWTexture2D drynesses = G_SDerefRW(frame.drynesses); - RWTexture2D occluders = G_SDerefRW(frame.occluders); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + Texture2D tiles = G_UniformDeref2D(frame.tiles); + RWTexture2D stains = G_UniformDerefRW2D(frame.stains); + RWTexture2D dry_stains = G_UniformDerefRW2D(frame.dry_stains); + RWTexture2D drynesses = G_UniformDerefRW2D(frame.drynesses); + RWTexture2D occluders = G_UniformDerefRW2D(frame.occluders); Vec2 cell_pos = SV_DispatchThreadID + 0.5; if (all(cell_pos < P_WorldCellsDims)) @@ -102,8 +101,8 @@ ComputeShader(V_PrepareCellsCS) Vec4 over_dry_stain = 0; for (V_ParticleLayer layer = (V_ParticleLayer)0; layer < V_ParticleLayer_COUNT; layer += (V_ParticleLayer)1) { - RWTexture2D cells = G_VDerefRW(frame.particle_cells[layer]); - RWTexture2D densities = G_VDerefRW(frame.particle_densities[layer]); + RWTexture2D cells = G_DynamicDerefRW2D(frame.particle_cells[layer]); + RWTexture2D densities = G_DynamicDerefRW2D(frame.particle_densities[layer]); u32 packed = cells[cell_pos]; if (packed & (1 << 31)) { @@ -160,8 +159,8 @@ ComputeShader(V_PrepareCellsCS) //- Clear particles ComputeShader(V_ClearParticlesCS) { - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - RWStructuredBuffer particles = G_SDerefRW(frame.particles); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + RWStructuredBuffer particles = G_UniformDerefRW(frame.particles); u32 particle_idx = SV_DispatchThreadID; if (particle_idx < V_ParticlesCap) { @@ -180,22 +179,16 @@ ComputeShader(V_BackdropDownCS) i32 mip_idx = V_GpuConst_MipIdx; b32 is_first_pass = mip_idx == 0; - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - SamplerState sampler = G_SDeref(frame.basic_samplers[G_BasicSamplerKind_BilinearMirror]); - - Texture2D bd_up; - if (is_first_pass) - { - bd_up = G_SDeref(frame.backdrop_src); - } - else - { - bd_up = G_SDeref(frame.backdrop_mips[mip_idx - 1]); - } - RWTexture2D bd_down = G_SDerefRW(frame.backdrop_mips[mip_idx]); - - Vec2 down_dims = countof(bd_down); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + SamplerState sampler = G_UniformDeref(frame.basic_samplers[G_BasicSamplerKind_BilinearMirror]); + Texture2D bd_up = ( + is_first_pass ? + G_UniformDeref2D(frame.backdrop_src) : + G_UniformDeref2D(frame.backdrop_chain, mip_idx - 1) + ); + RWTexture2D bd_down = G_UniformDerefRW2D(frame.backdrop_chain, mip_idx); + Vec2 down_dims = G_Count2D(bd_down); Vec2 bd_pos = SV_DispatchThreadID + 0.5; Vec2 bd_uv = bd_pos / down_dims; Vec2 off_uv = 0.5 / down_dims; @@ -245,13 +238,13 @@ ComputeShader(V_BackdropUpCS) { i32 mip_idx = V_GpuConst_MipIdx; - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - Texture2D bd_down = G_SDeref(frame.backdrop_mips[mip_idx + 1]); - RWTexture2D bd_up = G_SDerefRW(frame.backdrop_mips[mip_idx]); - SamplerState sampler = G_SDeref(frame.basic_samplers[G_BasicSamplerKind_BilinearMirror]); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + Texture2D bd_down = G_UniformDeref2D(frame.backdrop_chain, mip_idx + 1); + RWTexture2D bd_up = G_UniformDerefRW2D(frame.backdrop_chain, mip_idx); + SamplerState sampler = G_UniformDeref(frame.basic_samplers[G_BasicSamplerKind_BilinearMirror]); - Vec2 down_dims = countof(bd_down); - Vec2 up_dims = countof(bd_up); + Vec2 down_dims = G_Count2D(bd_down); + Vec2 up_dims = G_Count2D(bd_up); Vec2 bd_pos = SV_DispatchThreadID + 0.5; Vec2 bd_uv = bd_pos / up_dims; @@ -303,8 +296,8 @@ ComputeShader(V_BackdropUpCS) VertexShader(V_QuadVS, V_QuadPSInput) { - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - StructuredBuffer quads = G_SDeref(frame.quads); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + StructuredBuffer quads = G_UniformDeref(frame.quads); V_Quad quad = quads[SV_InstanceID]; @@ -327,12 +320,12 @@ VertexShader(V_QuadVS, V_QuadPSInput) PixelShader(V_QuadPS, V_QuadPSOutput, V_QuadPSInput input) { - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - SamplerState sampler = G_SDeref(frame.basic_samplers[G_BasicSamplerKind_PointClamp]); - RWTexture2D occluders = G_SDerefRW(frame.occluders); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + SamplerState sampler = G_UniformDeref(frame.basic_samplers[G_BasicSamplerKind_PointClamp]); + RWTexture2D occluders = G_UniformDerefRW2D(frame.occluders); V_Quad quad = input.quad; - Texture2D tex = G_VDeref(quad.tex); + Texture2D tex = G_DynamicDeref2D(quad.tex); Vec2 world_pos = input.world_pos; Vec2 cell_pos = mul(frame.af.world_to_cell, Vec3(world_pos, 1)); @@ -363,9 +356,9 @@ PixelShader(V_QuadPS, V_QuadPSOutput, V_QuadPSInput input) ComputeShader(V_EmitParticlesCS) { - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - StructuredBuffer emitters = G_SDeref(frame.emitters); - RWStructuredBuffer particles = G_SDerefRW(frame.particles); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + StructuredBuffer emitters = G_UniformDeref(frame.emitters); + RWStructuredBuffer particles = G_UniformDerefRW(frame.particles); u32 emitter_idx = SV_DispatchThreadID; if (emitter_idx < frame.emitters_count) @@ -394,10 +387,10 @@ ComputeShader(V_EmitParticlesCS) ComputeShader(V_SimParticlesCS) { - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - Texture2D tiles = G_SDeref(frame.tiles); - RWStructuredBuffer particles = G_SDerefRW(frame.particles); - Texture2D occluders = G_SDeref(frame.occluders); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + Texture2D tiles = G_UniformDeref2D(frame.tiles); + RWStructuredBuffer particles = G_UniformDerefRW(frame.particles); + Texture2D occluders = G_UniformDeref2D(frame.occluders); u32 particle_idx = SV_DispatchThreadID; if (particle_idx < V_ParticlesCap) @@ -422,7 +415,7 @@ ComputeShader(V_SimParticlesCS) if (particle.kind < 0) { u32 emitter_idx = -particle.kind - 1; - V_Emitter emitter = G_SDeref(frame.emitters)[emitter_idx]; + V_Emitter emitter = G_UniformDeref(frame.emitters)[emitter_idx]; f32 initial_angle = lerp(emitter.angle.min, emitter.angle.max, rand_angle); f32 initial_speed = lerp(emitter.speed.min, emitter.speed.max, rand_speed); @@ -437,8 +430,8 @@ ComputeShader(V_SimParticlesCS) if (particle.kind > V_ParticleKind_None && particle.kind < V_ParticleKind_COUNT && !prune) { V_ParticleDesc desc = V_DescFromParticleKind((V_ParticleKind)particle.kind); - RWTexture2D cells = G_VDerefRW(frame.particle_cells[desc.layer]); - RWTexture2D densities = G_VDerefRW(frame.particle_densities[desc.layer]); + RWTexture2D cells = G_DynamicDerefRW2D(frame.particle_cells[desc.layer]); + RWTexture2D densities = G_DynamicDerefRW2D(frame.particle_densities[desc.layer]); u32 packed = 0; packed |= (particle_idx & ((1 >> 24) - 1)) << 0; @@ -671,12 +664,12 @@ ComputeShader(V_SimParticlesCS) ComputeShader(V_ShadeCS) { - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - SamplerState sampler = G_SDeref(frame.basic_samplers[G_BasicSamplerKind_PointClamp]); - Texture2D tiles = G_SDeref(frame.tiles); - Texture2D albedo_tex = G_SDeref(frame.albedo); - RWTexture2D shade_tex = G_SDerefRW(frame.shade); - Texture2D drynesses = G_SDeref(frame.drynesses); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + SamplerState sampler = G_UniformDeref(frame.basic_samplers[G_BasicSamplerKind_PointClamp]); + Texture2D tiles = G_UniformDeref2D(frame.tiles); + Texture2D albedo_tex = G_UniformDeref2D(frame.albedo); + RWTexture2D shade_tex = G_UniformDerefRW2D(frame.shade); + Texture2D drynesses = G_UniformDeref2D(frame.drynesses); Vec2 shade_pos = SV_DispatchThreadID + 0.5; Vec2 world_pos = mul(frame.af.shade_to_world, Vec3(shade_pos, 1)); @@ -696,7 +689,7 @@ ComputeShader(V_ShadeCS) ////////////////////////////// //- Write result - if (all(shade_pos < countof(shade_tex))) + if (all(shade_pos < G_Count2D(shade_tex))) { shade_tex[shade_pos] = result; } @@ -707,18 +700,18 @@ ComputeShader(V_ShadeCS) ComputeShader(V_CompositeCS) { - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - // Texture2D shade_tex = G_SDeref(frame.shade); - SamplerState point_sampler = G_SDeref(frame.basic_samplers[G_BasicSamplerKind_PointClamp]); - SamplerState bilinear_sampler = G_SDeref(frame.basic_samplers[G_BasicSamplerKind_BilinearClamp]); - Texture2D albedo_tex = G_SDeref(frame.albedo); - RWTexture2D screen_tex = G_SDerefRW(frame.screen); - Texture2D stains = G_SDeref(frame.stains); - Texture2D dry_stains = G_SDeref(frame.dry_stains); - Texture2D drynesses = G_SDeref(frame.drynesses); - Texture2D tiles = G_SDeref(frame.tiles); - Texture2D backdrop = G_SDeref(frame.backdrop_mips[0]); - StructuredBuffer particles = G_SDeref(frame.particles); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + // Texture2D shade_tex = G_UniformDeref2D(frame.shade); + SamplerState point_sampler = G_UniformDeref(frame.basic_samplers[G_BasicSamplerKind_PointClamp]); + SamplerState bilinear_sampler = G_UniformDeref(frame.basic_samplers[G_BasicSamplerKind_BilinearClamp]); + Texture2D albedo_tex = G_UniformDeref2D(frame.albedo); + RWTexture2D screen_tex = G_UniformDerefRW2D(frame.screen); + Texture2D stains = G_UniformDeref2D(frame.stains); + Texture2D dry_stains = G_UniformDeref2D(frame.dry_stains); + Texture2D drynesses = G_UniformDeref2D(frame.drynesses); + Texture2D tiles = G_UniformDeref2D(frame.tiles); + Texture2D backdrop = G_UniformDeref2D(frame.backdrop_chain); + StructuredBuffer particles = G_UniformDeref(frame.particles); Vec2 screen_pos = SV_DispatchThreadID + 0.5; Vec2 world_pos = mul(frame.af.screen_to_world, Vec3(screen_pos, 1)); @@ -826,7 +819,7 @@ ComputeShader(V_CompositeCS) else if (tile != P_TileKind_Empty) { V_TileDesc tile_desc = frame.tile_descs[tile]; - Texture2D tile_tex = G_VDeref(tile_desc.tex); + Texture2D tile_tex = G_DynamicDeref2D(tile_desc.tex); Vec2 samp_t = clamp(frac(world_pos), 0.00001, 1.0 - 0.00001); Vec2 samp_uv = lerp(tile_desc.tex_slice_uv.p0, tile_desc.tex_slice_uv.p1, samp_t); tile_color = tile_tex.SampleLevel(point_sampler, samp_uv, 0); @@ -855,8 +848,8 @@ ComputeShader(V_CompositeCS) for (V_ParticleLayer layer = (V_ParticleLayer)0; layer < V_ParticleLayer_COUNT; layer += (V_ParticleLayer)1) { - Texture2D cells = G_SDeref(frame.particle_cells[layer]); - Texture2D densities = G_SDeref(frame.particle_densities[layer]); + Texture2D cells = G_UniformDeref2D(frame.particle_cells[layer]); + Texture2D densities = G_UniformDeref2D(frame.particle_densities[layer]); u32 packed = cells[cell_pos]; V_ParticleKind particle_kind = (V_ParticleKind)((packed >> 24) & 0x7F); if (particle_kind != V_ParticleKind_None) @@ -1109,24 +1102,19 @@ ComputeShader(V_CompositeCS) ComputeShader(V_BloomDownCS) { i32 mip_idx = V_GpuConst_MipIdx; - - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - SamplerState sampler = G_SDeref(frame.basic_samplers[G_BasicSamplerKind_BilinearClamp]); - RWTexture2D bloom_down = G_SDerefRW(frame.bloom_mips[mip_idx - 1]); - - Texture2D bloom_up; b32 is_first_pass = mip_idx == 1; - if (is_first_pass) - { - bloom_up = G_SDeref(frame.screen); - } - else - { - bloom_up = G_SDeref(frame.bloom_mips[mip_idx - 2]); - } - Vec2 down_dims = countof(bloom_down); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + SamplerState sampler = G_UniformDeref(frame.basic_samplers[G_BasicSamplerKind_BilinearClamp]); + RWTexture2D bloom_down = G_UniformDerefRW2D(frame.bloom_chain, mip_idx - 1); + Texture2D bloom_up = ( + is_first_pass ? + G_UniformDeref2D(frame.screen) : + G_UniformDeref2D(frame.bloom_chain, mip_idx - 2) + ); + + Vec2 down_dims = G_Count2D(bloom_down); Vec2 bloom_pos = SV_DispatchThreadID + 0.5; Vec2 bloom_uv = bloom_pos / down_dims; Vec2 off_uv = 0.5 / down_dims; @@ -1185,23 +1173,23 @@ ComputeShader(V_BloomUpCS) { i32 mip_idx = V_GpuConst_MipIdx; - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - SamplerState sampler = G_SDeref(frame.basic_samplers[G_BasicSamplerKind_BilinearClamp]); - Texture2D bloom_down = G_SDeref(frame.bloom_mips[mip_idx]); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + SamplerState sampler = G_UniformDeref(frame.basic_samplers[G_BasicSamplerKind_BilinearClamp]); + Texture2D bloom_down = G_UniformDeref2D(frame.bloom_chain, mip_idx); b32 is_last_pass = mip_idx == 0; RWTexture2D bloom_up; if (is_last_pass) { - bloom_up = G_SDerefRW(frame.screen); + bloom_up = G_UniformDerefRW2D(frame.screen); } else { - bloom_up = G_SDerefRW(frame.bloom_mips[mip_idx - 1]); + bloom_up = G_UniformDerefRW2D(frame.bloom_chain, mip_idx - 1); } - Vec2 down_dims = countof(bloom_down); - Vec2 up_dims = countof(bloom_up); + Vec2 down_dims = G_Count2D(bloom_down); + Vec2 up_dims = G_Count2D(bloom_up); Vec2 bloom_pos = SV_DispatchThreadID + 0.5; Vec2 bloom_uv = bloom_pos / up_dims; @@ -1250,10 +1238,10 @@ ComputeShader(V_BloomUpCS) ComputeShader(V_FinalizeCS) { - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - SamplerState bilinear_sampler = G_SDeref(frame.basic_samplers[G_BasicSamplerKind_BilinearClamp]); - Texture2D bloom_tex = G_SDeref(frame.bloom_mips[0]); - RWTexture2D screen_tex = G_SDerefRW(frame.screen); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + SamplerState bilinear_sampler = G_UniformDeref(frame.basic_samplers[G_BasicSamplerKind_BilinearClamp]); + Texture2D bloom_tex = G_UniformDeref2D(frame.bloom_chain, 0); + RWTexture2D screen_tex = G_UniformDerefRW2D(frame.screen); Vec2 screen_pos = SV_DispatchThreadID + 0.5; b32 is_in_screen = IsInside(screen_pos, frame.screen_dims); @@ -1283,8 +1271,8 @@ ComputeShader(V_FinalizeCS) VertexShader(V_DVertVS, V_DVertPSInput) { - V_SharedFrame frame = G_SDeref(V_GpuConst_Frame)[0]; - StructuredBuffer verts = G_SDeref(frame.dverts); + V_SharedFrame frame = G_UniformDeref(V_GpuConst_Frame)[0]; + StructuredBuffer verts = G_UniformDeref(frame.dverts); V_DVert vert = verts[SV_VertexID]; diff --git a/src/pp/pp_vis/pp_vis_shared.cgh b/src/pp/pp_vis/pp_vis_shared.cgh index 491ac605..64b3830a 100644 --- a/src/pp/pp_vis/pp_vis_shared.cgh +++ b/src/pp/pp_vis/pp_vis_shared.cgh @@ -12,8 +12,8 @@ Enum(V_GpuFlag) }; G_DeclConstant(V_GpuFlag, V_GpuConst_Flags, 0); -G_DeclConstant(G_StructuredBufferRef, V_GpuConst_Frame, 1); -G_DeclConstant(G_Texture3DRef, V_GpuConst_NoiseTex, 2); +G_DeclConstant(G_BufferRef, V_GpuConst_Frame, 1); +G_DeclConstant(G_TextureRef, V_GpuConst_NoiseTex, 2); G_DeclConstant(i32, V_GpuConst_MipsCount, 3); G_DeclConstant(i32, V_GpuConst_MipIdx, 4); @@ -200,7 +200,7 @@ Struct(V_Quad) V_QuadFlag flags; u32 occluder_id; Affine quad_uv_to_world_af; - G_Texture2DRef tex; + G_TextureRef tex; Rng2 tex_slice_uv; }; @@ -218,7 +218,7 @@ Struct(V_DVert) Struct(V_TileDesc) { - G_Texture2DRef tex; + G_TextureRef tex; Rng2 tex_slice_uv; }; @@ -346,32 +346,33 @@ Struct(V_SharedFrame) G_SamplerRef basic_samplers[G_BasicSamplerKind_COUNT]; V_TileDesc tile_descs[P_TileKind_COUNT]; - G_Texture2DRef tiles; + G_TextureRef tiles; f32 backdrop_parallax; - G_Texture2DRef backdrop_src; - G_Texture2DRef backdrop_chain; + G_TextureRef backdrop_src; + G_TextureRef backdrop_chain; - G_Texture2DRef screen; - G_Texture2DRef shade; - G_Texture2DRef albedo; + G_TextureRef screen; + G_TextureRef shade; + G_TextureRef albedo; - G_Texture2DRef bloom_chain; + G_TextureRef bloom_chain; u32 emitters_count; - G_StructuredBufferRef emitters; - G_StructuredBufferRef particles; + G_BufferRef emitters; + G_BufferRef particles; - G_Texture2DRef stains; - G_Texture2DRef dry_stains; - G_Texture2DRef drynesses; - G_Texture2DRef occluders; + G_TextureRef stains; + G_TextureRef dry_stains; + G_TextureRef drynesses; + G_TextureRef occluders; - G_Texture2DRef particle_cells[V_ParticleLayer_COUNT]; - G_Texture2DRef particle_densities[V_ParticleLayer_COUNT]; + G_TextureRef particle_cells[V_ParticleLayer_COUNT]; + G_TextureRef particle_densities[V_ParticleLayer_COUNT]; - G_StructuredBufferRef dverts; - G_StructuredBufferRef quads; + G_IndexBufferDesc dvert_idxs; + G_BufferRef dverts; + G_BufferRef quads; }; //////////////////////////////////////////////////////////// diff --git a/src/sprite/sprite.c b/src/sprite/sprite.c index 74ed7b25..632a4dde 100644 --- a/src/sprite/sprite.c +++ b/src/sprite/sprite.c @@ -5,23 +5,6 @@ SPR_Ctx SPR = Zi; void SPR_Bootstrap(void) { - G_ArenaHandle gpu_perm = G_PermArena(); - G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_Direct); - { - G_ResourceHandle unready_tex_res = G_PushTexture2D( - gpu_perm, cl, - G_Format_R8G8B8A8_Unorm, - VEC2I32(8, 8), - G_Layout_Common, - .flags = G_ResourceFlag_ZeroMemory, - .name = Lit("Sprite unready texture") - ); - SPR.unready_tex = G_PushTexture2DRef(gpu_perm, unready_tex_res); - SPR.unready_tex_dims = Vec2FromVec(G_Count2D(unready_tex_res)); - } - G_CommitCommandList(cl); - G_QueueSync(G_QueueMask_Direct, G_QueueMask_All); - OnAsyncTick(SPR_TickAsync); } @@ -344,9 +327,9 @@ SPR_Sprite SPR_SpriteFromSheetEx(SPR_SheetKey sheet_key, SPR_SpanKey span_key, i } else { - result.tex_dims = SPR.unready_tex_dims; - result.tex = SPR.unready_tex; - result.tex_rect = RNG2(VEC2(0, 0), SPR.unready_tex_dims); + result.tex = G_Blank2D(); + result.tex_dims = Vec2FromVec(G_Count2D(result.tex)); + result.tex_rect = RNG2(VEC2(0, 0), result.tex_dims); } // Fill rays @@ -446,14 +429,13 @@ void SPR_TickAsync(WaveLaneCtx *lane, AsyncFrameLaneCtx *base_async_lane_frame) atlas->dims = Vec2I32FromVec(slice_dims); { G_ArenaHandle gpu_perm = G_PermArena(); - atlas->tex_res = G_PushTexture2D( - gpu_perm, cl, + atlas->tex = G_PushTexture2D( + cl, gpu_perm, + G_TextureLayout_Common, G_Format_R8G8B8A8_Unorm_Srgb, atlas->dims, - G_Layout_Common, .name = Lit("Isolated sprite texture") ); - atlas->tex = G_PushTexture2DRef(gpu_perm, atlas->tex_res); } } else @@ -471,14 +453,13 @@ void SPR_TickAsync(WaveLaneCtx *lane, AsyncFrameLaneCtx *base_async_lane_frame) atlas->dims = VEC2I32(atlas_size, atlas_size); { G_ArenaHandle gpu_perm = G_PermArena(); - atlas->tex_res = G_PushTexture2D( - gpu_perm, cl, + atlas->tex = G_PushTexture2D( + cl, gpu_perm, + G_TextureLayout_Simultaneous, G_Format_R8G8B8A8_Unorm_Srgb, atlas->dims, - G_Layout_Simultaneous, .name = StringF(perm, "Sprite atlas #%F", FmtSint(SPR.atlases_count)) ); - atlas->tex = G_PushTexture2DRef(gpu_perm, atlas->tex_res); } SllStackPush(SPR.first_atlas, atlas); ++SPR.atlases_count; @@ -513,7 +494,7 @@ void SPR_TickAsync(WaveLaneCtx *lane, AsyncFrameLaneCtx *base_async_lane_frame) // Copy to atlas G_CopyCpuToTexture( cl, - atlas->tex_res, VEC3I32(atlas_pos.x, atlas_pos.y, 0), + atlas->tex, VEC3I32(atlas_pos.x, atlas_pos.y, 0), composite.pixels, VEC3I32(slice_dims.x, slice_dims.y, 1), RNG3I32( VEC3I32(0, 0, 0), diff --git a/src/sprite/sprite.h b/src/sprite/sprite.h index 0d88504f..18ba8c0e 100644 --- a/src/sprite/sprite.h +++ b/src/sprite/sprite.h @@ -14,8 +14,7 @@ Struct(SPR_Atlas) { SPR_Atlas *next; Vec2I32 dims; - G_ResourceHandle tex_res; - G_Texture2DRef tex; + G_TextureRef tex; Vec2I32 cur_pos; i32 cur_row_height; }; @@ -65,7 +64,7 @@ Struct(SPR_Sprite) SPR_Ray rays[SPR_RayKind_COUNT]; Vec2 tex_dims; - G_Texture2DRef tex; + G_TextureRef tex; Rng2 tex_rect; b32 matched; @@ -159,9 +158,6 @@ Struct(SPR_Ctx) { SPR_SheetBin sheet_bins[Kibi(16)]; - G_Texture2DRef unready_tex; - Vec2 unready_tex_dims; - i64 atlases_count; SPR_Atlas *first_atlas; diff --git a/src/ui/ui.lay b/src/ui/ui.lay index 5544521e..8350a11c 100644 --- a/src/ui/ui.lay +++ b/src/ui/ui.lay @@ -14,8 +14,6 @@ @VertexShader UI_DRectVS @PixelShader UI_DRectPS -@VertexShader UI_BlitVS -@PixelShader UI_BlitPS ////////////////////////////// //- Api diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 2c9f94f5..2f7ffe02 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -513,7 +513,7 @@ UI_Key UI_BuildBoxEx(UI_Key semantic_key) return key; } -void UI_SetRawTexture(UI_Key key, G_Texture2DRef tex, Rng2 uv) +void UI_SetRawTexture(UI_Key key, G_TextureRef tex, Rng2 uv) { UI_Frame *frame = UI_CurrentFrame(); UI_CmdNode *n = PushStruct(frame->arena, UI_CmdNode); @@ -1524,7 +1524,7 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) ////////////////////////////// //- Render - G_ResourceHandle backbuffer = frame->window_frame.backbuffer; + G_TextureRef draw_target = Zi; { ////////////////////////////// //- Build render data @@ -1703,45 +1703,41 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) ////////////////////////////// //- Upload data to GPU + UI_GpuParams params = Zi; + // Target - G_ResourceHandle draw_target = G_PushTexture2D( - UI.gpu_frame_arena, UI.cl, + draw_target = G_PushTexture2D( + UI.cl, UI.gpu_frame_arena, + G_TextureLayout_Family, G_Format_R16G16B16A16_Float, monitor_size, - G_Layout_Exclusive, - .flags = G_ResourceFlag_AllowRenderTarget, + .flags = G_MemoryFlag_AllowTextureDraw, .name = Lit("UI draw target") ); - G_Texture2DRef draw_target_ro = G_PushTexture2DRef(UI.gpu_frame_arena, draw_target); // Rects + UI_GpuRect *rects = ArenaFirst(frame->rects_arena, UI_GpuRect); u64 rects_count = ArenaCount(frame->rects_arena, UI_GpuRect); - G_ResourceHandle rects_buff = G_PushBufferFromCpuCopy( - UI.gpu_frame_arena, UI.cl, - StringFromArena(frame->rects_arena), + params.rects = G_PushStructsFromCpu( + UI.cl, UI.gpu_frame_arena, + rects, rects_count, .name = Lit("UI rects") ); - G_StructuredBufferRef rects_ro = G_PushStructuredBufferRef(UI.gpu_frame_arena, rects_buff, UI_GpuRect); // Params - UI_GpuParams params = Zi; - { - params.target_size = draw_size; - params.target_ro = draw_target_ro; - params.rects = rects_ro; - params.sampler = G_BasicSamplerFromKind(G_BasicSamplerKind_PointClamp); - params.cursor_pos = frame->cursor_pos; - params.aa = TweakFloat("UI anti-aliasing", 1, 0, 1); - } - G_ResourceHandle params_buff = G_PushBufferFromCpuCopy( - UI.gpu_frame_arena, UI.cl, - StringFromStruct(¶ms), + params.target = draw_target; + params.target_size = draw_size; + params.sampler = G_BasicSamplerFromKind(G_BasicSamplerKind_PointClamp); + params.cursor_pos = frame->cursor_pos; + params.anti_aliasing = TweakFloat("UI anti-aliasing", 1, 0, 1); + G_BufferRef params_buff = G_PushStructFromCpu( + UI.cl, UI.gpu_frame_arena, + ¶ms, .name = Lit("UI gpu params") ); - G_StructuredBufferRef params_ro = G_PushStructuredBufferRef(UI.gpu_frame_arena, params_buff, UI_GpuParams); // Init constants - G_SetConstant(UI.cl, UI_GpuConst_Params, params_ro); + G_SetConstant(UI.cl, UI_GpuConst_Params, params_buff); // Sync G_Sync(UI.cl); @@ -1758,57 +1754,43 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) //- Rect pass - if (rects_count > 0) + // Render rects + G_ZoneDF(UI.cl, "UI rects") { - // Render rects - G_ZoneDF(UI.cl, "UI rects") G_Draw( UI.cl, UI_DRectVS, UI_DRectPS, rects_count, G_QuadIndices(), - 1, &G_Rt(draw_target, G_BlendMode_CompositePremultipliedAlpha), + 1, &G_RT(draw_target, G_BlendMode_CompositePremultipliedAlpha), draw_viewport, draw_scissor, G_DrawMode_TriangleList ); + } - // Render rect wireframes + // Render rect wireframes + if (AnyBit(frame->frame_flags, UI_FrameFlag_Debug)) + { G_ZoneDF(UI.cl, "UI debug rects") - if (AnyBit(frame->frame_flags, UI_FrameFlag_Debug)) { G_SetConstant(UI.cl, UI_GpuConst_DebugDraw, 1); G_Draw( UI.cl, UI_DRectVS, UI_DRectPS, rects_count, G_QuadIndices(), - 1, &G_Rt(draw_target, G_BlendMode_CompositePremultipliedAlpha), + 1, &G_RT(draw_target, G_BlendMode_CompositePremultipliedAlpha), draw_viewport, draw_scissor, G_DrawMode_WireTriangleList ); + G_SetConstant(UI.cl, UI_GpuConst_DebugDraw, 0); } } - - //- Backbuffer blit pass - - G_SyncLayout(UI.cl, backbuffer, G_Layout_Exclusive); - { - G_ZoneDF(UI.cl, "UI blit to backbuffer") - G_Draw( - UI.cl, - UI_BlitVS, UI_BlitPS, - 1, G_QuadIndices(), - 1, &G_Rt(backbuffer, G_BlendMode_Opaque), - monitor_viewport, monitor_scissor, - G_DrawMode_TriangleList - ); - } - G_SyncLayout(UI.cl, backbuffer, G_Layout_Common); } ////////////////////////////// //- End frame G_CommitCommandList(UI.cl); - WND_EndFrame(frame->window_frame, vsync); + WND_EndFrame(frame->window_frame, VEC2I32(0, 0), draw_target, RNG2I32(VEC2I32(0, 0), draw_size), vsync); EndScratch(scratch); } diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 99526e06..9728396a 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -124,7 +124,7 @@ Enum(UI_BoxFlag) X(SpriteSheet, SPR_SheetKey) \ X(SpriteSpan, SPR_SpanKey) \ X(SpriteSeq, i64) \ - X(BackgroundTexture, G_Texture2DRef) \ + X(BackgroundTexture, G_TextureRef) \ X(BackgroundTextureSliceUv, Rng2) \ X(Misc, f64) \ /* --------------------------------------------- */ \ @@ -273,7 +273,7 @@ Struct(UI_Cmd) struct { UI_Key key; - G_Texture2DRef tex; + G_TextureRef tex; Rng2 slice_uv; } set_raw_texture; }; @@ -311,7 +311,7 @@ Struct(UI_Box) //- Cmd data UI_BoxDesc desc; - G_Texture2DRef raw_texture; + G_TextureRef raw_texture; Rng2 raw_texture_slice_uv; GC_Run glyph_run; SPR_Sprite sprite; @@ -379,7 +379,6 @@ Struct(UI_Frame) Arena *rects_arena; WND_Frame window_frame; - G_ResourceHandle backbuffer; // Time i64 tick; @@ -514,7 +513,7 @@ UI_Style UI_PopStyle(UI_StyleDesc desc); UI_Key UI_BuildBoxEx(UI_Key semantic_key); #define UI_BuildBox() UI_BuildBoxEx(UI_NilKey) -void UI_SetRawTexture(UI_Key key, G_Texture2DRef tex, Rng2 uv); +void UI_SetRawTexture(UI_Key key, G_TextureRef tex, Rng2 uv); //////////////////////////////////////////////////////////// //~ Report diff --git a/src/ui/ui_gpu.g b/src/ui/ui_gpu.g index 5f4379be..4c730574 100644 --- a/src/ui/ui_gpu.g +++ b/src/ui/ui_gpu.g @@ -6,8 +6,8 @@ VertexShader(UI_DRectVS, UI_DRectPSInput) { - UI_GpuParams params = G_SDeref(UI_GpuConst_Params)[0]; - StructuredBuffer rects = G_SDeref(params.rects); + UI_GpuParams params = G_UniformDeref(UI_GpuConst_Params)[0]; + StructuredBuffer rects = G_UniformDeref(params.rects); UI_GpuRect rect = rects[SV_InstanceID]; Vec2 rect_uv = RectUvFromIdx(SV_VertexID); @@ -33,8 +33,8 @@ VertexShader(UI_DRectVS, UI_DRectPSInput) PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input) { - UI_GpuParams params = G_SDeref(UI_GpuConst_Params)[0]; - SamplerState sampler = G_SDeref(params.sampler); + UI_GpuParams params = G_UniformDeref(UI_GpuConst_Params)[0]; + SamplerState sampler = G_UniformDeref(params.sampler); UI_GpuRect rect = input.rect; Vec2 rect_uv = input.rect_uv; @@ -73,7 +73,7 @@ PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input) } else { - Texture2D tex = G_VDeref(rect.tex); + Texture2D tex = G_DynamicDeref2D(rect.tex); background_premul = tex.SampleLevel(sampler, input.tex_uv, 0); background_premul.rgb *= background_premul.a; } @@ -93,7 +93,7 @@ PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input) //- Compute anti-aliased border-over-background color Vec4 composite_premul = 0; { - f32 smoothness = rect_dist_fwidth * params.aa * 0.5; + f32 smoothness = rect_dist_fwidth * params.anti_aliasing * 0.5; f32 border_coverage = smoothstep(smoothness, -smoothness, border_dist); composite_premul = lerp(background_premul, border_premul, border_coverage); } @@ -109,36 +109,3 @@ PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input) output.sv_target0 = result; return output; } - -//////////////////////////////////////////////////////////// -//~ Blit - -////////////////////////////// -//- Vertex shader - -VertexShader(UI_BlitVS, UI_BlitPSInput) -{ - Vec2 uv = RectUvFromIdx(SV_VertexID); - UI_BlitPSInput result; - result.sv_position = Vec4(NdcFromUv(uv).xy, 0, 1); - result.src_uv = uv; - - return result; -} - -////////////////////////////// -//- Pixel shader - -PixelShader(UI_BlitPS, UI_BlitPSOutput, UI_BlitPSInput input) -{ - UI_GpuParams params = G_SDeref(UI_GpuConst_Params)[0]; - Texture2D tex = G_SDeref(params.target_ro); - SamplerState sampler = G_SDeref(params.sampler); - - Vec2 uv = input.src_uv; - Vec4 result = tex.Sample(sampler, uv); - - UI_BlitPSOutput output; - output.sv_target0 = result; - return output; -} diff --git a/src/ui/ui_gpu.gh b/src/ui/ui_gpu.gh index cee9843c..1400d698 100644 --- a/src/ui/ui_gpu.gh +++ b/src/ui/ui_gpu.gh @@ -18,27 +18,9 @@ Struct(UI_DRectPSOutput) Vec4 Semantic(sv_target0); }; -//////////////////////////////////////////////////////////// -//~ Blit shader types - -Struct(UI_BlitPSInput) -{ - Vec4 Semantic(sv_position); - Vec2 Semantic(src_uv); -}; - -Struct(UI_BlitPSOutput) -{ - Vec4 Semantic(sv_target0); -}; - //////////////////////////////////////////////////////////// //~ Shaders //- Rects VertexShader(UI_DRectVS, UI_DRectPSInput); PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input); - -//- Blit -VertexShader(UI_BlitVS, UI_BlitPSInput); -PixelShader(UI_BlitPS, UI_BlitPSOutput, UI_BlitPSInput input); diff --git a/src/ui/ui_shared.cgh b/src/ui/ui_shared.cgh index f79f24fd..6a1211f0 100644 --- a/src/ui/ui_shared.cgh +++ b/src/ui/ui_shared.cgh @@ -1,20 +1,20 @@ //////////////////////////////////////////////////////////// //~ Constant types -G_DeclConstant(G_SamplerRef, UI_GpuConst_Params, 0); +G_DeclConstant(G_BufferRef, UI_GpuConst_Params, 0); G_DeclConstant(b32, UI_GpuConst_DebugDraw, 1); Struct(UI_GpuParams) { - f32 aa; + f32 anti_aliasing; Vec2I32 target_size; - G_Texture2DRef target_ro; + G_TextureRef target; Vec2 cursor_pos; - G_SamplerRef rects; - G_SamplerStateRef sampler; + G_BufferRef rects; + G_SamplerRef sampler; }; //////////////////////////////////////////////////////////// @@ -24,7 +24,7 @@ Struct(UI_GpuRect) { Rng2 bounds; - G_Texture2DRef tex; + G_TextureRef tex; Rng2 tex_slice_uv; Vec4 tint_lin;