remove forced descriptor slot api
This commit is contained in:
parent
f47f7114d0
commit
c7e560f98c
@ -28,7 +28,7 @@ void G_BootstrapCommon(void)
|
||||
/* Init point sampler */
|
||||
{
|
||||
G_ResourceHandle pt_sampler = G_PushSampler(gpu_perm, (G_SamplerResourceDesc) { .filter = G_Filter_MinMagMipPoint });
|
||||
G_PushSamplerStateRef(gpu_perm, pt_sampler, .forced = G_BasicPointSampler.v);
|
||||
g->basic_sampler = G_PushSamplerStateRef(gpu_perm, pt_sampler);
|
||||
}
|
||||
|
||||
/* Init noise texture */
|
||||
@ -49,7 +49,7 @@ void G_BootstrapCommon(void)
|
||||
noise_data.text, noise_dims,
|
||||
RNG3I32(VEC3I32(0, 0, 0), noise_dims));
|
||||
|
||||
G_PushTexture3DRef(gpu_perm, noise_tex, .forced = G_BasicNoiseTexture.v);
|
||||
g->basic_noise = G_PushTexture3DRef(gpu_perm, noise_tex);
|
||||
}
|
||||
|
||||
}
|
||||
@ -104,7 +104,17 @@ Rng2 G_ScissorFromTexture(G_ResourceHandle texture)
|
||||
|
||||
//- Shared resources
|
||||
|
||||
G_IndexBufferDesc G_GetSharedQuadIndices(void)
|
||||
G_IndexBufferDesc G_QuadIndices(void)
|
||||
{
|
||||
return G_shared_util_state.quad_indices;
|
||||
}
|
||||
|
||||
G_SamplerStateRef G_BasicSampler(void)
|
||||
{
|
||||
return G_shared_util_state.basic_sampler;
|
||||
}
|
||||
|
||||
G_Texture3DRef G_BasicNoiseTexture(void)
|
||||
{
|
||||
return G_shared_util_state.basic_noise;
|
||||
}
|
||||
|
||||
@ -5,6 +5,8 @@ Struct(G_SharedUtilState)
|
||||
{
|
||||
/* Common shared resources */
|
||||
G_IndexBufferDesc quad_indices;
|
||||
G_SamplerStateRef basic_sampler;
|
||||
G_Texture3DRef basic_noise;
|
||||
} extern G_shared_util_state;
|
||||
|
||||
extern ThreadLocal G_ArenaHandle G_t_perm_arena;
|
||||
@ -34,4 +36,6 @@ Rng2 G_ScissorFromTexture(G_ResourceHandle texture);
|
||||
|
||||
//- Shared resources
|
||||
|
||||
G_IndexBufferDesc G_GetSharedQuadIndices(void);
|
||||
G_IndexBufferDesc G_QuadIndices(void);
|
||||
G_SamplerStateRef G_BasicSampler(void);
|
||||
G_Texture3DRef G_BasicNoiseTexture(void);
|
||||
|
||||
@ -433,14 +433,6 @@ Struct(G_RefDesc)
|
||||
G_RefKind kind;
|
||||
u64 element_size;
|
||||
u64 element_offset;
|
||||
|
||||
/* If set, then the layer will attempt to allocate the shader-visible
|
||||
* ref in the specified slot. This slot can only be allocated to
|
||||
* once globally. Any subsequent static allocations to the same slot will
|
||||
* cause a panic unless it is freed. 0 will result in a regular
|
||||
* dynamically-chosen slot for the reference.
|
||||
*/
|
||||
u32 forced;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
@ -226,7 +226,7 @@ void G_Bootstrap(void)
|
||||
{
|
||||
/* Push an empty descriptor at index 0, so that a handle with a value of 0 always represents nil */
|
||||
G_D12_Arena *gpu_perm = G_D12_ArenaFromHandle(G_PermArena());
|
||||
G_D12_Descriptor *nil_descriptor = G_D12_PushDescriptor(gpu_perm, kind, 0);
|
||||
G_D12_Descriptor *nil_descriptor = G_D12_PushDescriptor(gpu_perm, kind);
|
||||
Assert(nil_descriptor->index == 0);
|
||||
}
|
||||
|
||||
@ -650,9 +650,9 @@ G_D12_RawCommandList *G_D12_PrepareRawCommandList(G_QueueKind queue_kind)
|
||||
G_D12_Arena *gpu_perm = G_D12_ArenaFromHandle(G_PermArena());
|
||||
for (u32 i = 0; i < countof(cl->rtv_descriptors); ++i)
|
||||
{
|
||||
cl->rtv_descriptors[i] = G_D12_PushDescriptor(gpu_perm, G_D12_DescriptorHeapKind_Rtv, 0);
|
||||
cl->rtv_descriptors[i] = G_D12_PushDescriptor(gpu_perm, G_D12_DescriptorHeapKind_Rtv);
|
||||
}
|
||||
cl->rtv_clear_descriptor = G_D12_PushDescriptor(gpu_perm, G_D12_DescriptorHeapKind_Rtv, 0);
|
||||
cl->rtv_clear_descriptor = G_D12_PushDescriptor(gpu_perm, G_D12_DescriptorHeapKind_Rtv);
|
||||
}
|
||||
}
|
||||
|
||||
@ -751,7 +751,7 @@ G_D12_Descriptor *G_D12_DescriptorFromIndex(G_D12_DescriptorHeapKind heap_kind,
|
||||
return &descriptors[index];
|
||||
}
|
||||
|
||||
G_D12_Descriptor *G_D12_PushDescriptor(G_D12_Arena *gpu_arena, G_D12_DescriptorHeapKind heap_kind, u32 forced)
|
||||
G_D12_Descriptor *G_D12_PushDescriptor(G_D12_Arena *gpu_arena, G_D12_DescriptorHeapKind heap_kind)
|
||||
{
|
||||
G_D12_SharedState *g = &G_D12_shared_state;
|
||||
G_D12_DescriptorHeap *heap = &g->descriptor_heaps[heap_kind];
|
||||
@ -759,8 +759,6 @@ G_D12_Descriptor *G_D12_PushDescriptor(G_D12_Arena *gpu_arena, G_D12_DescriptorH
|
||||
G_D12_Descriptor *descriptor = 0;
|
||||
|
||||
/* Grab completed descriptor from arena */
|
||||
if (forced == 0)
|
||||
{
|
||||
G_D12_DescriptorList *descriptors_by_queue = gpu_arena->committed_descriptors_by_heap_and_queue[heap_kind];
|
||||
for (G_QueueKind queue_kind = 0; !descriptor && queue_kind < G_NumQueues; ++queue_kind)
|
||||
{
|
||||
@ -782,15 +780,12 @@ G_D12_Descriptor *G_D12_PushDescriptor(G_D12_Arena *gpu_arena, G_D12_DescriptorH
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate new descriptor from heap */
|
||||
u32 index = forced;
|
||||
u32 index = 0;
|
||||
if (!descriptor)
|
||||
{
|
||||
Lock lock = LockE(&heap->mutex);
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
if (heap->first_free)
|
||||
{
|
||||
@ -809,57 +804,6 @@ G_D12_Descriptor *G_D12_PushDescriptor(G_D12_Arena *gpu_arena, G_D12_DescriptorH
|
||||
index = descriptors_count;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (index >= heap->max_count)
|
||||
{
|
||||
Panic(Lit("Max descriptors reached in heap"));
|
||||
}
|
||||
|
||||
/* Push descriptors if index slot is past end of heap */
|
||||
u32 descriptors_count = ArenaCount(heap->descriptors_arena, G_D12_Descriptor);
|
||||
if (index >= descriptors_count)
|
||||
{
|
||||
u32 pushed_count = index - descriptors_count + 1;
|
||||
PushStructs(heap->descriptors_arena, G_D12_Descriptor, pushed_count);
|
||||
for (u32 pushed_index = descriptors_count; pushed_index < descriptors_count + pushed_count; ++pushed_index)
|
||||
{
|
||||
G_D12_Descriptor *pushed = &(ArenaFirst(heap->descriptors_arena, G_D12_Descriptor)[pushed_index]);
|
||||
if (pushed_index < index)
|
||||
{
|
||||
pushed->heap = heap;
|
||||
pushed->index = pushed_index;
|
||||
pushed->handle.ptr = heap->start_handle.ptr + (pushed_index * heap->descriptor_size);
|
||||
DllStackPush(heap->first_free, pushed);
|
||||
}
|
||||
else
|
||||
{
|
||||
descriptor = pushed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Search free list for freed descriptor with matching index */
|
||||
if (!descriptor)
|
||||
{
|
||||
for (G_D12_Descriptor *n = heap->first_free; n; n = n->next)
|
||||
{
|
||||
if (n->index == index)
|
||||
{
|
||||
DllStackRemove(heap->first_free, n);
|
||||
descriptor = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!descriptor)
|
||||
{
|
||||
Arena *perm = PermArena();
|
||||
Panic(StringF(perm, "Tried to force push a GPU pointer into slot %F, but a descriptor already exists there (current heap count: %F)", FmtUint(index), FmtUint(ArenaCount(heap->descriptors_arena, G_D12_Descriptor))));
|
||||
}
|
||||
}
|
||||
}
|
||||
Unlock(&lock);
|
||||
}
|
||||
|
||||
@ -1111,7 +1055,7 @@ u32 G_PushRef(G_ArenaHandle arena_handle, G_ResourceHandle resource_handle, G_Re
|
||||
G_D12_Descriptor *descriptor = 0;
|
||||
if (is_buffer)
|
||||
{
|
||||
descriptor = G_D12_PushDescriptor(gpu_arena, G_D12_DescriptorHeapKind_CbvSrvUav, ref_desc.forced);
|
||||
descriptor = G_D12_PushDescriptor(gpu_arena, G_D12_DescriptorHeapKind_CbvSrvUav);
|
||||
u64 num_elements_in_buffer = 0;
|
||||
u64 num_elements_after_offset = 0;
|
||||
if (is_raw)
|
||||
@ -1168,7 +1112,7 @@ u32 G_PushRef(G_ArenaHandle arena_handle, G_ResourceHandle resource_handle, G_Re
|
||||
}
|
||||
else if (is_texture)
|
||||
{
|
||||
descriptor = G_D12_PushDescriptor(gpu_arena, G_D12_DescriptorHeapKind_CbvSrvUav, ref_desc.forced);
|
||||
descriptor = G_D12_PushDescriptor(gpu_arena, G_D12_DescriptorHeapKind_CbvSrvUav);
|
||||
if (is_uav)
|
||||
{
|
||||
ID3D12Device_CreateUnorderedAccessView(g->device, resource->d3d_resource, 0, 0, descriptor->handle);
|
||||
@ -1180,7 +1124,7 @@ u32 G_PushRef(G_ArenaHandle arena_handle, G_ResourceHandle resource_handle, G_Re
|
||||
}
|
||||
else if (is_sampler)
|
||||
{
|
||||
descriptor = G_D12_PushDescriptor(gpu_arena, G_D12_DescriptorHeapKind_Sampler, ref_desc.forced);
|
||||
descriptor = G_D12_PushDescriptor(gpu_arena, G_D12_DescriptorHeapKind_Sampler);
|
||||
G_SamplerResourceDesc sampler_desc = resource->sampler_desc;
|
||||
D3D12_SAMPLER_DESC d3d_desc = ZI;
|
||||
{
|
||||
|
||||
@ -417,7 +417,7 @@ G_D12_Queue *G_D12_QueueFromKind(G_QueueKind kind);
|
||||
//~ Resource helpers
|
||||
|
||||
G_D12_Descriptor *G_D12_DescriptorFromIndex(G_D12_DescriptorHeapKind heap_kind, u32 index);
|
||||
G_D12_Descriptor *G_D12_PushDescriptor(G_D12_Arena *gpu_arena, G_D12_DescriptorHeapKind heap_kind, u32 forced);
|
||||
G_D12_Descriptor *G_D12_PushDescriptor(G_D12_Arena *gpu_arena, G_D12_DescriptorHeapKind heap_kind);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Raw command list
|
||||
|
||||
@ -94,18 +94,6 @@ Struct(G_SamplerStateRef) { u32 v; };
|
||||
template<typename T> Vec3U32 countof(RWTexture3D<T> tex) { Vec3U32 result; tex.GetDimensions(result.x, result.y, result.z); return result; }
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Static refs
|
||||
|
||||
#if IsLanguageC
|
||||
#define G_StaticRef(type, v) ((type) { (v) })
|
||||
#elif IsLanguageG
|
||||
#define G_StaticRef(type, v) (type(v))
|
||||
#endif
|
||||
|
||||
#define G_BasicPointSampler G_StaticRef(G_SamplerStateRef, 1)
|
||||
#define G_BasicNoiseTexture G_StaticRef(G_Texture3DRef, 2)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Reserved constants
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ void PT_RunForever(WaveLaneCtx *lane)
|
||||
G_SetConstant(cl, PT_ShaderConst_TestConst, 3.123);
|
||||
G_SetConstant(cl, PT_ShaderConst_BlitSampler, G_BasicPointSampler);
|
||||
G_SetConstant(cl, PT_ShaderConst_BlitSrc, final_target_rhandle);
|
||||
G_SetConstant(cl, PT_ShaderConst_NoiseTex, G_BasicNoiseTexture);
|
||||
G_SetConstant(cl, PT_ShaderConst_NoiseTex, G_BasicNoiseTexture());
|
||||
}
|
||||
|
||||
/* Test pass */
|
||||
|
||||
@ -1390,6 +1390,7 @@ void UI_EndFrame(UI_Frame *frame)
|
||||
params.target_size = draw_size;
|
||||
params.target_ro = draw_target_ro;
|
||||
params.rects = rects_ro;
|
||||
params.sampler = G_BasicSampler();
|
||||
}
|
||||
G_ResourceHandle params_buff = G_PushBufferFromString(frame->gpu_arena, frame->cl, StringFromStruct(¶ms));
|
||||
G_StructuredBufferRef params_ro = G_PushStructuredBufferRef(frame->gpu_arena, params_buff, UI_DParams);
|
||||
@ -1416,7 +1417,7 @@ void UI_EndFrame(UI_Frame *frame)
|
||||
/* Render rects */
|
||||
G_Rasterize(frame->cl,
|
||||
UI_DRectVS, UI_DRectPS,
|
||||
1, G_GetSharedQuadIndices(),
|
||||
1, G_QuadIndices(),
|
||||
1, &draw_target,
|
||||
draw_viewport, draw_scissor,
|
||||
G_RasterMode_TriangleList);
|
||||
@ -1427,7 +1428,7 @@ void UI_EndFrame(UI_Frame *frame)
|
||||
G_SetConstant(frame->cl, UI_ShaderConst_DebugDraw, 1);
|
||||
G_Rasterize(frame->cl,
|
||||
UI_DRectVS, UI_DRectPS,
|
||||
1, G_GetSharedQuadIndices(),
|
||||
1, G_QuadIndices(),
|
||||
1, &draw_target,
|
||||
draw_viewport, draw_scissor,
|
||||
G_RasterMode_WireTriangleList);
|
||||
@ -1442,7 +1443,7 @@ void UI_EndFrame(UI_Frame *frame)
|
||||
{
|
||||
G_Rasterize(frame->cl,
|
||||
UI_BlitVS, UI_BlitPS,
|
||||
1, G_GetSharedQuadIndices(),
|
||||
1, G_QuadIndices(),
|
||||
1, &backbuffer,
|
||||
draw_viewport, draw_scissor,
|
||||
G_RasterMode_TriangleList);
|
||||
|
||||
@ -9,6 +9,7 @@ Struct(UI_DParams)
|
||||
Vec2I32 target_size;
|
||||
G_Texture2DRef target_ro;
|
||||
G_StructuredBufferRef rects;
|
||||
G_SamplerStateRef sampler;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
@ -33,7 +33,7 @@ PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input)
|
||||
{
|
||||
UI_DParams params = G_StructuredBufferFromRef<UI_DParams>(UI_ShaderConst_Params)[0];
|
||||
StructuredBuffer<UI_DRect> rects = G_StructuredBufferFromRef<UI_DRect>(params.rects);
|
||||
SamplerState sampler = G_SamplerStateFromRef(G_BasicPointSampler);
|
||||
SamplerState sampler = G_SamplerStateFromRef(params.sampler);
|
||||
|
||||
UI_DRect rect = rects[input.rect_idx];
|
||||
|
||||
@ -140,7 +140,7 @@ PixelShader(UI_BlitPS, UI_BlitPSOutput, UI_BlitPSInput input)
|
||||
{
|
||||
UI_DParams params = G_StructuredBufferFromRef<UI_DParams>(UI_ShaderConst_Params)[0];
|
||||
Texture2D<Vec4> tex = G_Texture2DFromRef<Vec4>(params.target_ro);
|
||||
SamplerState sampler = G_SamplerStateFromRef(G_BasicPointSampler);
|
||||
SamplerState sampler = G_SamplerStateFromRef(params.sampler);
|
||||
|
||||
Vec2 uv = input.src_uv;
|
||||
Vec4 result = tex.Sample(sampler, uv);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user