Skip to content

Commit 0141c98

Browse files
authored
Merge pull request #4 from GameTechDev/adding_command_line_options
Adding additional options to control the program using the command line
2 parents ec738e6 + a834c32 commit 0141c98

File tree

7 files changed

+93
-17
lines changed

7 files changed

+93
-17
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ The sample executable is called `dino_danger`. You can run it from the **Microso
4444
You can also get more info about the command line options by running:
4545

4646
dino_danger.exe --help
47-
--data-dir Location of the resource folders.
48-
--adapter-id Integer that allows to pick the desired GPU.
49-
--poi Integer that allows to pick the initial camera location.
50-
--disable-coop Disable cooperative vector usage at launch.
51-
--enable-animation Enable mesh animation at launch.
47+
--data-dir Location of the resource folders.
48+
--adapter-id Integer that allows to pick the desired GPU [-1 = Largest VRAM, >= 0 System adapter ID].
49+
--poi Integer that allows to pick the initial camera location.
50+
--disable-coop Disable cooperative vector usage at launch.
51+
--disable-animation Disable mesh animation at launch.
52+
--rendering-mode Pick the rendering mode [0 = Material, 1 = GBuffer, 2 = Debug].
53+
--texture-mode Pick the texture mode [0 = Uncompressed, 1 = BC6, 2 = Neural].
54+
--filtering-mode Pick the filtering mode [0 = Nearest, 1 = Linear, 2 = Anisotropic].
5255

5356
## License
5457
Intel® Texture Set Neural Compression Sample is licensed under the [MIT License](LICENSE).

sdk/include/math/operators.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
// SDK includes
1111
#include "math/types.h"
1212

13+
#pragma region int
14+
int clamp(int v, int minV, int maxV);
15+
#pragma endregion
16+
1317
#pragma region float
18+
float clamp(float v, float minV, float maxV);
1419
float min3(float v0, float v1, float v2);
1520
float max3(float v0, float v1, float v2);
1621
float lerp(const float& v0, const float& v1, float f);

sdk/include/tools/command_line.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
#pragma once
99

10+
// Project includes
11+
#include "render_pipeline/types.h"
12+
1013
// System includes
1114
#include <vector>
1215
#include <string>
@@ -17,7 +20,7 @@ struct CommandLineOptions
1720
std::string dataDir = ".";
1821

1922
// Adapter index (as returned by OS)
20-
uint32_t adapterIndex = 0;
23+
int32_t adapterIndex = -1;
2124

2225
// Picking an initial POI
2326
uint32_t initialPOI = 0;
@@ -26,7 +29,16 @@ struct CommandLineOptions
2629
bool enableCooperative = true;
2730

2831
// Mesh animation enabled at start
29-
bool enableAnimation = true;
32+
bool disableAnimation = false;
33+
34+
// Control the rendering mode
35+
RenderingMode renderingMode = RenderingMode::GBufferDeferred;
36+
37+
// Control the texture mode
38+
TextureMode textureMode = TextureMode::Neural;
39+
40+
// Filtering mode
41+
FilteringMode filteringMode = FilteringMode::Anisotropic;
3042
};
3143

3244
namespace command_line

sdk/src/dx12/dx12_backend_graphics_device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ namespace d3d12
184184
DXGI_ADAPTER_DESC1 dxgiAdapterDesc1;
185185
adapter->GetDesc1(&dxgiAdapterDesc1);
186186
dx12_device->adapterName = convert_to_regular(dxgiAdapterDesc1.Description);
187-
// wprintf(L"Picked GPU: %s\n", dxgiAdapterDesc1.Description);
187+
wprintf(L"Picked GPU: %s\n", dxgiAdapterDesc1.Description);
188188
// wprintf(L"GPU Memory: %" PRIu64 L"\n", dxgiAdapterDesc1.DedicatedVideoMemory);
189189

190190
// Create the graphics device and ensure it's been succesfully created

sdk/src/math/operators.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,24 @@ OT sign(IT value) {
1818
return 0;
1919
}
2020

