Make random number usage platform independent
authorAri Suonpaa <ari.suonpaa@siru.fi>
Tue, 23 Apr 2019 11:57:47 +0000 (14:57 +0300)
committerChris Forbes <chrisforbes@google.com>
Sat, 3 Aug 2019 17:04:57 +0000 (13:04 -0400)
Generating multiple random numbers in argument
list can happen in different order depending on
implementation. This change makes these happen
in the same order with all implementations.

Affects:

dEQP-VK.api.granularity.*
dEQP-VK.draw.basic_draw.*
dEQP-VK.protected_memory.*
dEQP-VK.glsl.builtin.function.common.*
dEQP-VK.glsl.builtin.function.pack_unpack.*
dEQP-VK.glsl.texture_gather.*
dEQP-VK.spirv_assembly.*
dEQP-GLES3*.functional.shaders.builtin_functions.common.*

Components: Vulkan, OpenGL, Framework

(cherry picked from commit 0106f01209fe7abb7f4daf029318a1de17844c48)

VK-GL-CTS issue: 1591

Change-Id: Iaaff9625fd331ed7184efd50b89fc835c701ac6f

25 files changed:
external/vulkancts/framework/vulkan/vkTypeUtil.hpp
external/vulkancts/modules/vulkan/api/vktApiGranularityTests.cpp
external/vulkancts/modules/vulkan/draw/vktBasicDrawTests.cpp
external/vulkancts/modules/vulkan/protected_memory/vktProtectedMemAttachmentClearTests.cpp
external/vulkancts/modules/vulkan/protected_memory/vktProtectedMemAttachmentLoadTests.cpp
external/vulkancts/modules/vulkan/protected_memory/vktProtectedMemBlitImageTests.cpp
external/vulkancts/modules/vulkan/protected_memory/vktProtectedMemClearColorImageTests.cpp
external/vulkancts/modules/vulkan/protected_memory/vktProtectedMemCopyBufferToImageTests.cpp
external/vulkancts/modules/vulkan/protected_memory/vktProtectedMemCopyImageTests.cpp
external/vulkancts/modules/vulkan/protected_memory/vktProtectedMemCopyImageToBufferTests.cpp
external/vulkancts/modules/vulkan/protected_memory/vktProtectedMemFillUpdateCopyBufferTests.cpp
external/vulkancts/modules/vulkan/protected_memory/vktProtectedMemStorageBufferTests.cpp
external/vulkancts/modules/vulkan/shaderexecutor/vktShaderCommonFunctionTests.cpp
external/vulkancts/modules/vulkan/shaderexecutor/vktShaderPackingFunctionTests.cpp
external/vulkancts/modules/vulkan/shaderrender/vktShaderRenderTextureGatherTests.cpp
external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmGraphicsShaderTestUtil.hpp
external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmImageSamplerTests.cpp
external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmIndexingTests.cpp
external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmInstructionTests.cpp
external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmUboMatrixPaddingTests.cpp
external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmVariablePointersTests.cpp
framework/common/tcuVectorUtil.hpp
framework/delibs/decpp/deRandom.hpp
modules/gles3/functional/es3fShaderCommonFunctionTests.cpp
modules/gles31/functional/es31fShaderCommonFunctionTests.cpp

index a3ccad4..b3ae6c0 100644 (file)
@@ -41,6 +41,11 @@ inline VkClearValue makeClearValueColorF32 (float r, float g, float b, float a)
        return v;
 }
 
+inline VkClearValue makeClearValueColorVec4 (tcu::Vec4 vec)
+{
+       return makeClearValueColorF32(vec.x(), vec.y(), vec.z(), vec.w());
+}
+
 inline VkClearValue makeClearValueColorU32 (deUint32 r, deUint32 g, deUint32 b, deUint32 a)
 {
        VkClearValue v;
index 8d3ea4d..33f298c 100644 (file)
@@ -463,30 +463,43 @@ tcu::TestCaseGroup* createGranularityQueryTests (tcu::TestContext& testCtx)
 
                {
                        std::vector<AttachmentInfo>     attachments;
-                       attachments.push_back(AttachmentInfo(format, rnd.getInt(1, maxDimension), rnd.getInt(1, maxDimension), 1));
+                       const int                                       i0                              = rnd.getInt(1, maxDimension);
+                       const int                                       i1                              = rnd.getInt(1, maxDimension);
+                       attachments.push_back(AttachmentInfo(format, i0, i1, 1));
                        single->addChild(new GranularityCase(testCtx, name.c_str(), description, attachments));
                }
 
                {
                        std::vector<AttachmentInfo>     attachments;
-                       deUint32        iterations      = rnd.getInt(minIteration, maxIteration);
+                       const deUint32                          iterations              = rnd.getInt(minIteration, maxIteration);
+                       const int                                       i0                              = rnd.getInt(1, maxDimension);
+                       const int                                       i1                              = rnd.getInt(1, maxDimension);
                        for (deUint32 idx = 0; idx < iterations; ++idx)
-                               attachments.push_back(AttachmentInfo(VkFormat(formatIdx), rnd.getInt(1, maxDimension), rnd.getInt(1, maxDimension), 1));
+                               attachments.push_back(AttachmentInfo(VkFormat(formatIdx), i0, i1, 1));
                        multi->addChild(new GranularityCase(testCtx, name.c_str(), description, attachments));
                }
 
                {
                        std::vector<AttachmentInfo>     attachments;
-                       deUint32        iterations      = rnd.getInt(minIteration, maxIteration);
-                       attachments.push_back(AttachmentInfo(VkFormat(formatIdx), rnd.getInt(1, maxDimension), rnd.getInt(1, maxDimension), 1));
+                       const deUint32                          iterations              = rnd.getInt(minIteration, maxIteration);
+                       const int                                       i0                              = rnd.getInt(1, maxDimension);
+                       const int                                       i1                              = rnd.getInt(1, maxDimension);
+                       attachments.push_back(AttachmentInfo(VkFormat(formatIdx), i0, i1, 1));
                        for (deUint32 idx = 0; idx < iterations; ++idx)
-                               attachments.push_back(AttachmentInfo(mandatoryFormats[rnd.getInt(0, DE_LENGTH_OF_ARRAY(mandatoryFormats) - 1)], rnd.getInt(1, maxDimension), rnd.getInt(1, maxDimension), 1));
+                       {
+                               const int       i2      = rnd.getInt(0, DE_LENGTH_OF_ARRAY(mandatoryFormats) - 1);
+                               const int       i3      = rnd.getInt(1, maxDimension);
+                               const int       i4      = rnd.getInt(1, maxDimension);
+                               attachments.push_back(AttachmentInfo(mandatoryFormats[i2], i3, i4, 1));
+                       }
                        random->addChild(new GranularityCase(testCtx, name.c_str(), description, attachments));
                }
 
                {
                        std::vector<AttachmentInfo>     attachments;
-                       attachments.push_back(AttachmentInfo(format, rnd.getInt(1, maxDimension), rnd.getInt(1, maxDimension), 1));
+                       const int                                       i0                              = rnd.getInt(1, maxDimension);
+                       const int                                       i1                              = rnd.getInt(1, maxDimension);
+                       attachments.push_back(AttachmentInfo(format, i0, i1, 1));
                        inRenderPass->addChild(new GranularityCase(testCtx, name.c_str(), description, attachments, true));
                }
        }
