From b93b78013a3d795fa65cf6e12f8c8e50969c7251 Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Mon, 16 Sep 2024 14:16:41 +0200 Subject: [PATCH] Kick out DirectXMath --- .../Sources/kope/direct3d12/device.cpp | 85 ++++++++++++++----- .../kope/direct3d12/device_functions.h | 6 +- Sources/kope/graphics5/device.c | 6 +- Sources/kope/graphics5/device.h | 6 +- 4 files changed, 77 insertions(+), 26 deletions(-) diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp index f7121fe76..2c4b10cbe 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp @@ -11,6 +11,7 @@ #include #include +#include #include @@ -649,12 +650,8 @@ void kope_d3d12_device_create_raytracing_volume(kope_g5_device *device, kope_g5_ kope_g5_device_create_buffer(device, &as_params, &volume->d3d12.acceleration_structure); } -#include // temporary - -void kope_d3d12_device_create_raytracing_hierarchy(kope_g5_device *device, kope_g5_raytracing_volume **volumes, uint32_t volumes_count, - kope_g5_raytracing_hierarchy *hierarchy) { - using namespace DirectX; // temporary - +void kope_d3d12_device_create_raytracing_hierarchy(kope_g5_device *device, kope_g5_raytracing_volume **volumes, kinc_matrix4x4_t *volume_transforms, + uint32_t volumes_count, kope_g5_raytracing_hierarchy *hierarchy) { hierarchy->d3d12.volumes_count = volumes_count; kope_g5_buffer_parameters instances_params; @@ -675,25 +672,75 @@ void kope_d3d12_device_create_raytracing_hierarchy(kope_g5_device *device, kope_ auto time = static_cast(GetTickCount64()) / 1000; { - auto cube = XMMatrixRotationRollPitchYaw(time / 2, time / 3, time / 5); - cube *= XMMatrixTranslation(-1.5, 2, 2); - auto *ptr = reinterpret_cast(&descs[0].Transform); - XMStoreFloat3x4(ptr, cube); + kinc_matrix4x4_t cube = kinc_matrix4x4_rotation_y(time / 3); + kinc_matrix4x4_t a = kinc_matrix4x4_rotation_x(time / 2); + cube = kinc_matrix4x4_multiply(&a, &cube); + kinc_matrix4x4_t b = kinc_matrix4x4_rotation_z(time / 5); + cube = kinc_matrix4x4_multiply(&b, &cube); + kinc_matrix4x4_t c = kinc_matrix4x4_translation(-1.5, 2, 2); + cube = kinc_matrix4x4_multiply(&c, &cube); + + descs[0].Transform[0][0] = cube.m[0]; + descs[0].Transform[1][0] = cube.m[1]; + descs[0].Transform[2][0] = cube.m[2]; + + descs[0].Transform[0][1] = cube.m[4]; + descs[0].Transform[1][1] = cube.m[5]; + descs[0].Transform[2][1] = cube.m[6]; + + descs[0].Transform[0][2] = cube.m[8]; + descs[0].Transform[1][2] = cube.m[9]; + descs[0].Transform[2][2] = cube.m[10]; + + descs[0].Transform[0][3] = cube.m[12]; + descs[0].Transform[1][3] = cube.m[13]; + descs[0].Transform[2][3] = cube.m[14]; } { - auto mirror = XMMatrixRotationX(-1.8f); - mirror *= XMMatrixRotationY(XMScalarSinEst(time) / 8 + 1); - mirror *= XMMatrixTranslation(2, 2, 2); - auto *ptr = reinterpret_cast(&descs[1].Transform); - XMStoreFloat3x4(ptr, mirror); + kinc_matrix4x4_t mirror = kinc_matrix4x4_rotation_x(-1.8f); + kinc_matrix4x4_t a = kinc_matrix4x4_rotation_y(sinf(time) / 8 + 1); + mirror = kinc_matrix4x4_multiply(&a, &mirror); + kinc_matrix4x4_t b = kinc_matrix4x4_translation(2, 2, 2); + mirror = kinc_matrix4x4_multiply(&b, &mirror); + + descs[1].Transform[0][0] = mirror.m[0]; + descs[1].Transform[1][0] = mirror.m[1]; + descs[1].Transform[2][0] = mirror.m[2]; + + descs[1].Transform[0][1] = mirror.m[4]; + descs[1].Transform[1][1] = mirror.m[5]; + descs[1].Transform[2][1] = mirror.m[6]; + + descs[1].Transform[0][2] = mirror.m[8]; + descs[1].Transform[1][2] = mirror.m[9]; + descs[1].Transform[2][2] = mirror.m[10]; + + descs[1].Transform[0][3] = mirror.m[12]; + descs[1].Transform[1][3] = mirror.m[13]; + descs[1].Transform[2][3] = mirror.m[14]; } { - auto floor = XMMatrixScaling(5, 5, 5); - floor *= XMMatrixTranslation(0, 0, 2); - auto *ptr = reinterpret_cast(&descs[2].Transform); - XMStoreFloat3x4(ptr, floor); + kinc_matrix4x4_t floor = kinc_matrix4x4_scale(5, 5, 5); + kinc_matrix4x4_t a = kinc_matrix4x4_translation(0, 0, 2); + floor = kinc_matrix4x4_multiply(&a, &floor); + + descs[2].Transform[0][0] = floor.m[0]; + descs[2].Transform[1][0] = floor.m[1]; + descs[2].Transform[2][0] = floor.m[2]; + + descs[2].Transform[0][1] = floor.m[4]; + descs[2].Transform[1][1] = floor.m[5]; + descs[2].Transform[2][1] = floor.m[6]; + + descs[2].Transform[0][2] = floor.m[8]; + descs[2].Transform[1][2] = floor.m[9]; + descs[2].Transform[2][2] = floor.m[10]; + + descs[2].Transform[0][3] = floor.m[12]; + descs[2].Transform[1][3] = floor.m[13]; + descs[2].Transform[2][3] = floor.m[14]; } // diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_functions.h b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_functions.h index b8108af17..0ccfcd55f 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_functions.h +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_functions.h @@ -3,6 +3,8 @@ #include +#include + #include "descriptorset_structs.h" #ifdef __cplusplus @@ -32,8 +34,8 @@ void kope_d3d12_device_execute_command_list(kope_g5_device *device, kope_g5_comm void kope_d3d12_device_create_raytracing_volume(kope_g5_device *device, kope_g5_buffer *vertex_buffer, uint64_t vertex_count, kope_g5_buffer *index_buffer, uint32_t index_count, kope_g5_raytracing_volume *volume); -void kope_d3d12_device_create_raytracing_hierarchy(kope_g5_device *device, kope_g5_raytracing_volume **volumes, uint32_t volumes_count, - kope_g5_raytracing_hierarchy *hierarchy); +void kope_d3d12_device_create_raytracing_hierarchy(kope_g5_device *device, kope_g5_raytracing_volume **volumes, kinc_matrix4x4_t *volume_transforms, + uint32_t volumes_count, kope_g5_raytracing_hierarchy *hierarchy); #ifdef __cplusplus } diff --git a/Sources/kope/graphics5/device.c b/Sources/kope/graphics5/device.c index d0b09c5c3..67f4471f6 100644 --- a/Sources/kope/graphics5/device.c +++ b/Sources/kope/graphics5/device.c @@ -164,7 +164,7 @@ void kope_g5_device_create_raytracing_volume(kope_g5_device *device, kope_g5_buf KOPE_G5_CALL6(device_create_raytracing_volume, device, vertex_buffer, vertex_count, index_buffer, index_count, volume); } -void kope_g5_device_create_raytracing_hierarchy(kope_g5_device *device, kope_g5_raytracing_volume **volumes, uint32_t volumes_count, - kope_g5_raytracing_hierarchy *hierarchy) { - KOPE_G5_CALL4(device_create_raytracing_hierarchy, device, volumes, volumes_count, hierarchy); +void kope_g5_device_create_raytracing_hierarchy(kope_g5_device *device, kope_g5_raytracing_volume **volumes, kinc_matrix4x4_t *volume_transforms, + uint32_t volumes_count, kope_g5_raytracing_hierarchy *hierarchy) { + KOPE_G5_CALL5(device_create_raytracing_hierarchy, device, volumes, volume_transforms, volumes_count, hierarchy); } diff --git a/Sources/kope/graphics5/device.h b/Sources/kope/graphics5/device.h index de149ee9f..53198f9aa 100644 --- a/Sources/kope/graphics5/device.h +++ b/Sources/kope/graphics5/device.h @@ -3,6 +3,8 @@ #include +#include + #include "api.h" #include "buffer.h" #include "commandlist.h" @@ -180,8 +182,8 @@ typedef struct kope_g5_raytracing_hierarchy { KOPE_FUNC void kope_g5_device_create_raytracing_volume(kope_g5_device *device, kope_g5_buffer *vertex_buffer, uint64_t vertex_count, kope_g5_buffer *index_buffer, uint32_t index_count, kope_g5_raytracing_volume *volume); -KOPE_FUNC void kope_g5_device_create_raytracing_hierarchy(kope_g5_device *device, kope_g5_raytracing_volume **volumes, uint32_t volumes_count, - kope_g5_raytracing_hierarchy *hierarchy); +KOPE_FUNC void kope_g5_device_create_raytracing_hierarchy(kope_g5_device *device, kope_g5_raytracing_volume **volumes, kinc_matrix4x4_t *volume_transforms, + uint32_t volumes_count, kope_g5_raytracing_hierarchy *hierarchy); #ifdef __cplusplus }