Skip to content

Commit

Permalink
Add fences
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Dec 1, 2024
1 parent c3ff68b commit 2fc8123
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ void kope_d3d12_descriptor_set_prepare_uav_texture(kope_g5_command_list *list, c
barrier.Transition.StateBefore =
(D3D12_RESOURCE_STATES)
texture_view->texture->d3d12.resource_states[kope_d3d12_texture_resource_state_index(texture_view->texture, texture_view->base_mip_level, 0)];
if (list->d3d12.list_type == D3D12_COMMAND_LIST_TYPE_COMPUTE && barrier.Transition.StateBefore == D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE) {
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COMMON;
}
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
barrier.Transition.Subresource = D3D12CalcSubresource(texture_view->base_mip_level, 0, 0, texture_view->texture->d3d12.mip_level_count,
texture_view->texture->d3d12.depth_or_array_layers);
Expand Down
33 changes: 33 additions & 0 deletions Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ static D3D12_COMMAND_LIST_TYPE convert_command_list_type(kope_g5_command_list_ty
case KOPE_G5_COMMAND_LIST_TYPE_COPY:
return D3D12_COMMAND_LIST_TYPE_COPY;
}
return D3D12_COMMAND_LIST_TYPE_DIRECT;
}

void kope_d3d12_device_create_command_list(kope_g5_device *device, kope_g5_command_list_type type, kope_g5_command_list *list) {
Expand Down Expand Up @@ -881,3 +882,35 @@ void kope_d3d12_device_create_query_set(kope_g5_device *device, const kope_g5_qu
uint32_t kope_d3d12_device_align_texture_row_bytes(kope_g5_device *device, uint32_t row_bytes) {
return (uint32_t)align_pow2((int)row_bytes, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
}

void kope_d3d12_device_create_fence(kope_g5_device *device, kope_g5_fence *fence) {
device->d3d12.device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_GRAPHICS_PPV_ARGS(&fence->d3d12.fence));
}

void kope_d3d12_device_signal(kope_g5_device *device, kope_g5_command_list_type list_type, kope_g5_fence *fence, uint64_t value) {
switch (list_type) {
case KOPE_G5_COMMAND_LIST_TYPE_GRAPHICS:
device->d3d12.queue->Signal(fence->d3d12.fence, value);
break;
case KOPE_G5_COMMAND_LIST_TYPE_ASYNC:
device->d3d12.async_queue->Signal(fence->d3d12.fence, value);
break;
case KOPE_G5_COMMAND_LIST_TYPE_COPY:
device->d3d12.copy_queue->Signal(fence->d3d12.fence, value);
break;
}
}

void kope_d3d12_device_wait(kope_g5_device *device, kope_g5_command_list_type list_type, kope_g5_fence *fence, uint64_t value) {
switch (list_type) {
case KOPE_G5_COMMAND_LIST_TYPE_GRAPHICS:
device->d3d12.queue->Wait(fence->d3d12.fence, value);
break;
case KOPE_G5_COMMAND_LIST_TYPE_ASYNC:
device->d3d12.async_queue->Wait(fence->d3d12.fence, value);
break;
case KOPE_G5_COMMAND_LIST_TYPE_COPY:
device->d3d12.copy_queue->Wait(fence->d3d12.fence, value);
break;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ void kope_d3d12_device_create_raytracing_hierarchy(kope_g5_device *device, kope_

void kope_d3d12_device_create_query_set(kope_g5_device *device, const kope_g5_query_set_parameters *parameters, kope_g5_query_set *query_set);

void kope_d3d12_device_create_fence(kope_g5_device *device, kope_g5_fence *fence);

uint32_t kope_d3d12_device_align_texture_row_bytes(kope_g5_device *device, uint32_t row_bytes);

void kope_d3d12_device_signal(kope_g5_device *device, kope_g5_command_list_type list_type, kope_g5_fence *fence, uint64_t value);

void kope_d3d12_device_wait(kope_g5_device *device, kope_g5_command_list_type list_type, kope_g5_fence *fence, uint64_t value);

#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "fence_functions.h"

#include <kope/graphics5/fence.h>

#include <kinc/backend/SystemMicrosoft.h>

void kope_d3d12_fence_destroy(kope_g5_fence *fence) {
fence->d3d12.fence->Release();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef KOPE_D3D12_FENCE_FUNCTIONS_HEADER
#define KOPE_D3D12_FENCE_FUNCTIONS_HEADER

#include <kope/graphics5/fence.h>

#ifdef __cplusplus
extern "C" {
#endif

void kope_d3d12_fence_destroy(kope_g5_fence *fence);

#ifdef __cplusplus
}
#endif

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef KOPE_D3D12_FENCE_STRUCTS_HEADER
#define KOPE_D3D12_FENCE_STRUCTS_HEADER

#include <kope/graphics5/buffer.h>

#ifdef __cplusplus
extern "C" {
#endif

struct ID3D12Fence;

typedef struct kope_d3d12_fence {
struct ID3D12Fence *fence;
} kope_d3d12_fence;

#ifdef __cplusplus
}
#endif

#endif
12 changes: 12 additions & 0 deletions Sources/kope/graphics5/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ void kope_g5_device_create_query_set(kope_g5_device *device, const kope_g5_query
KOPE_G5_CALL3(device_create_query_set, device, parameters, query_set);
}

void kope_g5_device_create_fence(kope_g5_device *device, kope_g5_fence *fence) {
KOPE_G5_CALL2(device_create_fence, device, fence);
}

void kope_g5_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list) {
KOPE_G5_CALL2(device_execute_command_list, device, list);
}
Expand All @@ -77,3 +81,11 @@ void kope_g5_device_wait_until_idle(kope_g5_device *device) {
uint32_t kope_g5_device_align_texture_row_bytes(kope_g5_device *device, uint32_t row_bytes) {
return KOPE_G5_CALL2(device_align_texture_row_bytes, device, row_bytes);
}

void kope_g5_device_signal(kope_g5_device *device, kope_g5_command_list_type list_type, kope_g5_fence *fence, uint64_t value) {
KOPE_G5_CALL4(device_signal, device, list_type, fence, value);
}

void kope_g5_device_wait(kope_g5_device *device, kope_g5_command_list_type list_type, kope_g5_fence *fence, uint64_t value) {
KOPE_G5_CALL4(device_wait, device, list_type, fence, value);
}
7 changes: 7 additions & 0 deletions Sources/kope/graphics5/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "api.h"
#include "buffer.h"
#include "commandlist.h"
#include "fence.h"
#include "sampler.h"
#include "textureformat.h"

Expand Down Expand Up @@ -138,6 +139,8 @@ typedef struct kope_g5_query_set_parameters {

KOPE_FUNC void kope_g5_device_create_query_set(kope_g5_device *device, const kope_g5_query_set_parameters *parameters, kope_g5_query_set *query_set);

KOPE_FUNC void kope_g5_device_create_fence(kope_g5_device *device, kope_g5_fence *fence);

KOPE_FUNC void kope_g5_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list);

KOPE_FUNC void kope_g5_device_wait_until_idle(kope_g5_device *device);
Expand All @@ -158,6 +161,10 @@ KOPE_FUNC void kope_g5_device_create_raytracing_hierarchy(kope_g5_device *device

KOPE_FUNC uint32_t kope_g5_device_align_texture_row_bytes(kope_g5_device *device, uint32_t row_bytes);

KOPE_FUNC void kope_g5_device_signal(kope_g5_device *device, kope_g5_command_list_type list_type, kope_g5_fence *fence, uint64_t value);

KOPE_FUNC void kope_g5_device_wait(kope_g5_device *device, kope_g5_command_list_type list_type, kope_g5_fence *fence, uint64_t value);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions Sources/kope/graphics5/fence.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "fence.h"

#ifdef KOPE_DIRECT3D12
#include <kope/direct3d12/fence_functions.h>
#endif

void kope_g5_fence_destroy(kope_g5_fence *fence) {
KOPE_G5_CALL1(fence_destroy, fence);
}
26 changes: 26 additions & 0 deletions Sources/kope/graphics5/fence.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef KOPE_G5_FENCE_HEADER
#define KOPE_G5_FENCE_HEADER

#include <kope/global.h>

#include "api.h"

#ifdef KOPE_DIRECT3D12
#include <kope/direct3d12/fence_structs.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef struct kope_g5_fence {
KOPE_G5_IMPL(fence);
} kope_g5_fence;

KOPE_FUNC void kope_g5_fence_destroy(kope_g5_fence *fence);

#ifdef __cplusplus
}
#endif

#endif

0 comments on commit 2fc8123

Please sign in to comment.