index 8cc14ba..fc2de92 100644 (file)
@@ -38,6 +38,7 @@
 #include "tcuRGBA.hpp"
 #include "tcuTextureUtil.hpp"
 #include "tcuImageCompare.hpp"
+#include "tcuVectorUtil.hpp"
 
 #include "rrRenderer.hpp"
 
@@ -631,9 +632,12 @@ void DrawTestInstance<DrawParams>::generateDrawData (void)
        // Fill only the used indexes
        for (deUint32 vertexIdx = m_data.params.firstVertex; vertexIdx < vectorSize; ++vertexIdx)
        {
+               const float f0 = rnd.getFloat(-1.0f, 1.0f);
+               const float f1 = rnd.getFloat(-1.0f, 1.0f);
+
                m_data.vertices[vertexIdx] = PositionColorVertex(
-                       tcu::Vec4(rnd.getFloat(-1.0, 1.0), rnd.getFloat(-1.0, 1.0), 1.0, 1.0),                                                                          // Coord
-                       tcu::Vec4(rnd.getFloat(0.0, 1.0), rnd.getFloat(0.0, 1.0), rnd.getFloat(0.0, 1.0), rnd.getFloat(0.0, 1.0)));     // Color
+                       tcu::Vec4(f0, f1, 1.0f, 1.0f),  // Coord
+                       tcu::randomVec4(rnd));                  // Color
        }
 }
 
@@ -712,10 +716,12 @@ void DrawTestInstance<DrawIndexedParams>::generateDrawData (void)
                std::vector<PositionColorVertex>::iterator vertexIt = m_data.vertices.begin() + m_data.params.vertexOffset + *indexIt;
 
                tcu::VecAccess<float, 4, 4>     positionAccess = vertexIt->position.xyzw();
-               positionAccess = tcu::Vec4(rnd.getFloat(-1.0, 1.0), rnd.getFloat(-1.0, 1.0), 1.0, 1.0);
+               const float f0 = rnd.getFloat(-1.0f, 1.0f);
+               const float f1 = rnd.getFloat(-1.0f, 1.0f);
+               positionAccess = tcu::Vec4(f0, f1, 1.0f, 1.0f);
 
                tcu::VecAccess<float, 4, 4>     colorAccess = vertexIt->color.xyzw();
-               colorAccess = tcu::Vec4(rnd.getFloat(0.0, 1.0), rnd.getFloat(0.0, 1.0), rnd.getFloat(0.0, 1.0), rnd.getFloat(0.0, 1.0));
+               colorAccess = tcu::randomVec4(rnd);
        }
 }
 
@@ -825,10 +831,12 @@ void DrawTestInstance<DrawIndirectParams>::generateDrawData (void)
                        std::vector<PositionColorVertex>::iterator vertexIt = vertexStart + idx;
 
                        tcu::VecAccess<float, 4, 4> positionAccess = vertexIt->position.xyzw();
-                       positionAccess = tcu::Vec4(rnd.getFloat(-1.0, 1.0), rnd.getFloat(-1.0, 1.0), 1.0, 1.0);
+                       const float f0 = rnd.getFloat(-1.0f, 1.0f);
+                       const float f1 = rnd.getFloat(-1.0f, 1.0f);
+                       positionAccess = tcu::Vec4(f0, f1, 1.0f, 1.0f);
 
                        tcu::VecAccess<float, 4, 4> colorAccess = vertexIt->color.xyzw();
-                       colorAccess = tcu::Vec4(rnd.getFloat(0.0, 1.0), rnd.getFloat(0.0, 1.0), rnd.getFloat(0.0, 1.0), rnd.getFloat(0.0, 1.0));
+                       colorAccess = tcu::randomVec4(rnd);
                }
        }
 }
@@ -976,10 +984,12 @@ void DrawTestInstance<DrawIndexedIndirectParams>::generateDrawData (void)
                        std::vector<PositionColorVertex>::iterator      vertexIt = m_data.vertices.begin() + cmdIt->vertexOffset + m_data.indexes[idx];
 
                        tcu::VecAccess<float, 4, 4> positionAccess = vertexIt->position.xyzw();
-                       positionAccess = tcu::Vec4(rnd.getFloat(-1.0, 1.0), rnd.getFloat(-1.0, 1.0), 1.0, 1.0);
+                       const float f0 = rnd.getFloat(-1.0f, 1.0f);
+                       const float f1 = rnd.getFloat(-1.0f, 1.0f);
+                       positionAccess = tcu::Vec4(f0, f1, 1.0f, 1.0f);
 
                        tcu::VecAccess<float, 4, 4> colorAccess = vertexIt->color.xyzw();
-                       colorAccess = tcu::Vec4(rnd.getFloat(0.0, 1.0), rnd.getFloat(0.0, 1.0), rnd.getFloat(0.0, 1.0), rnd.getFloat(0.0, 1.0));
+                       colorAccess = tcu::randomVec4(rnd);
                }
        }
 }
index fd0a0be..cb6eb6c 100644 (file)
@@ -27,6 +27,7 @@
 #include "deRandom.hpp"
 #include "tcuTestLog.hpp"
 #include "tcuVector.hpp"
+#include "tcuVectorUtil.hpp"
 
 #include "vkPrograms.hpp"
 #include "vktTestCase.hpp"
@@ -356,19 +357,16 @@ tcu::TestCaseGroup*       createAttachmentClearTests (tcu::TestContext& testCtx, CmdBu
        for (int ndx = 0; ndx < testCount; ++ndx)
        {
                const std::string       name            = "clear_" +  de::toString(ndx + 1);
-               vk::VkClearValue        clearValue      = vk::makeClearValueColorF32(
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f));
+               vk::VkClearValue        clearValue      = vk::makeClearValueColorVec4(tcu::randomVec4(rnd));
+               const tcu::Vec4         refValue        (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
+               const tcu::Vec4         vec0            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec1            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec2            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec3            = tcu::randomVec4(rnd);
 
-               tcu::Vec4                       refValue        (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
                ValidationData          data            =
                {
-                       { tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)) },
+                       { vec0, vec1, vec2, vec3 },
                        { refValue, refValue, refValue, refValue }
                };
 
index 66ae052..cf3a45f 100644 (file)
@@ -27,6 +27,7 @@
 #include "deRandom.hpp"
 #include "tcuTestLog.hpp"
 #include "tcuVector.hpp"
+#include "tcuVectorUtil.hpp"
 
 #include "vkPrograms.hpp"
 #include "vktTestCase.hpp"
@@ -300,18 +301,15 @@ tcu::TestCaseGroup*       createAttachmentLoadTests (tcu::TestContext& testCtx)
        for (int ndx = 0; ndx < testCount; ++ndx)
        {
                const std::string       name            = "clear_" + de::toString(ndx + 1);
-               vk::VkClearValue        clearValue      = vk::makeClearValueColorF32(
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f));
+               vk::VkClearValue        clearValue      = vk::makeClearValueColorVec4(tcu::randomVec4(rnd));
+               const tcu::Vec4         refValue        (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
+               const tcu::Vec4         vec0            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec1            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec2            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec3            = tcu::randomVec4(rnd);
 
-               tcu::Vec4                       refValue        (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
                ValidationData          data = {
-                       { tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)) },
+                       { vec0, vec1, vec2, vec3 },
                        { refValue, refValue, refValue, refValue }
                };
 
index b3091f8..1568031 100644 (file)
@@ -27,6 +27,7 @@
 #include "deRandom.hpp"
 #include "tcuTestLog.hpp"
 #include "tcuVector.hpp"
+#include "tcuVectorUtil.hpp"
 
 #include "vkPrograms.hpp"
 #include "vktTestCase.hpp"
@@ -425,19 +426,16 @@ tcu::TestCaseGroup*       createBlitImageTests (tcu::TestContext& testCtx, CmdBufferTy
        for (int ndx = 0; ndx < testCount; ++ndx)
        {
                const std::string       name            = "blit_" + de::toString(ndx + 1);
-               vk::VkClearValue        clearValue      = vk::makeClearValueColorF32(
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f));
+               vk::VkClearValue        clearValue      = vk::makeClearValueColorVec4(tcu::randomVec4(rnd));
+               const tcu::Vec4         refValue        (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
+               const tcu::Vec4         vec0            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec1            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec2            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec3            = tcu::randomVec4(rnd);
 
-               tcu::Vec4                       refValue        (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
                ValidationData          data            =
                {
-                       { tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)) },
+                       { vec0, vec1, vec2, vec3 },
                        { refValue, refValue, refValue, refValue }
                };
                blitRandomTests->addChild(new BlitImageTestCase(testCtx, name.c_str(), clearValue.color, data, cmdBufferType));
index 86b8ba0..823a7b7 100644 (file)
@@ -27,6 +27,7 @@
 #include "deRandom.hpp"
 #include "tcuTestLog.hpp"
 #include "tcuVector.hpp"
+#include "tcuVectorUtil.hpp"
 
 #include "vkPrograms.hpp"
 #include "vktTestCase.hpp"
@@ -318,19 +319,16 @@ tcu::TestCaseGroup*       createClearColorImageTests (tcu::TestContext& testCtx, CmdBu
        for (int ndx = 0; ndx < testCount; ++ndx)
        {
                const std::string       name            = "clear_" + de::toString(ndx + 1);
-               vk::VkClearValue        clearValue      = vk::makeClearValueColorF32(
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f));
+               vk::VkClearValue        clearValue      = vk::makeClearValueColorVec4(tcu::randomVec4(rnd));
+               const tcu::Vec4         refValue        (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
+               const tcu::Vec4         vec0            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec1            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec2            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec3            = tcu::randomVec4(rnd);
 
-               tcu::Vec4                       refValue        (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
                ValidationData          data            =
                {
-                       { tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)) },
+                       { vec0, vec1, vec2, vec3 },
                        { refValue, refValue, refValue, refValue }
                };
                clearRandomTests->addChild(new ClearColorImageTestCase(testCtx, name.c_str(), clearValue.color, data, cmdBufferType));
index 3c56960..c93db6d 100644 (file)
@@ -27,6 +27,7 @@
 #include "deRandom.hpp"
 #include "tcuTestLog.hpp"
 #include "tcuVector.hpp"
+#include "tcuVectorUtil.hpp"
 
 #include "vkPrograms.hpp"
 #include "vktTestCase.hpp"
@@ -386,13 +387,15 @@ tcu::TestCaseGroup*       createCopyBufferToImageTests (tcu::TestContext& testCtx, Cmd
                        deUint32        uint;
                }                                       fillValue       = { rnd.getFloat(0.0, 1.0f) };
 
-               tcu::Vec4                       refValue        (fillValue.flt);
+               const tcu::Vec4         refValue        (fillValue.flt);
+               const tcu::Vec4         vec0            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec1            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec2            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec3            = tcu::randomVec4(rnd);
+
                ValidationData          data            =
                {
-                       { tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)) },
+                       { vec0, vec1, vec2, vec3 },
                        { refValue, refValue, refValue, refValue }
                };
                copyRandomTests->addChild(new CopyBufferToImageTestCase(testCtx, name.c_str(), fillValue.uint, data, cmdBufferType));
index 769897c..85b4635 100644 (file)
@@ -27,6 +27,7 @@
 #include "deRandom.hpp"
 #include "tcuTestLog.hpp"
 #include "tcuVector.hpp"
+#include "tcuVectorUtil.hpp"
 
 #include "vkPrograms.hpp"
 #include "vktTestCase.hpp"
@@ -423,19 +424,16 @@ tcu::TestCaseGroup*       createCopyImageTests (tcu::TestContext& testCtx, CmdBufferTy
        for (int ndx = 0; ndx < testCount; ++ndx)
        {
                const std::string       name            = "copy_" + de::toString(ndx + 1);
-               vk::VkClearValue        clearValue      = vk::makeClearValueColorF32(
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f));
+               vk::VkClearValue        clearValue      = vk::makeClearValueColorVec4(tcu::randomVec4(rnd));
+               const tcu::Vec4         refValue        (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
+               const tcu::Vec4         vec0            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec1            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec2            = tcu::randomVec4(rnd);
+               const tcu::Vec4         vec3            = tcu::randomVec4(rnd);
 
-               tcu::Vec4                       refValue        (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
                ValidationData          data            =
                {
-                       { tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
-                         tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)) },
+                       { vec0, vec1, vec2, vec3 },
                        { refValue, refValue, refValue, refValue }
                };
                copyRandomTests->addChild(new CopyImageTestCase(testCtx, name.c_str(), clearValue.color, data, cmdBufferType));
index 2783273..4afde53 100644 (file)
@@ -27,6 +27,7 @@
 #include "deRandom.hpp"
 #include "tcuTestLog.hpp"
 #include "tcuVector.hpp"
+#include "tcuVectorUtil.hpp"
 
 #include "vkPrograms.hpp"
 #include "vktTestCase.hpp"
@@ -371,19 +372,16 @@ tcu::TestCaseGroup*       createCopyImageToFloatBufferTests(tcu::TestContext& testCtx,
        for (int ndx = 0; ndx < testCount; ++ndx)
        {
                const std::string       name            = "copy_" + de::toString(ndx + 1);
-               vk::VkClearValue        clearValue      = vk::makeClearValueColorF32(
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f),
-                                                                                       rnd.getFloat(0.0, 1.0f));
+               vk::VkClearValue        clearValue      = vk::makeClearValueColorVec4(tcu::randomVec4(rnd));
+               const tcu::Vec4         refValue        (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
+               const tcu::IVec4        vec0            = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+               const tcu::IVec4        vec1            = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+               const tcu::IVec4        vec2            = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+               const tcu::IVec4        vec3            = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
 
-               tcu::Vec4                       refValue        (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
                ValidationDataVec4      data            =
                {
-                       { tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)),
-                         tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)),
-                         tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)),
-                         tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)) },
+                       { vec0, vec1, vec2, vec3 },
                        { refValue, refValue, refValue, refValue }
                };
 
index fb8c89d..4616b04 100644 (file)
@@ -369,13 +369,15 @@ tcu::TestCaseGroup*       createFillUpdateCopyBufferFloatTests (tcu::TestContext& test
                        deUint32        uint;
                }                                       fillValue       = { rnd.getFloat(std::numeric_limits<float>::min(), std::numeric_limits<float>::max() - 1) };
 
-               tcu::Vec4                       refValue        (fillValue.flt);
+               const tcu::Vec4         refValue        (fillValue.flt);
+               const tcu::IVec4        vec0            = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+               const tcu::IVec4        vec1            = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+               const tcu::IVec4        vec2            = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+               const tcu::IVec4        vec3            = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+
                ValidationDataVec4      data            =
                {
-                       { tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)),
-                         tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)),
-                         tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)),
-                         tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)) },
+                       { vec0, vec1, vec2, vec3 },
                        { refValue, refValue, refValue, refValue }
                };
 
@@ -478,13 +480,15 @@ tcu::TestCaseGroup*       createFillUpdateCopyBufferIntegerTests (tcu::TestContext& te
                        deUint32        uint;
                }                                       fillValue       = { rnd.getInt(std::numeric_limits<deInt32>::min(), std::numeric_limits<deInt32>::max() - 1) };
 
-               tcu::IVec4                      refValue        (fillValue.integer);
+               const tcu::IVec4        refValue        (fillValue.integer);
+               const tcu::IVec4        v0                      = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+               const tcu::IVec4        v1                      = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+               const tcu::IVec4        v2                      = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+               const tcu::IVec4        v3                      = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+
                ValidationDataIVec4     data            =
                {
-                       { tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)),
-                         tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)),
-                         tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)),
-                         tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)) },
+                       { v0, v1, v2, v3 },
                        { refValue, refValue, refValue, refValue }
                };
 
@@ -579,14 +583,16 @@ tcu::TestCaseGroup*       createFillUpdateCopyBufferUnsignedTests (tcu::TestContext& t
        for (int ndx = 0; ndx < testCount; ++ndx)
        {
                const std::string       name            = "test_" + de::toString(ndx + 1);
-               deUint32                        fillValue       = rnd.getUint32();
-               tcu::UVec4                      refValue        (fillValue);
+               const deUint32          fillValue       = rnd.getUint32();
+               const tcu::UVec4        refValue        (fillValue);
+               const tcu::IVec4        v0                      = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+               const tcu::IVec4        v1                      = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+               const tcu::IVec4        v2                      = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+               const tcu::IVec4        v3                      = tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1));
+
                ValidationDataUVec4     data            =
                {
-                       { tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)),
-                         tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)),
-                         tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)),
-                         tcu::IVec4(rnd.getInt(0, MAX_POSITION - 1)) },
+                       { v0, v1, v2, v3 },
                        { refValue, refValue, refValue, refValue }
                };
 