21+
#pragma region int
22+
int clamp(int v, int minV, int maxV)
23+
{
24+
return std::min(std::max(v, minV), maxV);
25+
}
26+
#pragma endregion
27+
2128
#pragma region float
29+
float clamp(float v, float minV, float maxV)
30+
{
31+
return std::min(std::max(v, minV), maxV);
32+
}
33+
2234
float max3(float v0, float v1, float v2)
2335
{
2436
return std::max({ v0, v1, v2 });
2537
}
38+
2639
float min3(float v0, float v1, float v2)
2740
{
2841
return std::min({ v0, v1, v2 });

sdk/src/render_pipeline/dino_renderer.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ void DinoRenderer::initialize(uint64_t hInstance, const CommandLineOptions& opti
5656
graphics::setup_graphics_api(GraphicsAPI::DX12);
5757
// graphics::device::enable_debug_layer();
5858
graphics::device::enable_experimental_features();
59-
m_Device = graphics::device::create_graphics_device();
59+
60+
// Create the device based on the criteria
61+
if (options.adapterIndex >= 0 )
62+
m_Device = graphics::device::create_graphics_device(DevicePickStrategy::AdapterID, options.adapterIndex);
63+
else
64+
m_Device = graphics::device::create_graphics_device(DevicePickStrategy::VRAMSize);
65+
6066
m_Window = graphics::window::create_window(m_Device, (uint64_t)hInstance, 1920, 1080, "Intel TSNC (DX12)");
6167
m_CmdQueue = graphics::command_queue::create_command_queue(m_Device);
6268
m_SwapChain = graphics::swap_chain::create_swap_chain(m_Window, m_Device, m_CmdQueue, FRAME_BUFFER_FORMAT);
@@ -80,10 +86,10 @@ void DinoRenderer::initialize(uint64_t hInstance, const CommandLineOptions& opti
8086
m_CameraController.move_to_poi(options.initialPOI);
8187

8288
// Initial setup
83-
m_RenderingMode = RenderingMode::GBufferDeferred;
84-
m_TextureMode = TextureMode::Neural;
89+
m_RenderingMode = options.renderingMode;
90+
m_TextureMode = options.textureMode;
8591
m_DebugMode = DebugMode::TileInfo;
86-
m_FilteringMode = FilteringMode::Linear;
92+
m_FilteringMode = options.filteringMode;
8793
m_DisplayUI = true;
8894
m_UseCooperativeVectors = m_CooperativeVectorsSupported ? options.enableCooperative : false;
8995
m_EnableCounters = false;
@@ -164,7 +170,7 @@ void DinoRenderer::initialize(uint64_t hInstance, const CommandLineOptions& opti
164170
m_GBuffer = graphics::resources::create_graphics_buffer(m_Device, numPixels * sizeof(uint16_t) * numChannels, sizeof(uint16_t), GraphicsBufferType::Default);
165171

166172
// Post setups
167-
m_MeshRenderer.set_animation_state(options.enableAnimation);
173+
m_MeshRenderer.set_animation_state(!options.disableAnimation);
168174
}
169175

170176
void DinoRenderer::reload_shaders()

sdk/src/tools/command_line.cpp

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
// Includes
99
#include "tools/command_line.h"
10+
#include "math/operators.h"
11+
12+
// System includes
13+
#include <algorithm>
1014

1115
namespace command_line
1216
{
@@ -56,19 +60,52 @@ namespace command_line
5660
commandLineOptions.enableCooperative = false;
5761
current_arg_idx += 1;
5862
}
59-
else if (args[current_arg_idx] == "--enable-animation")
63+
else if (args[current_arg_idx] == "--disable-animation")
6064
{
61-
commandLineOptions.enableAnimation = true;
65+
commandLineOptions.disableAnimation = true;
6266
current_arg_idx += 1;
6367
}
68+
else if (args[current_arg_idx] == "--rendering-mode")
69+
{
70+
if (current_arg_idx == num_args - 1)
71+
{
72+
printf("Command line parser: please provide a rendering mode [0 = Material, 1 = GBuffer, 2 = Debug].");
73+
continue;
74+
}
75+
commandLineOptions.renderingMode = (RenderingMode)clamp(atoi(args[current_arg_idx + 1].c_str()), 0, 2);
76+
current_arg_idx += 2;
77+
}
78+
else if (args[current_arg_idx] == "--texture-mode")
79+
{
80+
if (current_arg_idx == num_args - 1)
81+
{
82+
printf("Command line parser: please provide a texture mode ID [0 = Uncompressed, 1 = BC6, 2 = Neural].");
83+
continue;
84+
}
85+
commandLineOptions.textureMode = (TextureMode)clamp(atoi(args[current_arg_idx + 1].c_str()), 0, 2);
86+
current_arg_idx += 2;
87+
}
88+
else if (args[current_arg_idx] == "--filtering-mode")
89+
{
90+
if (current_arg_idx == num_args - 1)
91+
{
92+
printf("Command line parser: please provide a filtering mode ID [0 = Nearest, 1 = Linear, 2 = Anisotropic].");
93+
continue;
94+
}
95+
commandLineOptions.filteringMode = (FilteringMode)clamp(atoi(args[current_arg_idx + 1].c_str()), 0, 2);
96+
current_arg_idx += 2;
97+
}
6498
else if (args[current_arg_idx] == "--help")
6599
{
66100
printf("Option list:\n");
67101
printf("--data-dir Location of the resource folders.\n");
68-
printf("--adapter-id Integer that allows to pick the desired GPU.\n");
102+
printf("--adapter-id Integer that allows to pick the desired GPU [-1 = Largest VRAM, >= 0 System adapter ID].\n");
69103
printf("--poi Integer that allows to pick the initial camera location.\n");
70104
printf("--disable-coop Disable cooperative vector usage at launch.\n");
71-
printf("--enable-animation Enable mesh animation at launch.\n");
105+
printf("--disable-animation Disable mesh animation at launch.\n");
106+
printf("--rendering-mode Pick the rendering mode [0 = Material, 1 = GBuffer, 2 = Debug].\n");
107+
printf("--texture-mode Pick the texture mode [0 = Uncompressed, 1 = BC6, 2 = Neural].\n");
108+
printf("--filtering-mode Pick the filtering mode [0 = Nearest, 1 = Linear, 2 = Anisotropic].\n");
72109
return false;
73110
}
74111
else

0 commit comments

Comments
 (0)