|
@@ -1,3 +1,5 @@
|
|
|
|
|
+#include "DX12GraphicsApi.h"
|
|
|
|
|
+
|
|
|
#include <d3d11.h>
|
|
#include <d3d11.h>
|
|
|
#include <d3d12.h>
|
|
#include <d3d12.h>
|
|
|
#include <dxgi1_6.h>
|
|
#include <dxgi1_6.h>
|
|
@@ -6,17 +8,17 @@
|
|
|
#include "Camera3D.h"
|
|
#include "Camera3D.h"
|
|
|
#include "d3dx12.h"
|
|
#include "d3dx12.h"
|
|
|
#include "DLLRegister.h"
|
|
#include "DLLRegister.h"
|
|
|
-#include "DX12Buffer.h"
|
|
|
|
|
|
|
+#include "DX12BLASModel.h"
|
|
|
#include "DX12CommandQueue.h"
|
|
#include "DX12CommandQueue.h"
|
|
|
#include "DX12PixelShader.h"
|
|
#include "DX12PixelShader.h"
|
|
|
#include "DX12Shader.h"
|
|
#include "DX12Shader.h"
|
|
|
#include "DX12Texture.h"
|
|
#include "DX12Texture.h"
|
|
|
#include "DX12VertexShader.h"
|
|
#include "DX12VertexShader.h"
|
|
|
#include "Globals.h"
|
|
#include "Globals.h"
|
|
|
-#include "GraphicsApi.h"
|
|
|
|
|
#include "Image.h"
|
|
#include "Image.h"
|
|
|
#include "Model3D.h"
|
|
#include "Model3D.h"
|
|
|
#include "Model3DList.h"
|
|
#include "Model3DList.h"
|
|
|
|
|
+#include "Screen.h"
|
|
|
#include "Shader.h"
|
|
#include "Shader.h"
|
|
|
#include "TextureList.h"
|
|
#include "TextureList.h"
|
|
|
#include "TextureModel.h"
|
|
#include "TextureModel.h"
|
|
@@ -103,6 +105,34 @@ DirectX12::~DirectX12()
|
|
|
if (debug) debug->Release();
|
|
if (debug) debug->Release();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void DirectX12::updateBottomLevelAccelerationStructure()
|
|
|
|
|
+{
|
|
|
|
|
+ bool updateRequired = 0;
|
|
|
|
|
+ for (Model3DData* model : *modelList->zModels())
|
|
|
|
|
+ {
|
|
|
|
|
+ if (model->wasIndexBufferChanged() || model->wasVertexBufferChanged())
|
|
|
|
|
+ {
|
|
|
|
|
+ updateRequired = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ int bufferIndex = 0;
|
|
|
|
|
+ if (updateRequired)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (Model3DData* model : *modelList->zModels())
|
|
|
|
|
+ {
|
|
|
|
|
+ int id = model->getId();
|
|
|
|
|
+ if (model->wasIndexBufferChanged()
|
|
|
|
|
+ || model->wasVertexBufferChanged())
|
|
|
|
|
+ {
|
|
|
|
|
+ blasModels[id]->calculateBuffers();
|
|
|
|
|
+ }
|
|
|
|
|
+ bufferIndex += blasModels[id]->getBufferCount();
|
|
|
|
|
+ }
|
|
|
|
|
+ // TODO: create BLAS from calculated buffers
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
typedef HRESULT(__stdcall* CreateDXGIFactory2Function)(UINT, REFIID, void**);
|
|
typedef HRESULT(__stdcall* CreateDXGIFactory2Function)(UINT, REFIID, void**);
|
|
|
|
|
|
|
|
typedef HRESULT(__stdcall* D3D12CreateDeviceFunction)(
|
|
typedef HRESULT(__stdcall* D3D12CreateDeviceFunction)(
|
|
@@ -788,7 +818,8 @@ void DirectX12::beginFrame(bool fill2D, bool fill3D, int fillColor)
|
|
|
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
|
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
|
|
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
|
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
|
|
|
|
|
|
|
- directCommandQueue->getCommandList()->ResourceBarrier(1, &barrier);
|
|
|
|
|
|
|
+ // TODO
|
|
|
|
|
+ // directCommandQueue->getCommandList()->ResourceBarrier(1, &barrier);
|
|
|
|
|
|
|
|
if (fill2D) uiTexture->zImage()->setColor(fillColor);
|
|
if (fill2D) uiTexture->zImage()->setColor(fillColor);
|
|
|
if (fill3D)
|
|
if (fill3D)
|
|
@@ -806,72 +837,26 @@ void DirectX12::beginFrame(bool fill2D, bool fill3D, int fillColor)
|
|
|
= rtvHeap->GetCPUDescriptorHandleForHeapStart();
|
|
= rtvHeap->GetCPUDescriptorHandleForHeapStart();
|
|
|
rtv.ptr += rtvDescriptorSize * backBufferIndex;
|
|
rtv.ptr += rtvDescriptorSize * backBufferIndex;
|
|
|
|
|
|
|
|
- directCommandQueue->getCommandList()->OMSetRenderTargets(1, &rtv, 0, 0);
|
|
|
|
|
- directCommandQueue->getCommandList()->ClearRenderTargetView(
|
|
|
|
|
- rtv, color, 0, 0);
|
|
|
|
|
|
|
+ // TODO
|
|
|
|
|
+ // directCommandQueue->getCommandList()->OMSetRenderTargets(1, &rtv, 0,
|
|
|
|
|
+ // 0);
|
|
|
|
|
+ // directCommandQueue->getCommandList()->ClearRenderTargetView(
|
|
|
|
|
+ // rtv, color, 0, 0);
|
|
|
}
|
|
}
|
|
|
int lc[] = {0, 0};
|
|
int lc[] = {0, 0};
|
|
|
pixelShader->fillConstBuffer((char*)lc, 4, sizeof(int) * 2);
|
|
pixelShader->fillConstBuffer((char*)lc, 4, sizeof(int) * 2);
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
-// Checks whether a sphere is in the visible space of the world and
|
|
|
|
|
-// needs to be drawn
|
|
|
|
|
-// pos: The center of the sphere
|
|
|
|
|
-// radius: The radius of the sphere
|
|
|
|
|
-// dist: A pointer to a float where the square of the distance to the
|
|
|
|
|
-// camera position is stored if this function returns true and
|
|
|
|
|
-// the pointer is not 0
|
|
|
|
|
-bool DirectX12::isInFrustrum(
|
|
|
|
|
- const Vec3<float>& pos, float radius, float* dist) const
|
|
|
|
|
-{
|
|
|
|
|
- for (int i = 0; i < 6; i++)
|
|
|
|
|
- {
|
|
|
|
|
- if (frustrum[i] * pos + radius < 0) return 0;
|
|
|
|
|
- }
|
|
|
|
|
- if (dist) *dist = kamPos.distance(pos);
|
|
|
|
|
- return 1;
|
|
|
|
|
|
|
+ uiTexture->updateTextur();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void DirectX12::renderKamera(Cam3D* zKamera)
|
|
void DirectX12::renderKamera(Cam3D* zKamera)
|
|
|
{
|
|
{
|
|
|
- directCommandQueue->getCommandList()->RSSetViewports(
|
|
|
|
|
- 1, (D3D12_VIEWPORT*)zKamera->zViewPort());
|
|
|
|
|
|
|
+ // TODO
|
|
|
|
|
+ // directCommandQueue->getCommandList()->RSSetViewports(
|
|
|
|
|
+ // 1, (D3D12_VIEWPORT*)zKamera->zViewPort());
|
|
|
|
|
|
|
|
Mat4<float> tmp = zKamera->getProjectionMatrix() * zKamera->getViewMatrix();
|
|
Mat4<float> tmp = zKamera->getProjectionMatrix() * zKamera->getViewMatrix();
|
|
|
|
|
|
|
|
- frustrum[0].x = tmp.elements[3][0] + tmp.elements[0][0];
|
|
|
|
|
- frustrum[0].y = tmp.elements[3][1] + tmp.elements[0][1];
|
|
|
|
|
- frustrum[0].z = tmp.elements[3][2] + tmp.elements[0][2];
|
|
|
|
|
- frustrum[0].w = tmp.elements[3][3] + tmp.elements[0][3];
|
|
|
|
|
-
|
|
|
|
|
- frustrum[1].x = tmp.elements[3][0] - tmp.elements[0][0];
|
|
|
|
|
- frustrum[1].y = tmp.elements[3][1] - tmp.elements[0][1];
|
|
|
|
|
- frustrum[1].z = tmp.elements[3][2] - tmp.elements[0][2];
|
|
|
|
|
- frustrum[1].w = tmp.elements[3][3] - tmp.elements[0][3];
|
|
|
|
|
-
|
|
|
|
|
- frustrum[2].x = tmp.elements[3][0] - tmp.elements[1][0];
|
|
|
|
|
- frustrum[2].y = tmp.elements[3][1] - tmp.elements[1][1];
|
|
|
|
|
- frustrum[2].z = tmp.elements[3][2] - tmp.elements[1][2];
|
|
|
|
|
- frustrum[2].w = tmp.elements[3][3] - tmp.elements[1][3];
|
|
|
|
|
-
|
|
|
|
|
- frustrum[3].x = tmp.elements[3][0] + tmp.elements[1][0];
|
|
|
|
|
- frustrum[3].y = tmp.elements[3][1] + tmp.elements[1][1];
|
|
|
|
|
- frustrum[3].z = tmp.elements[3][2] + tmp.elements[1][2];
|
|
|
|
|
- frustrum[3].w = tmp.elements[3][3] + tmp.elements[1][3];
|
|
|
|
|
-
|
|
|
|
|
- frustrum[4].x = tmp.elements[2][0];
|
|
|
|
|
- frustrum[4].y = tmp.elements[2][1];
|
|
|
|
|
- frustrum[4].z = tmp.elements[2][2];
|
|
|
|
|
- frustrum[4].w = tmp.elements[2][3];
|
|
|
|
|
-
|
|
|
|
|
- frustrum[5].x = tmp.elements[3][0] - tmp.elements[2][0];
|
|
|
|
|
- frustrum[5].y = tmp.elements[3][1] - tmp.elements[2][1];
|
|
|
|
|
- frustrum[5].z = tmp.elements[3][2] - tmp.elements[2][2];
|
|
|
|
|
- frustrum[5].w = tmp.elements[3][3] - tmp.elements[2][3];
|
|
|
|
|
-
|
|
|
|
|
- for (int i = 0; i < 6; i++)
|
|
|
|
|
- frustrum[i].normalize();
|
|
|
|
|
-
|
|
|
|
|
viewAndProj[0] = zKamera->getViewMatrix();
|
|
viewAndProj[0] = zKamera->getViewMatrix();
|
|
|
viewAndProj[1] = zKamera->getProjectionMatrix();
|
|
viewAndProj[1] = zKamera->getProjectionMatrix();
|
|
|
kamPos = zKamera->getWorldPosition();
|
|
kamPos = zKamera->getWorldPosition();
|
|
@@ -882,13 +867,16 @@ void DirectX12::renderKamera(Cam3D* zKamera)
|
|
|
pixelShader->fillConstBuffer((char*)&kamPos, 2, sizeof(float) * 3);
|
|
pixelShader->fillConstBuffer((char*)&kamPos, 2, sizeof(float) * 3);
|
|
|
World3D* w = zKamera->zWorld();
|
|
World3D* w = zKamera->zWorld();
|
|
|
w->render([this](Model3D* obj) {
|
|
w->render([this](Model3D* obj) {
|
|
|
- if (isInFrustrum(obj->getPos(), obj->getRadius())) renderObject(obj);
|
|
|
|
|
|
|
+ // TODO: create or update top level aceleration structure if a model was
|
|
|
|
|
+ // changed
|
|
|
});
|
|
});
|
|
|
|
|
+ // TODO: call ray tracing
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void DirectX12::presentFrame()
|
|
void DirectX12::presentFrame()
|
|
|
{
|
|
{
|
|
|
- directCommandQueue->getCommandList()->RSSetViewports(1, viewPort);
|
|
|
|
|
|
|
+ // TODO
|
|
|
|
|
+ // directCommandQueue->getCommandList()->RSSetViewports(1, viewPort);
|
|
|
|
|
|
|
|
viewAndProj[0] = Mat4<float>::identity();
|
|
viewAndProj[0] = Mat4<float>::identity();
|
|
|
viewAndProj[1] = Mat4<float>::identity();
|
|
viewAndProj[1] = Mat4<float>::identity();
|
|
@@ -896,11 +884,6 @@ void DirectX12::presentFrame()
|
|
|
vertexShader->fillConstBuffer(
|
|
vertexShader->fillConstBuffer(
|
|
|
(char*)viewAndProj, 0, sizeof(Mat4<float>) * 2);
|
|
(char*)viewAndProj, 0, sizeof(Mat4<float>) * 2);
|
|
|
|
|
|
|
|
- uiTexture->updateTextur();
|
|
|
|
|
-
|
|
|
|
|
- if (fenster && !IsIconic(fenster->getWindowHandle()))
|
|
|
|
|
- renderObject(texturModel);
|
|
|
|
|
-
|
|
|
|
|
D3D12_RESOURCE_BARRIER barrier;
|
|
D3D12_RESOURCE_BARRIER barrier;
|
|
|
ZeroMemory(&barrier, sizeof(barrier));
|
|
ZeroMemory(&barrier, sizeof(barrier));
|
|
|
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
|
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
|
@@ -910,7 +893,8 @@ void DirectX12::presentFrame()
|
|
|
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
|
|
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
|
|
|
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
|
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
|
|
|
|
|
|
|
- directCommandQueue->getCommandList()->ResourceBarrier(1, &barrier);
|
|
|
|
|
|
|
+ // TODO
|
|
|
|
|
+ // directCommandQueue->getCommandList()->ResourceBarrier(1, &barrier);
|
|
|
copyCommandQueue->execute();
|
|
copyCommandQueue->execute();
|
|
|
directCommandQueue->execute();
|
|
directCommandQueue->execute();
|
|
|
|
|
|