index 43bbdeb..a0b93e0 100644 (file)
@@ -694,7 +694,8 @@ tcu::TestCaseGroup* createRandomizedBufferTests (tcu::TestContext& testCtx, SSBO
        testData.resize(testCount);
 
        for (size_t ndx = 0; ndx < testCount; ++ndx)
-               testData[ndx].values = tcu::UVec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32());
+               for (deUint32 compIdx = 0; compIdx < 4; ++compIdx)
+                       testData[ndx].values[compIdx] = rnd.getUint32();
 
        return createSpecifiedStorageBufferTests(testCtx, "random", testType, shaderType, testData.data(), testData.size());
 }
index 33a44de..0e72b78 100644 (file)
@@ -31,6 +31,7 @@
 #include "tcuFloat.hpp"
 #include "tcuInterval.hpp"
 #include "tcuFloatFormat.hpp"
+#include "tcuVectorUtil.hpp"
 #include "deRandom.hpp"
 #include "deMath.h"
 #include "deString.h"
@@ -74,25 +75,12 @@ private:
        tcu::Vector<T, Size>*                   m_array;
 };
 
-template<typename T>   T                       randomScalar    (de::Random& rnd, T minValue, T maxValue);
-template<> inline              float           randomScalar    (de::Random& rnd, float minValue, float maxValue)               { return rnd.getFloat(minValue, maxValue);      }
-template<> inline              deInt32         randomScalar    (de::Random& rnd, deInt32 minValue, deInt32 maxValue)   { return rnd.getInt(minValue, maxValue);        }
-
-template<typename T, int Size>
-inline tcu::Vector<T, Size> randomVector (de::Random& rnd, const tcu::Vector<T, Size>& minValue, const tcu::Vector<T, Size>& maxValue)
-{
-       tcu::Vector<T, Size> res;
-       for (int ndx = 0; ndx < Size; ndx++)
-               res[ndx] = randomScalar<T>(rnd, minValue[ndx], maxValue[ndx]);
-       return res;
-}
-
 template<typename T, int Size>
 static void fillRandomVectors (de::Random& rnd, const tcu::Vector<T, Size>& minValue, const tcu::Vector<T, Size>& maxValue, void* dst, int numValues, int offset = 0)
 {
        VecArrayAccess<T, Size> access(dst);
        for (int ndx = 0; ndx < numValues; ndx++)
-               access[offset + ndx] = randomVector<T, Size>(rnd, minValue, maxValue);
+               access[offset + ndx] = tcu::randomVector<T, Size>(rnd, minValue, maxValue);
 }
 
 template<typename T>
@@ -100,7 +88,7 @@ static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* ds
 {
        T* typedPtr = (T*)dst;
        for (int ndx = 0; ndx < numValues; ndx++)
-               typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue);
+               typedPtr[offset + ndx] = de::randomScalar<T>(rnd, minValue, maxValue);
 }
 
 inline int numBitsLostInOp (float input, float output)
index 469369d..ad40f2e 100644 (file)
@@ -28,6 +28,7 @@
 #include "tcuTestLog.hpp"
 #include "tcuFormatUtil.hpp"
 #include "tcuFloat.hpp"
+#include "tcuVectorUtil.hpp"
 #include "deRandom.hpp"
 #include "deMath.h"
 #include "deString.h"
@@ -179,17 +180,13 @@ public:
                // Random values, mostly in range.
                for (int ndx = 0; ndx < 15; ndx++)
                {
-                       const float x = rnd.getFloat()*2.5f - 1.25f;
-                       const float y = rnd.getFloat()*2.5f - 1.25f;
-                       inputs.push_back(tcu::Vec2(x, y));
+                       inputs.push_back(tcu::randomVector<float, 2>(rnd, tcu::Vec2(-1.25f), tcu::Vec2(1.25f)));
                }
 
                // Large random values.
                for (int ndx = 0; ndx < 80; ndx++)
                {
-                       const float x = rnd.getFloat()*1e6f - 0.5e6f;
-                       const float y = rnd.getFloat()*1e6f - 0.5e6f;
-                       inputs.push_back(tcu::Vec2(x, y));
+                       inputs.push_back(tcu::randomVector<float, 2>(rnd, tcu::Vec2(-0.5e6f), tcu::Vec2(0.5e6f)));
                }
 
                outputs.resize(inputs.size());
@@ -402,17 +399,13 @@ public:
                // Random values, mostly in range.
                for (int ndx = 0; ndx < 15; ndx++)
                {
-                       const float x = rnd.getFloat()*1.25f;
-                       const float y = rnd.getFloat()*1.25f;
-                       inputs.push_back(tcu::Vec2(x, y));
+                       inputs.push_back(tcu::randomVector<float, 2>(rnd, tcu::Vec2(0.0f), tcu::Vec2(1.25f)));
                }
 
                // Large random values.
                for (int ndx = 0; ndx < 80; ndx++)
                {
-                       const float x = rnd.getFloat()*1e6f - 1e5f;
-                       const float y = rnd.getFloat()*1e6f - 1e5f;
-                       inputs.push_back(tcu::Vec2(x, y));
+                       inputs.push_back(tcu::randomVector<float, 2>(rnd, tcu::Vec2(-1e5f), tcu::Vec2(0.9e6f)));
                }
 
                outputs.resize(inputs.size());
@@ -949,21 +942,13 @@ public:
                // Random values, mostly in range.
                for (int ndx = 0; ndx < 15; ndx++)
                {
-                       const float x = rnd.getFloat()*2.5f - 1.25f;
-                       const float y = rnd.getFloat()*2.5f - 1.25f;
-                       const float z = rnd.getFloat()*2.5f - 1.25f;
-                       const float w = rnd.getFloat()*2.5f - 1.25f;
-                       inputs.push_back(tcu::Vec4(x, y, z, w));
+                       inputs.push_back(tcu::randomVector<float, 4>(rnd, tcu::Vec4(-1.25f), tcu::Vec4(1.25f)));
                }
 
                // Large random values.
                for (int ndx = 0; ndx < 80; ndx++)
                {
-                       const float x = rnd.getFloat()*1e6f - 0.5e6f;
-                       const float y = rnd.getFloat()*1e6f - 0.5e6f;
-                       const float z = rnd.getFloat()*1e6f - 0.5e6f;
-                       const float w = rnd.getFloat()*1e6f - 0.5e6f;
-                       inputs.push_back(tcu::Vec4(x, y, z, w));
+                       inputs.push_back(tcu::randomVector<float, 4>(rnd, tcu::Vec4(-0.5e6f), tcu::Vec4(0.5e6f)));
                }
 
                outputs.resize(inputs.size());
@@ -1192,21 +1177,13 @@ public:
                // Random values, mostly in range.
                for (int ndx = 0; ndx < 15; ndx++)
                {
-                       const float x = rnd.getFloat()*1.25f - 0.125f;
-                       const float y = rnd.getFloat()*1.25f - 0.125f;
-                       const float z = rnd.getFloat()*1.25f - 0.125f;
-                       const float w = rnd.getFloat()*1.25f - 0.125f;
-                       inputs.push_back(tcu::Vec4(x, y, z, w));
+                       inputs.push_back(tcu::randomVector<float, 4>(rnd, tcu::Vec4(-0.125f), tcu::Vec4(1.125f)));
                }
 
                // Large random values.
                for (int ndx = 0; ndx < 80; ndx++)
                {
-                       const float x = rnd.getFloat()*1e6f - 1e5f;
-                       const float y = rnd.getFloat()*1e6f - 1e5f;
-                       const float z = rnd.getFloat()*1e6f - 1e5f;
-                       const float w = rnd.getFloat()*1e6f - 1e5f;
-                       inputs.push_back(tcu::Vec4(x, y, z, w));
+                       inputs.push_back(tcu::randomVector<float, 4>(rnd, tcu::Vec4(-1e5f), tcu::Vec4(0.9e6f)));
                }
 
                outputs.resize(inputs.size());
index 7e4bd10..6f5d4d9 100644 (file)
@@ -178,9 +178,8 @@ static void fillWithRandomColorTiles (const PixelBufferAccess& dst, const Vec4&
                const int       yEnd    = (row+1)*dst.getHeight()/numRows;
                const int       xBegin  = (col+0)*dst.getWidth()/numCols;
                const int       xEnd    = (col+1)*dst.getWidth()/numCols;
-               Vec4            color;
-               for (int i = 0; i < 4; i++)
-                       color[i] = rnd.getFloat(minVal[i], maxVal[i]);
+               const Vec4      color   = tcu::randomVector<float, 4>(rnd, minVal, maxVal);
+
                tcu::clear(tcu::getSubregion(dst, xBegin, yBegin, slice, xEnd-xBegin, yEnd-yBegin, 1), color);
        }
 }
index 3bf3933..e6d51a3 100644 (file)
@@ -325,10 +325,6 @@ const std::string numberToString (T number)
        return ss.str();
 }
 
-template<typename T>   T                       randomScalar    (de::Random& rnd, T minValue, T maxValue);
-template<> inline              float           randomScalar    (de::Random& rnd, float minValue, float maxValue)               { return rnd.getFloat(minValue, maxValue);      }
-template<> inline              deInt32         randomScalar    (de::Random& rnd, deInt32 minValue, deInt32 maxValue)   { return rnd.getInt(minValue, maxValue);        }
-
 void getDefaultColors (tcu::RGBA (&colors)[4]);
 
 void getHalfColorsFullAlpha (tcu::RGBA (&colors)[4]);
index c0a0d41..af3abb8 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "vkImageUtil.hpp"
 #include "tcuTextureUtil.hpp"
