Apply a random seed when NOT in benchmark mode to have 100% deterministic runs in all samples (#1127)
* Apply a random seed when NOT in benchmark mode to have 100% deterministic runs These samples lack the check for benchmark.active when applying a random seed, which is done for other samples. * Update texture3d.cpp
This commit is contained in:
parent
478b6c39bf
commit
3d4446fa15
6 changed files with 26 additions and 27 deletions
|
|
@ -96,7 +96,7 @@ public:
|
||||||
textures.resize(32);
|
textures.resize(32);
|
||||||
for (size_t i = 0; i < textures.size(); i++) {
|
for (size_t i = 0; i < textures.size(); i++) {
|
||||||
std::random_device rndDevice;
|
std::random_device rndDevice;
|
||||||
std::default_random_engine rndEngine(rndDevice());
|
std::default_random_engine rndEngine(benchmark.active ? 0 : rndDevice());
|
||||||
std::uniform_int_distribution<> rndDist(50, UCHAR_MAX);
|
std::uniform_int_distribution<> rndDist(50, UCHAR_MAX);
|
||||||
const int32_t dim = 3;
|
const int32_t dim = 3;
|
||||||
const size_t bufferSize = dim * dim * 4;
|
const size_t bufferSize = dim * dim * 4;
|
||||||
|
|
@ -119,7 +119,7 @@ public:
|
||||||
|
|
||||||
// Generate random per-face texture indices
|
// Generate random per-face texture indices
|
||||||
std::random_device rndDevice;
|
std::random_device rndDevice;
|
||||||
std::default_random_engine rndEngine(rndDevice());
|
std::default_random_engine rndEngine(benchmark.active ? 0 : rndDevice());
|
||||||
std::uniform_int_distribution<int32_t> rndDist(0, static_cast<uint32_t>(textures.size()) - 1);
|
std::uniform_int_distribution<int32_t> rndDist(0, static_cast<uint32_t>(textures.size()) - 1);
|
||||||
|
|
||||||
// Generate cubes with random per-face texture indices
|
// Generate cubes with random per-face texture indices
|
||||||
|
|
|
||||||
|
|
@ -374,7 +374,7 @@ public:
|
||||||
shaderStageCI.pName = "main";
|
shaderStageCI.pName = "main";
|
||||||
|
|
||||||
// Select lighting model using a specialization constant
|
// Select lighting model using a specialization constant
|
||||||
srand((unsigned int)time(NULL));
|
srand(benchmark.active ? 0 : ((unsigned int)time(NULL)));
|
||||||
uint32_t lighting_model = (int)(rand() % 4);
|
uint32_t lighting_model = (int)(rand() % 4);
|
||||||
|
|
||||||
// Each shader constant of a shader stage corresponds to one map entry
|
// Each shader constant of a shader stage corresponds to one map entry
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,9 @@ public:
|
||||||
float ambient;
|
float ambient;
|
||||||
} material;
|
} material;
|
||||||
VkDescriptorSet descriptorSet;
|
VkDescriptorSet descriptorSet;
|
||||||
void setRandomMaterial() {
|
void setRandomMaterial(bool applyRandomSeed) {
|
||||||
std::random_device rndDevice;
|
std::random_device rndDevice;
|
||||||
std::default_random_engine rndEngine(rndDevice());
|
std::default_random_engine rndEngine(applyRandomSeed ? rndDevice() : 0);
|
||||||
std::uniform_real_distribution<float> rndDist(0.1f, 1.0f);
|
std::uniform_real_distribution<float> rndDist(0.1f, 1.0f);
|
||||||
material.r = rndDist(rndEngine);
|
material.r = rndDist(rndEngine);
|
||||||
material.g = rndDist(rndEngine);
|
material.g = rndDist(rndEngine);
|
||||||
|
|
@ -161,7 +161,7 @@ public:
|
||||||
|
|
||||||
// Setup random materials for every object in the scene
|
// Setup random materials for every object in the scene
|
||||||
for (uint32_t i = 0; i < objects.size(); i++) {
|
for (uint32_t i = 0; i < objects.size(); i++) {
|
||||||
objects[i].setRandomMaterial();
|
objects[i].setRandomMaterial(!benchmark.active);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -342,7 +342,7 @@ public:
|
||||||
void updateMaterials() {
|
void updateMaterials() {
|
||||||
// Setup random materials for every object in the scene
|
// Setup random materials for every object in the scene
|
||||||
for (uint32_t i = 0; i < objects.size(); i++) {
|
for (uint32_t i = 0; i < objects.size(); i++) {
|
||||||
objects[i].setRandomMaterial();
|
objects[i].setRandomMaterial(!benchmark.active);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &object : objects) {
|
for (auto &object : objects) {
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ public:
|
||||||
{
|
{
|
||||||
// Setup random colors and fixed positions for every sphere in the scene
|
// Setup random colors and fixed positions for every sphere in the scene
|
||||||
std::random_device rndDevice;
|
std::random_device rndDevice;
|
||||||
std::default_random_engine rndEngine(rndDevice());
|
std::default_random_engine rndEngine(benchmark.active ? 0 : rndDevice());
|
||||||
std::uniform_real_distribution<float> rndDist(0.1f, 1.0f);
|
std::uniform_real_distribution<float> rndDist(0.1f, 1.0f);
|
||||||
for (uint32_t i = 0; i < spheres.size(); i++) {
|
for (uint32_t i = 0; i < spheres.size(); i++) {
|
||||||
spheres[i].color = glm::vec4(rndDist(rndEngine), rndDist(rndEngine), rndDist(rndEngine), 1.0f);
|
spheres[i].color = glm::vec4(rndDist(rndEngine), rndDist(rndEngine), rndDist(rndEngine), 1.0f);
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,13 @@ private:
|
||||||
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
|
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
PerlinNoise()
|
PerlinNoise(bool applyRandomSeed)
|
||||||
{
|
{
|
||||||
// Generate random lookup for permutations containing all numbers from 0..255
|
// Generate random lookup for permutations containing all numbers from 0..255
|
||||||
std::vector<uint8_t> plookup;
|
std::vector<uint8_t> plookup;
|
||||||
plookup.resize(256);
|
plookup.resize(256);
|
||||||
std::iota(plookup.begin(), plookup.end(), 0);
|
std::iota(plookup.begin(), plookup.end(), 0);
|
||||||
std::default_random_engine rndEngine(std::random_device{}());
|
std::default_random_engine rndEngine(applyRandomSeed ? std::random_device{}() : 0);
|
||||||
std::shuffle(plookup.begin(), plookup.end(), rndEngine);
|
std::shuffle(plookup.begin(), plookup.end(), rndEngine);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 256; i++)
|
for (uint32_t i = 0; i < 256; i++)
|
||||||
|
|
@ -89,16 +89,15 @@ template <typename T>
|
||||||
class FractalNoise
|
class FractalNoise
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
PerlinNoise<float> perlinNoise;
|
PerlinNoise<T> perlinNoise;
|
||||||
uint32_t octaves;
|
uint32_t octaves;
|
||||||
T frequency;
|
T frequency;
|
||||||
T amplitude;
|
T amplitude;
|
||||||
T persistence;
|
T persistence;
|
||||||
public:
|
public:
|
||||||
|
FractalNoise(const PerlinNoise<T> &perlinNoiseIn) :
|
||||||
FractalNoise(const PerlinNoise<T> &perlinNoise)
|
perlinNoise(perlinNoiseIn)
|
||||||
{
|
{
|
||||||
this->perlinNoise = perlinNoise;
|
|
||||||
octaves = 6;
|
octaves = 6;
|
||||||
persistence = (T)0.5;
|
persistence = (T)0.5;
|
||||||
}
|
}
|
||||||
|
|
@ -166,7 +165,7 @@ public:
|
||||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -2.5f));
|
camera.setPosition(glm::vec3(0.0f, 0.0f, -2.5f));
|
||||||
camera.setRotation(glm::vec3(0.0f, 15.0f, 0.0f));
|
camera.setRotation(glm::vec3(0.0f, 15.0f, 0.0f));
|
||||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
||||||
srand((unsigned int)time(NULL));
|
srand(benchmark.active ? 0 : (unsigned int)time(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
~VulkanExample()
|
~VulkanExample()
|
||||||
|
|
@ -287,7 +286,7 @@ public:
|
||||||
|
|
||||||
auto tStart = std::chrono::high_resolution_clock::now();
|
auto tStart = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
PerlinNoise<float> perlinNoise;
|
PerlinNoise<float> perlinNoise(!benchmark.active);
|
||||||
FractalNoise<float> fractalNoise(perlinNoise);
|
FractalNoise<float> fractalNoise(perlinNoise);
|
||||||
|
|
||||||
const float noiseScale = static_cast<float>(rand() % 10) + 4.0f;
|
const float noiseScale = static_cast<float>(rand() % 10) + 4.0f;
|
||||||
|
|
|
||||||
|
|
@ -714,7 +714,7 @@ void VulkanExample::fillRandomPages()
|
||||||
{
|
{
|
||||||
vkDeviceWaitIdle(device);
|
vkDeviceWaitIdle(device);
|
||||||
|
|
||||||
std::default_random_engine rndEngine(std::random_device{}());
|
std::default_random_engine rndEngine(benchmark.active ? 0 : std::random_device{}());
|
||||||
std::uniform_real_distribution<float> rndDist(0.0f, 1.0f);
|
std::uniform_real_distribution<float> rndDist(0.0f, 1.0f);
|
||||||
|
|
||||||
std::vector<VirtualTexturePage> updatedPages;
|
std::vector<VirtualTexturePage> updatedPages;
|
||||||
|
|
@ -810,7 +810,7 @@ void VulkanExample::flushRandomPages()
|
||||||
{
|
{
|
||||||
vkDeviceWaitIdle(device);
|
vkDeviceWaitIdle(device);
|
||||||
|
|
||||||
std::default_random_engine rndEngine(std::random_device{}());
|
std::default_random_engine rndEngine(benchmark.active ? 0 : std::random_device{}());
|
||||||
std::uniform_real_distribution<float> rndDist(0.0f, 1.0f);
|
std::uniform_real_distribution<float> rndDist(0.0f, 1.0f);
|
||||||
|
|
||||||
std::vector<VirtualTexturePage> updatedPages;
|
std::vector<VirtualTexturePage> updatedPages;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue