Skip to content

Commit

Permalink
Support more descriptor types
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Sep 10, 2024
1 parent 20cc674 commit bcb31dd
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ void kope_d3d12_command_list_draw_indexed(kope_g5_command_list *list, uint32_t i
}

void kope_d3d12_command_list_set_descriptor_table(kope_g5_command_list *list, uint32_t table_index, kope_d3d12_descriptor_set *set) {
D3D12_GPU_DESCRIPTOR_HANDLE gpu_descriptor = list->d3d12.device->descriptor_heap->GetGPUDescriptorHandleForHeapStart();
gpu_descriptor.ptr += set->allocation.offset * list->d3d12.device->cbv_srv_uav_increment;
list->d3d12.list->SetGraphicsRootDescriptorTable(table_index, gpu_descriptor);
if (set->descriptor_count > 0) {
D3D12_GPU_DESCRIPTOR_HANDLE gpu_descriptor = list->d3d12.device->descriptor_heap->GetGPUDescriptorHandleForHeapStart();
gpu_descriptor.ptr += set->descriptor_allocation.offset * list->d3d12.device->cbv_srv_uav_increment;
list->d3d12.list->SetGraphicsRootDescriptorTable(table_index, gpu_descriptor);
table_index += 1;
}

if (set->sampler_count > 0) {
D3D12_GPU_DESCRIPTOR_HANDLE gpu_descriptor = list->d3d12.device->sampler_heap->GetGPUDescriptorHandleForHeapStart();
gpu_descriptor.ptr += set->sampler_allocation.offset * list->d3d12.device->sampler_increment;
list->d3d12.list->SetGraphicsRootDescriptorTable(table_index, gpu_descriptor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
#include "descriptorset.cpp"
#include "device.cpp"
#include "pipeline.cpp"
#include "sampler.cpp"
#include "texture.cpp"
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,42 @@
#include "descriptorset_structs.h"

void kope_d3d12_descriptor_set_set_buffer_view_cbv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_buffer *buffer, uint32_t index) {
D3D12_CONSTANT_BUFFER_VIEW_DESC desc;
D3D12_CONSTANT_BUFFER_VIEW_DESC desc = {};
desc.BufferLocation = buffer->d3d12.resource->GetGPUVirtualAddress();
desc.SizeInBytes = (UINT)buffer->d3d12.size;

D3D12_CPU_DESCRIPTOR_HANDLE descriptor_handle = device->d3d12.descriptor_heap->GetCPUDescriptorHandleForHeapStart();
descriptor_handle.ptr += (set->allocation.offset + index) * device->d3d12.cbv_srv_uav_increment;
descriptor_handle.ptr += (set->descriptor_allocation.offset + index) * device->d3d12.cbv_srv_uav_increment;
device->d3d12.device->CreateConstantBufferView(&desc, descriptor_handle);
}

void kope_d3d12_descriptor_set_set_texture_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_texture *texture, uint32_t index) {
D3D12_SHADER_RESOURCE_VIEW_DESC desc = {};
desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.Texture2D.MipLevels = 1;
desc.Texture2D.MostDetailedMip = 0;
desc.Texture2D.ResourceMinLODClamp = 0.0f;

D3D12_CPU_DESCRIPTOR_HANDLE descriptor_handle = device->d3d12.descriptor_heap->GetCPUDescriptorHandleForHeapStart();
descriptor_handle.ptr += (set->descriptor_allocation.offset + index) * device->d3d12.cbv_srv_uav_increment;
device->d3d12.device->CreateShaderResourceView(texture->d3d12.resource, &desc, descriptor_handle);
}

void kope_d3d12_descriptor_set_set_sampler(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_sampler *sampler, uint32_t index) {
D3D12_SAMPLER_DESC desc = {};
desc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
desc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
desc.MinLOD = 0.0f;
desc.MaxLOD = 1.0f;
desc.MipLODBias = 0.0f;
desc.MaxAnisotropy = 1;
desc.ComparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL;

D3D12_CPU_DESCRIPTOR_HANDLE descriptor_handle = device->d3d12.sampler_heap->GetCPUDescriptorHandleForHeapStart();
descriptor_handle.ptr += (set->sampler_allocation.offset + index) * device->d3d12.sampler_increment;
device->d3d12.device->CreateSampler(&desc, descriptor_handle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
#include "descriptorset_structs.h"
#include "device_structs.h"

#include <kope/graphics5/sampler.h>

#ifdef __cplusplus
extern "C" {
#endif

void kope_d3d12_descriptor_set_set_buffer_view_cbv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_buffer *buffer, uint32_t index);
void kope_d3d12_descriptor_set_set_texture_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_texture *texture, uint32_t index);
void kope_d3d12_descriptor_set_set_sampler(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_sampler *sampler, uint32_t index);

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ extern "C" {
#endif

typedef struct kope_d3d12_descriptor_set {
oa_allocation_t allocation;
oa_allocation_t descriptor_allocation;
size_t descriptor_count;

oa_allocation_t sampler_allocation;
size_t sampler_count;
} kope_d3d12_descriptor_set;

#ifdef __cplusplus
Expand Down
11 changes: 9 additions & 2 deletions Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,14 @@ void kope_d3d12_device_execute_command_list(kope_g5_device *device, kope_g5_comm
}
}

void kope_d3d12_device_create_descriptor_set(kope_g5_device *device, uint32_t descriptor_count, kope_d3d12_descriptor_set *set) {
oa_allocate(&device->d3d12.descriptor_heap_allocator, descriptor_count, &set->allocation);
void kope_d3d12_device_create_descriptor_set(kope_g5_device *device, uint32_t descriptor_count, uint32_t sampler_count, kope_d3d12_descriptor_set *set) {
if (descriptor_count > 0) {
oa_allocate(&device->d3d12.descriptor_heap_allocator, descriptor_count, &set->descriptor_allocation);
}
set->descriptor_count = descriptor_count;

if (sampler_count > 0) {
oa_allocate(&device->d3d12.sampler_heap_allocator, sampler_count, &set->sampler_allocation);
}
set->sampler_count = sampler_count;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void kope_d3d12_device_create_command_list(kope_g5_device *device, kope_g5_comma

void kope_d3d12_device_create_texture(kope_g5_device *device, const kope_g5_texture_parameters *parameters, kope_g5_texture *texture);

void kope_d3d12_device_create_descriptor_set(kope_g5_device *device, uint32_t descriptor_count, kope_d3d12_descriptor_set *set);
void kope_d3d12_device_create_descriptor_set(kope_g5_device *device, uint32_t descriptor_count, uint32_t sampler_count, kope_d3d12_descriptor_set *set);

kope_g5_texture *kope_d3d12_device_get_framebuffer(kope_g5_device *device);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "sampler_functions.h"

#include "d3d12unit.h"

#include <kope/graphics5/sampler.h>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef KOPE_D3D12_SAMPLER_FUNCTIONS_HEADER
#define KOPE_D3D12_SAMPLER_FUNCTIONS_HEADER

#include <kope/graphics5/sampler.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

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

#include "d3d12mini.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct kope_d3d12_sampler {
int nothing;
} kope_d3d12_sampler;

#ifdef __cplusplus
}
#endif

#endif
1 change: 1 addition & 0 deletions Sources/kope/graphics5/g5unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
#include "commandlist.c"
#include "device.c"
#include "graphics.c"
#include "sampler.c"
#include "texture.c"
9 changes: 9 additions & 0 deletions Sources/kope/graphics5/sampler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "sampler.h"

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

#ifdef KOPE_VULKAN
#include <kope/vulkan/sampler_functions.h>
#endif
28 changes: 28 additions & 0 deletions Sources/kope/graphics5/sampler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef KOPE_G5_SAMPLER_HEADER
#define KOPE_G5_SAMPLER_HEADER

#include <kope/global.h>

#include "api.h"

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

#ifdef KOPE_VULKAN
#include <kope/vulkan/sampler_structs.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef struct kope_g5_sampler {
KOPE_G5_IMPL(texture);
} kope_g5_sampler;

#ifdef __cplusplus
}
#endif

#endif

0 comments on commit bcb31dd

Please sign in to comment.