+#include "tcuVectorUtil.hpp"
 
 namespace vkt
 {
@@ -758,7 +759,7 @@ void addComputeImageSamplerTest (tcu::TestCaseGroup* group)
        inputData.reserve(numDataPoints);
 
        for (deUint32 numIdx = 0; numIdx < numDataPoints; ++numIdx)
-               inputData.push_back(tcu::Vec4(rnd.getFloat(), rnd.getFloat(), rnd.getFloat(), rnd.getFloat()));
+               inputData.push_back(tcu::randomVec4(rnd));
 
        for (deUint32 opNdx = 0u; opNdx <= READOP_IMAGESAMPLE; opNdx++)
        {
@@ -1050,7 +1051,7 @@ void addGraphicsImageSamplerTest (tcu::TestCaseGroup* group)
 
        vector<tcu::Vec4> inputData(numDataPoints);
        for (deUint32 numIdx = 0; numIdx < numDataPoints; ++numIdx)
-               inputData[numIdx] = tcu::Vec4(rnd.getFloat(), rnd.getFloat(), rnd.getFloat(), rnd.getFloat());
+               inputData[numIdx] = tcu::randomVec4(rnd);
 
        for (deUint32 opNdx = 0u; opNdx <= READOP_IMAGESAMPLE; opNdx++)
        {
@@ -1196,7 +1197,7 @@ void addGraphicsDepthPropertyTest (tcu::TestCaseGroup* group)
        inputDataVec4.reserve(numDataPoints);
 
        for (deUint32 numIdx = 0; numIdx < numDataPoints; ++numIdx)
-               inputDataVec4.push_back(Vec4(rnd.getFloat(), rnd.getFloat(), rnd.getFloat(), rnd.getFloat()));
+               inputDataVec4.push_back(tcu::randomVec4(rnd));
 
        de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "depth_property", ""));
 
index c543d96..17ef9e5 100644 (file)
@@ -27,6 +27,7 @@
 #include "vktSpvAsmGraphicsShaderTestUtil.hpp"
 
 #include "tcuStringTemplate.hpp"
+#include "tcuVectorUtil.hpp"
 
 namespace vkt
 {
@@ -81,7 +82,7 @@ void addComputeIndexingStructTests (tcu::TestCaseGroup* group)
 
        indexSelectorData.reserve(numItems);
        for (deUint32 numIdx = 0; numIdx < numItems; ++numIdx)
-               indexSelectorData.push_back(UVec4(rnd.getUint32() % 32, rnd.getUint32() % 32, rnd.getUint32() % 4, rnd.getUint32() % 4));
+               indexSelectorData.push_back(tcu::randomVector<deUint32, 4>(rnd, UVec4(0), UVec4(31, 31, 3, 3)));
 
        for (int chainOpIdx = 0; chainOpIdx < CHAIN_OP_LAST; ++chainOpIdx)
        {
@@ -297,7 +298,7 @@ void addGraphicsIndexingStructTests (tcu::TestCaseGroup* group)
 
        indexSelectorData.reserve(numItems);
        for (deUint32 numIdx = 0; numIdx < numItems; ++numIdx)
-               indexSelectorData.push_back(UVec4(rnd.getUint32() % 32, rnd.getUint32() % 32, rnd.getUint32() % 4, rnd.getUint32() % 4));
+               indexSelectorData.push_back(tcu::randomVector<deUint32, 4>(rnd, UVec4(0), UVec4(31, 31, 3, 3)));
 
        getDefaultColors(defaultColors);
 
index 51ff4e8..152a08d 100644 (file)
@@ -48,6 +48,7 @@
 #include "deStringUtil.hpp"
 #include "deUniquePtr.hpp"
 #include "deMath.h"
+#include "deRandom.hpp"
 #include "tcuStringTemplate.hpp"
 
 #include "vktSpvAsmCrossStageInterfaceTests.hpp"
@@ -110,7 +111,7 @@ static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* ds
 {
        T* const typedPtr = (T*)dst;
        for (int ndx = 0; ndx < numValues; ndx++)
-               typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue);
+               typedPtr[offset + ndx] = de::randomScalar<T>(rnd, minValue, maxValue);
 }
 
 // Filter is a function that returns true if a value should pass, false otherwise.
@@ -122,7 +123,7 @@ static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* ds
        for (int ndx = 0; ndx < numValues; ndx++)
        {
                do
-                       value = randomScalar<T>(rnd, minValue, maxValue);
+                       value = de::randomScalar<T>(rnd, minValue, maxValue);
                while (!filter(value));
 
                typedPtr[offset + ndx] = value;
index 1c333a5..b84b15a 100644 (file)
@@ -25,6 +25,7 @@
 #include "vktSpvAsmComputeShaderCase.hpp"
 #include "vktSpvAsmComputeShaderTestUtil.hpp"
 #include "vktSpvAsmGraphicsShaderTestUtil.hpp"
+#include "tcuVectorUtil.hpp"
 
 namespace vkt
 {
@@ -130,7 +131,7 @@ void addComputeUboMatrixPaddingTest (tcu::TestCaseGroup* group)
 
        inputData.reserve(numElements);
        for (deUint32 numIdx = 0; numIdx < numElements; ++numIdx)
-               inputData.push_back(tcu::Vec4(rnd.getFloat(), rnd.getFloat(), rnd.getFloat(), rnd.getFloat()));
+               inputData.push_back(tcu::randomVec4(rnd));
 
        spec.assembly                   = shaderSource;
        spec.numWorkGroups              = IVec3(numElements, 1, 1);
@@ -158,7 +159,7 @@ void addGraphicsUboMatrixPaddingTest (tcu::TestCaseGroup* group)
 
        vector<tcu::Vec4> inputData(numDataPoints);
        for (deUint32 numIdx = 0; numIdx < numDataPoints; ++numIdx)
-               inputData[numIdx] = tcu::Vec4(rnd.getFloat(), rnd.getFloat(), rnd.getFloat(), rnd.getFloat());
+               inputData[numIdx] = tcu::randomVec4(rnd);
 
        resources.inputs.push_back(Resource(BufferSp(new Vec4Buffer(inputData)), VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER));
        // Shader is expected to pass the input data by treating the input vec4 as mat2x2
index f17fe94..0bb8aed 100644 (file)
@@ -83,7 +83,7 @@ void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int
 {
        T* const typedPtr = (T*)dst;
        for (int ndx = 0; ndx < numValues; ndx++)
-               typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue);
+               typedPtr[offset + ndx] = de::randomScalar<T>(rnd, minValue, maxValue);
 }
 
 // The following structure (outer_struct) is passed as a vector of 64 32-bit floats into some shaders.
index 622bffa..0797463 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "tcuDefs.hpp"
 #include "tcuVector.hpp"
+#include "deRandom.hpp"
 #include "deMeta.hpp"
 #include "deMath.h"
 #include "deInt32.h"
@@ -368,6 +369,32 @@ static inline Vector<T, Size> absDiff (const Vector<T, Size>& a, const Vector<T,
        return res;
 }
 
+template<typename T, int Size>
+inline tcu::Vector<T, Size> randomVector (de::Random& rnd, const tcu::Vector<T, Size>& minValue, const tcu::Vector<T, Size>& maxValue)
+{
+       tcu::Vector<T, Size> res;
+
+       for (int ndx = 0; ndx < Size; ndx++)
+               res[ndx] = de::randomScalar<T>(rnd, minValue[ndx], maxValue[ndx]);
+
+       return res;
+}
+
+inline Vector<float, 2> randomVec2 (de::Random& rnd)
+{
+       return randomVector<float, 2>(rnd, tcu::Vector<float, 2>(0.0f), tcu::Vector<float, 2>(1.0f));
+}
+
+inline Vector<float, 3> randomVec3 (de::Random& rnd)
+{
+       return randomVector<float, 3>(rnd, tcu::Vector<float, 3>(0.0f), tcu::Vector<float, 3>(1.0f));
+}
+
+inline Vector<float, 4> randomVec4 (de::Random& rnd)
+{
+       return randomVector<float, 4>(rnd, tcu::Vector<float, 4>(0.0f), tcu::Vector<float, 4>(1.0f));
+}
+
 // Macros for component-wise ops.
 
 #define TCU_DECLARE_VECTOR_UNARY_FUNC(FUNC_NAME, OP_NAME)      \
index a048622..4f6d15c 100644 (file)
@@ -177,6 +177,11 @@ void Random::shuffle (Iterator first, Iterator last)
        }
 }
 
+template<typename T>   T                       randomScalar    (de::Random& rnd, T minValue, T maxValue);
+template<> inline              float           randomScalar    (de::Random& rnd, float minValue, float maxValue)               { return rnd.getFloat(minValue, maxValue); }
+template<> inline              deInt32         randomScalar    (de::Random& rnd, deInt32 minValue, deInt32 maxValue)   { return rnd.getInt(minValue, maxValue); }
+template<> inline              deUint32        randomScalar    (de::Random& rnd, deUint32 minValue, deUint32 maxValue) { return minValue + rnd.getUint32() % (maxValue - minValue + 1); }
+
 } // de
 
 #endif // _DERANDOM_HPP
