blend state

This commit is contained in:
jacob 2025-06-23 14:39:42 -05:00
parent acc1fd69f1
commit 878ff5cba5

View File

@ -977,12 +977,18 @@ INTERNAL WORK_TASK_FUNC_DEF(pipeline_load_task, load_arg_raw)
.NumElements = 0 .NumElements = 0
}; };
/* Opaque blend state */ /* Blend state */
D3D12_BLEND_DESC blend_desc = { D3D12_BLEND_DESC blend_desc = {
.AlphaToCoverageEnable = FALSE, .AlphaToCoverageEnable = FALSE,
.IndependentBlendEnable = FALSE .IndependentBlendEnable = FALSE
}; };
blend_desc.RenderTarget[0].BlendEnable = FALSE; blend_desc.RenderTarget[0].BlendEnable = TRUE;
blend_desc.RenderTarget[0].SrcBlend = D3D12_BLEND_SRC_ALPHA;
blend_desc.RenderTarget[0].DestBlend = D3D12_BLEND_INV_SRC_ALPHA;
blend_desc.RenderTarget[0].BlendOp = D3D12_BLEND_OP_ADD;
blend_desc.RenderTarget[0].SrcBlendAlpha = D3D12_BLEND_ONE;
blend_desc.RenderTarget[0].DestBlendAlpha = D3D12_BLEND_INV_SRC_ALPHA;
blend_desc.RenderTarget[0].BlendOpAlpha = D3D12_BLEND_OP_ADD;
blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL; blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
/* Disable depth stencil */ /* Disable depth stencil */
@ -1273,7 +1279,9 @@ INTERNAL struct dx12_resource *dx12_resource_alloc(D3D12_HEAP_PROPERTIES heap_pr
} }
MEMZERO_STRUCT(r); MEMZERO_STRUCT(r);
HRESULT hr = ID3D12Device_CreateCommittedResource(G.device, &heap_props, heap_flags, &desc, initial_state, NULL, &IID_ID3D12Resource, (void **)&r->resource); D3D12_CLEAR_VALUE clear_value = { .Format = desc.Format, .Color = { 0 } };
D3D12_CLEAR_VALUE *clear_value_ptr = desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET ? &clear_value : NULL;
HRESULT hr = ID3D12Device_CreateCommittedResource(G.device, &heap_props, heap_flags, &desc, initial_state, clear_value_ptr, &IID_ID3D12Resource, (void **)&r->resource);
if (FAILED(hr)) { if (FAILED(hr)) {
/* TODO: Don't panic */ /* TODO: Don't panic */
sys_panic(LIT("Failed to create resource")); sys_panic(LIT("Failed to create resource"));
@ -2031,7 +2039,7 @@ void gp_dispatch(struct gp_dispatch_params params)
enum D3D12_RESOURCE_STATES old_state = dx12_resource_barrier(cl->cl, target, D3D12_RESOURCE_STATE_RENDER_TARGET); enum D3D12_RESOURCE_STATES old_state = dx12_resource_barrier(cl->cl, target, D3D12_RESOURCE_STATE_RENDER_TARGET);
ID3D12GraphicsCommandList_OMSetRenderTargets(cl->cl, 1, &target->rtv_descriptor->handle, false, NULL); ID3D12GraphicsCommandList_OMSetRenderTargets(cl->cl, 1, &target->rtv_descriptor->handle, false, NULL);
//f32 clear_color[] = { 0.0f, 0.0f, 0.0f, 0.0f }; //f32 clear_color[] = { 0.0f, 0.0f, 0.0f, 0.0f };
//ID3D12GraphicsCommandList_ClearRenderTargetView(cl->cl, rtvHandle, clearColor, 0, nullptr); //ID3D12GraphicsCommandList_ClearRenderTargetView(cl->cl, target->rtv_descriptor->handle, clear_color, 0, NULL);
/* Draw */ /* Draw */
ID3D12GraphicsCommandList_IASetPrimitiveTopology(cl->cl, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); ID3D12GraphicsCommandList_IASetPrimitiveTopology(cl->cl, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
@ -2217,24 +2225,6 @@ void gp_present(struct sys_window *window, struct v2i32 backbuffer_resolution, s
{ {
//sys_sleep(0.1); //sys_sleep(0.1);
#if 0
/* FIXME: Remove this */
static b32 bla = false;
static ID3D12Fence *fence = ZI;
static u64 fence_value = 0;
if (!bla) {
bla = true;
ID3D12Device_CreateFence(G.device, 0, 0, &IID_ID3D12Fence, (void **)&fence);
}
++fence_value;
ID3D12CommandQueue_Signal(G.cq_direct->cq, fence, fence_value);
HANDLE event = CreateEvent(NULL, FALSE, FALSE, NULL);
ID3D12Fence_SetEventOnCompletion(fence, fence_value, event);
WaitForSingleObject(event, INFINITE);
CloseHandle(event);
#endif
struct dx12_resource *backbuffer_resource = update_swapchain(window, backbuffer_resolution); struct dx12_resource *backbuffer_resource = update_swapchain(window, backbuffer_resolution);
struct dx12_resource *texture_resource = handle_get_data(texture, DX12_HANDLE_KIND_RESOURCE); struct dx12_resource *texture_resource = handle_get_data(texture, DX12_HANDLE_KIND_RESOURCE);