Skip to content

Commit

Permalink
Reorganize a few files and a few build libs/incs
Browse files Browse the repository at this point in the history
  • Loading branch information
quadpixels committed Sep 11, 2023
1 parent 0211842 commit e56ac2d
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 84 deletions.
41 changes: 29 additions & 12 deletions chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ int Chunk::size = 32;
unsigned Chunk::program = 0;

extern bool IsGL();
extern bool IsD3D11();
extern bool IsD3D12();
extern Camera* GetCurrentSceneCamera();

#ifdef WIN32
Expand All @@ -18,6 +20,8 @@ extern ID3D11DeviceContext* g_context11;
extern ID3D11Buffer* g_perobject_cb_default_palette;
extern DirectX::XMMATRIX g_projection_d3d11;

extern ID3D12Device* g_device12;

struct DefaultPalettePerObjectCB {
DirectX::XMMATRIX M, V, P;
};
Expand Down Expand Up @@ -268,18 +272,31 @@ void Chunk::BuildBuffers(Chunk* neighbors[26]) {
}
else {
#ifdef WIN32
if (tri_count > 0) {
D3D11_BUFFER_DESC desc = { };
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
desc.ByteWidth = sizeof(float) * tri_count * 3 * 6;
desc.StructureByteStride = sizeof(float) * 6;
desc.Usage = D3D11_USAGE_IMMUTABLE;

D3D11_SUBRESOURCE_DATA srd = { };
srd.pSysMem = tmp_packed;
srd.SysMemPitch = sizeof(float) * tri_count * 3 * 6;

assert(SUCCEEDED(g_device11->CreateBuffer(&desc, &srd, &d3d11_vertex_buffer)));
if (IsD3D11()) {
if (tri_count > 0) {
D3D11_BUFFER_DESC desc = { };
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
desc.ByteWidth = sizeof(float) * tri_count * 3 * 6;
desc.StructureByteStride = sizeof(float) * 6;
desc.Usage = D3D11_USAGE_IMMUTABLE;

D3D11_SUBRESOURCE_DATA srd = { };
srd.pSysMem = tmp_packed;
srd.SysMemPitch = sizeof(float) * tri_count * 3 * 6;

assert(SUCCEEDED(g_device11->CreateBuffer(&desc, &srd, &d3d11_vertex_buffer)));
}
}
else if (IsD3D12()) {
if (tri_count > 0) {
CE(g_device12->CreateCommittedResource(
&keep(CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD)),
D3D12_HEAP_FLAG_NONE,
&keep(CD3DX12_RESOURCE_DESC::Buffer(sizeof(float)* tri_count * 3 * 6)),
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(&d3d12_vertex_buffer)));
}
}
#endif
}
Expand Down
2 changes: 2 additions & 0 deletions chunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifdef WIN32
#include <d3d11.h>
#include <d3d12.h>
#include "d3dx12.h"
#include <DirectXMath.h>
#endif
#undef max
Expand Down Expand Up @@ -44,6 +45,7 @@ class Chunk {
#ifdef WIN32
ID3D11Buffer* d3d11_vertex_buffer;
ID3D12Resource* d3d12_vertex_buffer;
D3D12_VERTEX_BUFFER_VIEW d3d12_vertex_buffer_view;
#endif

static float l0;
Expand Down
8 changes: 4 additions & 4 deletions cyclimb_win.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
<LibraryPath>$(ProjectDir)\windows_lib\freetype-2.10.0\win32;$(ProjectDir)\windows_lib\glew-2.0.0\lib\Release\Win32;$(ProjectDir)\windows_lib\glfw-3.3.2.bin.WIN32\lib-vc2019;$(ProjectDir)\windows_lib\freeglut\lib;$(ProjectDir)\windows_lib\DirectxTK\Bin\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>$(ProjectDir)\windows_lib\freetype-2.10.0\include;$(ProjectDir)\windows_lib\glm-0.9.9.5;$(ProjectDir)\windows_lib\glew-2.0.0\include;$(ProjectDir)\windows_lib\freeglut\include;$(ProjectDir)\windows_lib\glfw-3.2.1.bin.WIN64\include;$(ProjectDir)\windows_lib\DirectxTK\Inc;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)\windows_lib\freetype-2.10.0\include;$(ProjectDir)\windows_lib\glm-0.9.9.5;$(ProjectDir)\windows_lib\glew-2.0.0\include;$(ProjectDir)\windows_lib\freeglut\include;$(ProjectDir)\windows_lib\glfw-3.2.1.bin.WIN64\include;$(ProjectDir)\windows_lib\DirectxTK\Inc;$(SolutionDir)dx12helloworld;$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)\windows_lib\freetype-2.10.0\win64;$(ProjectDir)\windows_lib\freeglut\lib\x64;$(ProjectDir)\windows_lib\glew-2.0.0\lib\Release\x64;$(ProjectDir)\windows_lib\glfw-3.2.1.bin.WIN64\lib-vc2015;$(ProjectDir)\windows_lib\DirectxTK\Bin\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>$(ProjectDir)\windows_lib\glfw-3.3.2.bin.WIN64\include;C:\Users\nitroglycerine\Downloads\DirectXTK-master\Inc;$(ProjectDir)\windows_lib\freetype-2.10.0\include;$(ProjectDir)\windows_lib\glm-0.9.9.5;$(ProjectDir)\windows_lib\glew-2.0.0\include;$(ProjectDir)\windows_lib\freeglut\include;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)\windows_lib\glfw-3.3.2.bin.WIN64\include;C:\Users\nitroglycerine\Downloads\DirectXTK-master\Inc;$(ProjectDir)\windows_lib\freetype-2.10.0\include;$(ProjectDir)\windows_lib\glm-0.9.9.5;$(ProjectDir)\windows_lib\glew-2.0.0\include;$(ProjectDir)\windows_lib\freeglut\include;$(SolutionDir)\dx12helloworld;$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)\windows_lib\glfw-3.3.2.bin.WIN64\lib-vc2015;C:\Users\nitroglycerine\Downloads\DirectXTK-master\Bin\Desktop_2019_Win10\x64\Release;$(ProjectDir)\windows_lib\freeglut\lib\x64;$(ProjectDir)\windows_lib\freetype-2.10.0\win64;$(ProjectDir)\windows_lib\glew-2.0.0\lib\Release\x64;$(ProjectDir)\windows_lib\DirectxTK\Bin\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
Expand Down Expand Up @@ -118,7 +118,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Link>
<AdditionalDependencies>glfw3.lib;glew32.lib;freetype.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>glfw3.lib;glew32.lib;freetype.lib;d3d11.lib;d3d12.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
<ClCompile>
Expand All @@ -128,7 +128,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Link>
<AdditionalDependencies>directxtk.lib;glfw3.lib;d3d11.lib;d3dcompiler.lib;glew32.lib;freetype.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>directxtk.lib;glfw3.lib;d3d11.lib;d3d12.lib;d3dcompiler.lib;glew32.lib;freetype.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
</Link>
<ClCompile>
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions dx12helloworld/DX12ChunksScene.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "scene.hpp"