index 237b754..edcf245 100644 (file)
@@ -25,6 +25,7 @@
 #include "glsShaderExecUtil.hpp"
 #include "tcuTestLog.hpp"
 #include "tcuFormatUtil.hpp"
+#include "tcuVectorUtil.hpp"
 #include "tcuFloat.hpp"
 #include "deRandom.hpp"
 #include "deMath.h"
@@ -65,26 +66,12 @@ private:
        tcu::Vector<T, Size>*                   m_array;
 };
 
-template<typename T>   T                       randomScalar    (de::Random& rnd, T minValue, T maxValue);
-template<> inline              float           randomScalar    (de::Random& rnd, float minValue, float maxValue)               { return rnd.getFloat(minValue, maxValue);      }
-template<> inline              deInt32         randomScalar    (de::Random& rnd, deInt32 minValue, deInt32 maxValue)   { return rnd.getInt(minValue, maxValue);        }
-template<> inline              deUint32        randomScalar    (de::Random& rnd, deUint32 minValue, deUint32 maxValue) { return minValue + rnd.getUint32() % (maxValue - minValue + 1); }
-
-template<typename T, int Size>
-inline tcu::Vector<T, Size> randomVector (de::Random& rnd, const tcu::Vector<T, Size>& minValue, const tcu::Vector<T, Size>& maxValue)
-{
-       tcu::Vector<T, Size> res;
-       for (int ndx = 0; ndx < Size; ndx++)
-               res[ndx] = randomScalar<T>(rnd, minValue[ndx], maxValue[ndx]);
-       return res;
-}
-
 template<typename T, int Size>
 static void fillRandomVectors (de::Random& rnd, const tcu::Vector<T, Size>& minValue, const tcu::Vector<T, Size>& maxValue, void* dst, int numValues, int offset = 0)
 {
        VecArrayAccess<T, Size> access(dst);
        for (int ndx = 0; ndx < numValues; ndx++)
-               access[offset + ndx] = randomVector<T, Size>(rnd, minValue, maxValue);
+               access[offset + ndx] = tcu::randomVector<T, Size>(rnd, minValue, maxValue);
 }
 
 template<typename T>
@@ -92,7 +79,7 @@ static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* ds
 {
        T* typedPtr = (T*)dst;
        for (int ndx = 0; ndx < numValues; ndx++)
-               typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue);
+               typedPtr[offset + ndx] = de::randomScalar<T>(rnd, minValue, maxValue);
 }
 
 inline int numBitsLostInOp (float input, float output)
index e7aae44..566e183 100644 (file)
@@ -29,6 +29,7 @@
 #include "tcuFloat.hpp"
 #include "tcuInterval.hpp"
 #include "tcuFloatFormat.hpp"
+#include "tcuVectorUtil.hpp"
 #include "deRandom.hpp"
 #include "deMath.h"
 #include "deString.h"
@@ -69,26 +70,12 @@ private:
        tcu::Vector<T, Size>*                   m_array;
 };
 
-template<typename T>   T                       randomScalar    (de::Random& rnd, T minValue, T maxValue);
-template<> inline              float           randomScalar    (de::Random& rnd, float minValue, float maxValue)               { return rnd.getFloat(minValue, maxValue);      }
-template<> inline              deInt32         randomScalar    (de::Random& rnd, deInt32 minValue, deInt32 maxValue)   { return rnd.getInt(minValue, maxValue);        }
-template<> inline              deUint32        randomScalar    (de::Random& rnd, deUint32 minValue, deUint32 maxValue) { return minValue + rnd.getUint32() % (maxValue - minValue + 1); }
-
-template<typename T, int Size>
-inline tcu::Vector<T, Size> randomVector (de::Random& rnd, const tcu::Vector<T, Size>& minValue, const tcu::Vector<T, Size>& maxValue)
-{
-       tcu::Vector<T, Size> res;
-       for (int ndx = 0; ndx < Size; ndx++)
-               res[ndx] = randomScalar<T>(rnd, minValue[ndx], maxValue[ndx]);
-       return res;
-}
-
 template<typename T, int Size>
 static void fillRandomVectors (de::Random& rnd, const tcu::Vector<T, Size>& minValue, const tcu::Vector<T, Size>& maxValue, void* dst, int numValues, int offset = 0)
 {
        VecArrayAccess<T, Size> access(dst);
        for (int ndx = 0; ndx < numValues; ndx++)
-               access[offset + ndx] = randomVector<T, Size>(rnd, minValue, maxValue);
+               access[offset + ndx] = tcu::randomVector<T, Size>(rnd, minValue, maxValue);
 }
 
 template<typename T>
@@ -96,7 +83,7 @@ static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* ds
 {
        T* typedPtr = (T*)dst;
        for (int ndx = 0; ndx < numValues; ndx++)
-               typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue);
+               typedPtr[offset + ndx] = de::randomScalar<T>(rnd, minValue, maxValue);
 }
 
 inline int numBitsLostInOp (float input, float output)