Skip to content

Commit a680524

Browse files
authored
Merge pull request #50 from egorodet/develop
Graphics Core API optimizations and refactoring, improved shaders toolchain with HLSL6 & DXC, external library updates
2 parents c14bca1 + 749fd1a commit a680524

File tree

409 files changed

+11231
-7104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

409 files changed

+11231
-7104
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
/.idea/workspace.xml
33
/.scannerwork
44
/.sonarqube
5+
/*.srctrl*
56
/out
67
/CMakeLists.txt.user

.idea/dictionaries/egorodet.xml

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 319 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Apps/Samples/Asteroids/Asteroid.cpp

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@ Random generated asteroid model with mesh and texture ready for rendering
2424
#include "Asteroid.h"
2525

2626
#include <Methane/Graphics/Noise.hpp>
27-
#include <Methane/Data/Instrumentation.h>
27+
#include <Methane/Instrumentation.h>
2828

2929
#include <cmath>
30-
#include <sstream>
3130

3231
namespace Methane::Samples
3332
{
3433

3534
using AsteroidColorSchema = std::array<gfx::Color3f, Asteroid::color_schema_size>;
3635

37-
static gfx::Color3f TransformSRGBToLinear(const gfx::Color3f& srgb_color)
36+
static gfx::Color3f TransformSrgbToLinear(const gfx::Color3f& srgb_color)
3837
{
3938
ITT_FUNCTION_TASK();
4039

@@ -46,20 +45,20 @@ static gfx::Color3f TransformSRGBToLinear(const gfx::Color3f& srgb_color)
4645
return linear_color;
4746
}
4847

49-
static AsteroidColorSchema TransformSRGBToLinear(const AsteroidColorSchema& srgb_color_schema)
48+
static AsteroidColorSchema TransformSrgbToLinear(const AsteroidColorSchema& srgb_color_schema)
5049
{
5150
ITT_FUNCTION_TASK();
5251

5352
AsteroidColorSchema linear_color_schema = {};
5453
for (size_t i = 0; i < srgb_color_schema.size(); ++i)
5554
{
56-
linear_color_schema[i] = TransformSRGBToLinear(srgb_color_schema[i]);
55+
linear_color_schema[i] = TransformSrgbToLinear(srgb_color_schema[i]);
5756
}
5857
return linear_color_schema;
5958
}
6059

6160
Asteroid::Mesh::Mesh(uint32_t subdivisions_count, bool randomize)
62-
: gfx::IcosahedronMesh<Vertex>(VertexLayoutFromArray(Vertex::layout), 0.5f, subdivisions_count, true)
61+
: gfx::IcosahedronMesh<Vertex>(Mesh::VertexLayout(Vertex::layout), 0.5f, subdivisions_count, true)
6362
{
6463
ITT_FUNCTION_TASK();
6564

@@ -100,21 +99,21 @@ void Asteroid::Mesh::Randomize(uint32_t random_seed)
10099
ComputeAverageNormals();
101100
}
102101

103-
Asteroid::Asteroid(gfx::Context& context)
102+
Asteroid::Asteroid(gfx::RenderContext& context)
104103
: BaseBuffers(context, Mesh(3, true), "Asteroid")
105104
{
106105
ITT_FUNCTION_TASK();
107106

108107
SetTexture(GenerateTextureArray(context, gfx::Dimensions(256, 256), 1, true, TextureNoiseParameters()));
109108
}
110109

111-
gfx::Texture::Ptr Asteroid::GenerateTextureArray(gfx::Context& context, const gfx::Dimensions& dimensions, uint32_t array_size, bool mipmapped,
110+
Ptr<gfx::Texture> Asteroid::GenerateTextureArray(gfx::RenderContext& context, const gfx::Dimensions& dimensions, uint32_t array_size, bool mipmapped,
112111
const TextureNoiseParameters& noise_parameters)
113112
{
114113
ITT_FUNCTION_TASK();
115114

116115
const gfx::Resource::SubResources sub_resources = GenerateTextureArraySubresources(dimensions, array_size, noise_parameters);
117-
gfx::Texture::Ptr sp_texture_array = gfx::Texture::CreateImage(context, dimensions, array_size, gfx::PixelFormat::RGBA8Unorm, mipmapped);
116+
Ptr<gfx::Texture> sp_texture_array = gfx::Texture::CreateImage(context, dimensions, array_size, gfx::PixelFormat::RGBA8Unorm, mipmapped);
118117
sp_texture_array->SetData(sub_resources);
119118
return sp_texture_array;
120119
}
@@ -124,9 +123,9 @@ gfx::Resource::SubResources Asteroid::GenerateTextureArraySubresources(const gfx
124123
ITT_FUNCTION_TASK();
125124

126125
const gfx::PixelFormat pixel_format = gfx::PixelFormat::RGBA8Unorm;
127-
const uint32_t pixel_size = gfx::GetPixelSize(pixel_format);
128-
const uint32_t pixels_count = dimensions.GetPixelsCount();
129-
const uint32_t row_stide = pixel_size * dimensions.width;
126+
const uint32_t pixel_size = gfx::GetPixelSize(pixel_format);
127+
const uint32_t pixels_count = dimensions.GetPixelsCount();
128+
const uint32_t row_stride = pixel_size * dimensions.width;
130129

131130
gfx::Resource::SubResources sub_resources;
132131
sub_resources.reserve(array_size);
@@ -137,13 +136,11 @@ gfx::Resource::SubResources Asteroid::GenerateTextureArraySubresources(const gfx
137136
for (uint32_t array_index = 0; array_index < array_size; ++array_index)
138137
{
139138
Data::Bytes sub_resource_data(pixels_count * pixel_size, 255u);
140-
FillPerlinNoiseToTexture(sub_resource_data, dimensions,
141-
pixel_size, row_stide,
139+
FillPerlinNoiseToTexture(sub_resource_data, dimensions, row_stride,
142140
noise_seed_distribution(rng),
143141
noise_parameters.persistence,
144142
noise_parameters.scale,
145-
noise_parameters.strength,
146-
array_index);
143+
noise_parameters.strength);
147144

148145
sub_resources.emplace_back(std::move(sub_resource_data), gfx::Resource::SubResource::Index{ 0, array_index });
149146
}
@@ -163,7 +160,7 @@ Asteroid::Colors Asteroid::GetAsteroidRockColors(uint32_t deep_color_index, uint
163160
{ 88.f, 88.f, 88.f },
164161
{ 148.f, 108.f, 102.f },
165162
} };
166-
static const AsteroidColorSchema s_linear_deep_rock_colors = TransformSRGBToLinear(s_srgb_deep_rock_colors);
163+
static const AsteroidColorSchema s_linear_deep_rock_colors = TransformSrgbToLinear(s_srgb_deep_rock_colors);
167164

168165
static const AsteroidColorSchema s_srgb_shallow_rock_colors = { {
169166
{ 156.f, 139.f, 113.f },
@@ -173,7 +170,7 @@ Asteroid::Colors Asteroid::GetAsteroidRockColors(uint32_t deep_color_index, uint
173170
{ 153.f, 146.f, 136.f },
174171
{ 189.f, 181.f, 164.f },
175172
} };
176-
static const AsteroidColorSchema s_linear_shallow_rock_colors = TransformSRGBToLinear(s_srgb_shallow_rock_colors);
173+
static const AsteroidColorSchema s_linear_shallow_rock_colors = TransformSrgbToLinear(s_srgb_shallow_rock_colors);
177174

178175
if (deep_color_index >= s_linear_deep_rock_colors.size() || shallow_color_index >= s_linear_shallow_rock_colors.size())
179176
throw std::invalid_argument("Deep or shallow color indices are out of boundaries for asteroids color schema.");
@@ -193,7 +190,7 @@ Asteroid::Colors Asteroid::GetAsteroidIceColors(uint32_t deep_color_index, uint3
193190
{ 16.f, 66.f, 66.f },
194191
{ 48.f, 103.f, 147.f }
195192
} };
196-
static const AsteroidColorSchema s_linear_deep_ice_colors = TransformSRGBToLinear(s_srgb_deep_ice_colors);
193+
static const AsteroidColorSchema s_linear_deep_ice_colors = TransformSrgbToLinear(s_srgb_deep_ice_colors);
197194

198195
static const AsteroidColorSchema s_srgb_shallow_ice_colors = { {
199196
{ 199.f, 212.f, 244.f },
@@ -203,7 +200,7 @@ Asteroid::Colors Asteroid::GetAsteroidIceColors(uint32_t deep_color_index, uint3
203200
{ 167.f, 212.f, 239.f },
204201
{ 200.f, 221.f, 252.f }
205202
} };
206-
static const AsteroidColorSchema s_linear_shallow_ice_colors = TransformSRGBToLinear(s_srgb_shallow_ice_colors);
203+
static const AsteroidColorSchema s_linear_shallow_ice_colors = TransformSrgbToLinear(s_srgb_shallow_ice_colors);
207204

208205
if (deep_color_index >= s_linear_deep_ice_colors.size() || shallow_color_index >= s_linear_shallow_ice_colors.size())
209206
throw std::invalid_argument("Deep or shallow color indices are out of boundaries for asteroids color schema.");
@@ -222,7 +219,7 @@ Asteroid::Colors Asteroid::GetAsteroidLodColors(uint32_t lod_index)
222219
{ 128.f, 128.f, 0.f }, // LOD-4: yellow
223220
{ 128.f, 64.f, 0.f }, // LOD-5: orange
224221
} };
225-
static const AsteroidColorSchema s_linear_lod_deep_colors = TransformSRGBToLinear(s_srgb_lod_deep_colors);
222+
static const AsteroidColorSchema s_linear_lod_deep_colors = TransformSrgbToLinear(s_srgb_lod_deep_colors);
226223

227224
static const AsteroidColorSchema s_srgb_lod_shallow_colors = { {
228225
{ 0.f, 255.f, 0.f }, // LOD-0: green
@@ -232,16 +229,16 @@ Asteroid::Colors Asteroid::GetAsteroidLodColors(uint32_t lod_index)
232229
{ 255.f, 255.f, 0.f }, // LOD-4: yellow
233230
{ 255.f, 128.f, 0.f }, // LOD-5: orange
234231
} };
235-
static const AsteroidColorSchema s_linear_lod_shallow_colors = TransformSRGBToLinear(s_srgb_lod_shallow_colors);
232+
static const AsteroidColorSchema s_linear_lod_shallow_colors = TransformSrgbToLinear(s_srgb_lod_shallow_colors);
236233

237234
if (lod_index >= s_linear_lod_deep_colors.size() || lod_index >= s_linear_lod_shallow_colors.size())
238235
throw std::invalid_argument("LOD index is out of boundaries for asteroids color schema.");
239236

240237
return Asteroid::Colors{ s_linear_lod_deep_colors[lod_index], s_linear_lod_shallow_colors[lod_index] };
241238
}
242239

243-
void Asteroid::FillPerlinNoiseToTexture(Data::Bytes& texture_data, const gfx::Dimensions& dimensions, uint32_t pixel_size, uint32_t row_stride,
244-
float random_seed, float persistence, float noise_scale, float noise_strength, uint32_t array_index)
240+
void Asteroid::FillPerlinNoiseToTexture(Data::Bytes& texture_data, const gfx::Dimensions& dimensions, uint32_t row_stride,
241+
float random_seed, float persistence, float noise_scale, float noise_strength)
245242
{
246243
ITT_FUNCTION_TASK();
247244

@@ -259,12 +256,7 @@ void Asteroid::FillPerlinNoiseToTexture(Data::Bytes& texture_data, const gfx::Di
259256
uint8_t* texel_data = reinterpret_cast<uint8_t*>(&row_data[col]);
260257
for (size_t channel = 0; channel < 3; ++channel)
261258
{
262-
#if 1
263-
const float channel_value = 255.f;
264-
#else
265-
const float channel_value = array_index % 3 == channel ? 255.f : 125.f;
266-
#endif
267-
texel_data[channel] = static_cast<uint8_t>(channel_value * noise_intensity);
259+
texel_data[channel] = static_cast<uint8_t>(255.f * noise_intensity);
268260
}
269261
}
270262
}

Apps/Samples/Asteroids/Asteroid.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ Random generated asteroid model with mesh and texture ready for rendering.
2323

2424
#pragma once
2525

26-
#include <Methane/Graphics/Context.h>
26+
#include <Methane/Graphics/RenderContext.h>
2727
#include <Methane/Graphics/MathTypes.h>
2828
#include <Methane/Graphics/MeshBuffers.hpp>
29+
#include <Methane/Graphics/Mesh/IcosahedronMesh.hpp>
2930

3031
namespace Methane::Samples
3132
{
@@ -45,15 +46,14 @@ struct SHADER_STRUCT_ALIGN AsteroidUniforms
4546
class Asteroid final : public gfx::TexturedMeshBuffers<AsteroidUniforms>
4647
{
4748
public:
48-
using Ptr = std::unique_ptr<Asteroid>;
4949
using BaseBuffers = gfx::TexturedMeshBuffers<AsteroidUniforms>;
5050

5151
struct Vertex
5252
{
5353
gfx::Mesh::Position position;
5454
gfx::Mesh::Normal normal;
5555

56-
static constexpr const std::array<gfx::Mesh::VertexField, 2> layout = {
56+
inline static const gfx::Mesh::VertexLayout layout = {
5757
gfx::Mesh::VertexField::Position,
5858
gfx::Mesh::VertexField::Normal,
5959
};
@@ -101,9 +101,9 @@ class Asteroid final : public gfx::TexturedMeshBuffers<AsteroidUniforms>
101101
float strength = 1.5f;
102102
};
103103

104-
Asteroid(gfx::Context& context);
104+
explicit Asteroid(gfx::RenderContext& context);
105105

106-
static gfx::Texture::Ptr GenerateTextureArray(gfx::Context& context, const gfx::Dimensions& dimensions, uint32_t array_size, bool mipmapped, const TextureNoiseParameters& noise_parameters);
106+
static Ptr<gfx::Texture> GenerateTextureArray(gfx::RenderContext& context, const gfx::Dimensions& dimensions, uint32_t array_size, bool mipmapped, const TextureNoiseParameters& noise_parameters);
107107
static gfx::Resource::SubResources GenerateTextureArraySubresources(const gfx::Dimensions& dimensions, uint32_t array_size, const TextureNoiseParameters& noise_parameters);
108108

109109
static constexpr size_t color_schema_size = 6u;
@@ -112,8 +112,8 @@ class Asteroid final : public gfx::TexturedMeshBuffers<AsteroidUniforms>
112112
static Colors GetAsteroidLodColors(uint32_t lod_index);
113113

114114
private:
115-
static void FillPerlinNoiseToTexture(Data::Bytes& texture_data, const gfx::Dimensions& dimensions, uint32_t pixel_size, uint32_t row_stride,
116-
float random_seed, float persistence, float noise_scale, float noise_strength, uint32_t array_index);
115+
static void FillPerlinNoiseToTexture(Data::Bytes& texture_data, const gfx::Dimensions& dimensions, uint32_t row_stride,
116+
float random_seed, float persistence, float noise_scale, float noise_strength);
117117
};
118118

119119
} // namespace Methane::Samples

0 commit comments

Comments
 (0)