#include "d3dx12.h"
#include "utils.hpp"
#include "util.hpp"
#include <wrl/client.h>

using Microsoft::WRL::ComPtr;

void WaitForPreviousFrame();
extern ID3D12Device* g_device;
extern ID3D12Device* g_device12;

/*
cbuffer CBPerObject : register(b0) {
Expand Down Expand Up @@ -38,9 +38,9 @@ DX12ChunksScene::DX12ChunksScene() {
}

void DX12ChunksScene::InitPipelineAndCommandList() {
CE(g_device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
CE(g_device12->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
IID_PPV_ARGS(&command_allocator)));
CE(g_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT,
CE(g_device12->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT,
command_allocator, nullptr, IID_PPV_ARGS(&command_list)));
CE(command_list->Close());

Expand Down Expand Up @@ -79,7 +79,7 @@ void DX12ChunksScene::InitPipelineAndCommandList() {
(char*)(error->GetBufferPointer()));
}

CE(g_device->CreateRootSignature(0, signature->GetBufferPointer(),
CE(g_device12->CreateRootSignature(0, signature->GetBufferPointer(),
signature->GetBufferSize(), IID_PPV_ARGS(&root_signature)));
root_signature->SetName(L"Root signature");
}
Expand Down Expand Up @@ -116,7 +116,7 @@ void DX12ChunksScene::InitPipelineAndCommandList() {
.Count = 1,
},
};
CE(g_device->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&pipeline_state)));
CE(g_device12->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&pipeline_state)));
}

void DX12ChunksScene::InitResources() {
Expand Down
12 changes: 6 additions & 6 deletions dx12helloworld/DX12ClearScreenScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#include <dxgi1_4.h>
#include <wrl/client.h>

#include "utils.hpp"
#include "util.hpp"

using Microsoft::WRL::ComPtr;

extern HWND g_hwnd;
extern int WIN_W, WIN_H;

extern ID3D12Device* g_device;
extern ID3D12Device* g_device12;
extern IDXGIFactory4* g_factory;
extern ID3D12CommandQueue* g_command_queue;
extern ID3D12Fence* g_fence;
Expand All @@ -36,10 +36,10 @@ void DX12ClearScreenScene::Update(float secs) {
}

void DX12ClearScreenScene::InitPipelineAndCommandList() {
CE(g_device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
CE(g_device12->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
IID_PPV_ARGS(&command_allocator)));

CE(g_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT,
CE(g_device12->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT,
command_allocator, nullptr, IID_PPV_ARGS(&command_list)));
CE(command_list->Close());

Expand Down Expand Up @@ -69,7 +69,7 @@ void DX12ClearScreenScene::InitPipelineAndCommandList() {
(char*)(error->GetBufferPointer()));
}

CE(g_device->CreateRootSignature(0, signature->GetBufferPointer(),
CE(g_device12->CreateRootSignature(0, signature->GetBufferPointer(),
signature->GetBufferSize(), IID_PPV_ARGS(&root_signature)));
root_signature->SetName(L"Root signature");
}
Expand Down Expand Up @@ -116,7 +116,7 @@ void DX12ClearScreenScene::InitPipelineAndCommandList() {
},
};

CE(g_device->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&pipeline_state)));
CE(g_device12->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&pipeline_state)));
}

DX12ClearScreenScene::DX12ClearScreenScene() {
Expand Down
24 changes: 12 additions & 12 deletions dx12helloworld/DX12HelloTriangleScene.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "scene.hpp"

#include "d3dx12.h"
#include "utils.hpp"
#include "util.hpp"
#include <Windows.h>
#include <stdio.h>
#include <wrl/client.h>

using Microsoft::WRL::ComPtr;

extern int WIN_W, WIN_H;
extern ID3D12Device* g_device;
extern ID3D12Device* g_device12;
extern int g_frame_index;
extern ID3D12CommandQueue* g_command_queue;
extern IDXGISwapChain3* g_swapchain;
Expand Down Expand Up @@ -107,9 +107,9 @@ void DX12HelloTriangleScene::Update(float secs) {
}

void DX12HelloTriangleScene::InitPipelineAndCommandList() {
CE(g_device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
CE(g_device12->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
IID_PPV_ARGS(&command_allocator)));
CE(g_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT,
CE(g_device12->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT,
command_allocator, nullptr, IID_PPV_ARGS(&command_list)));
CE(command_list->Close());

Expand Down Expand Up @@ -163,7 +163,7 @@ void DX12HelloTriangleScene::InitPipelineAndCommandList() {
(char*)(error->GetBufferPointer()));
}

CE(g_device->CreateRootSignature(0, signature->GetBufferPointer(),
CE(g_device12->CreateRootSignature(0, signature->GetBufferPointer(),
signature->GetBufferSize(), IID_PPV_ARGS(&root_signature)));
root_signature->SetName(L"Root signature");
}
Expand Down Expand Up @@ -201,7 +201,7 @@ void DX12HelloTriangleScene::InitPipelineAndCommandList() {
},
};

CE(g_device->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&pipeline_state)));
CE(g_device12->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&pipeline_state)));
}

void DX12HelloTriangleScene::InitResources() {
Expand All @@ -210,7 +210,7 @@ void DX12HelloTriangleScene::InitResources() {
{ { 0.25f, -0.25f, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } },
{ { -0.25f, -0.25f, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } }
};
CE(g_device->CreateCommittedResource(
CE(g_device12->CreateCommittedResource(
&keep(CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD)),
D3D12_HEAP_FLAG_NONE,
&keep(CD3DX12_RESOURCE_DESC::Buffer(sizeof(verts))),
Expand All @@ -232,11 +232,11 @@ void DX12HelloTriangleScene::InitResources() {
cbv_heap_desc.NumDescriptors = 2; // Just 1 constant buffer
cbv_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
cbv_heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
CE(g_device->CreateDescriptorHeap(&cbv_heap_desc, IID_PPV_ARGS(&cbv_heap)));
cbv_descriptor_size = g_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
CE(g_device12->CreateDescriptorHeap(&cbv_heap_desc, IID_PPV_ARGS(&cbv_heap)));
cbv_descriptor_size = g_device12->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);

// CBV's resource
CE(g_device->CreateCommittedResource(
CE(g_device12->CreateCommittedResource(
&keep(CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD)),
D3D12_HEAP_FLAG_NONE,
&keep(CD3DX12_RESOURCE_DESC::Buffer(512)),
Expand All @@ -251,9 +251,9 @@ void DX12HelloTriangleScene::InitResources() {

CD3DX12_CPU_DESCRIPTOR_HANDLE handle1(cbv_heap->GetCPUDescriptorHandleForHeapStart(),
0, cbv_descriptor_size);
g_device->CreateConstantBufferView(&cbv_desc, handle1);
g_device12->CreateConstantBufferView(&cbv_desc, handle1);

handle1.Offset(cbv_descriptor_size);
cbv_desc.BufferLocation += 256;
g_device->CreateConstantBufferView(&cbv_desc, handle1);
g_device12->CreateConstantBufferView(&cbv_desc, handle1);
}
4 changes: 2 additions & 2 deletions dx12helloworld/dx12helloworld.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir)\windows_lib\freetype-2.10.0\include;$(SolutionDir)\windows_lib\glm-0.9.9.5;$(SolutionDir)\windows_lib\glew-2.0.0\include;$(SolutionDir)\windows_lib\freeglut\include;$(SolutionDir)\windows_lib\glfw-3.2.1.bin.WIN64\include;$(SolutionDir)\windows_lib\DirectxTK\Inc</IncludePath>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir)\windows_lib\freetype-2.10.0\include;$(SolutionDir)\windows_lib\glm-0.9.9.5;$(SolutionDir)\windows_lib\glew-2.0.0\include;$(SolutionDir)\windows_lib\freeglut\include;$(SolutionDir)\windows_lib\glfw-3.2.1.bin.WIN64\include;$(SolutionDir)\windows_lib\DirectxTK\Inc;$(SolutionDir)</IncludePath>
<LibraryPath>$(SolutionDir)\windows_lib\freetype-2.10.0\win64;$(SolutionDir)\windows_lib\freeglut\lib\x64;$(SolutionDir)\windows_lib\glew-2.0.0\lib\Release\x64;$(SolutionDir)\windows_lib\glfw-3.2.1.bin.WIN64\lib-vc2015;$(SolutionDir)\windows_lib\DirectxTK\Bin\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down Expand Up @@ -162,8 +162,8 @@
<ItemGroup>
<ClInclude Include="..\chunk.hpp" />
<ClInclude Include="..\chunkindex.hpp" />
<ClInclude Include="..\d3dx12.h" />
<ClInclude Include="..\util.hpp" />
<ClInclude Include="d3dx12.h" />
<ClInclude Include="scene.hpp" />
<ClInclude Include="utils.hpp" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions dx12helloworld/dx12helloworld.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="d3dx12.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="scene.hpp">
<Filter>Header Files</Filter>
</ClInclude>
Expand All @@ -59,5 +56,8 @@
<ClInclude Include="..\util.hpp">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\d3dx12.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
Loading

0 comments on commit e56ac2d

Please sign in to comment.