diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-02-03 00:25:38 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-02-03 00:50:41 +0000 |
| commit | cf64c170eeef92bce1799b715f89a27ebb245019 (patch) | |
| tree | 6441514fb2e83438cfc36bbf8b52ed7417ad2c37 /Tests | |
| parent | ShaderResourceLayoutTest.RWTextures: added resource binding validation (diff) | |
| download | DiligentCore-cf64c170eeef92bce1799b715f89a27ebb245019.tar.gz DiligentCore-cf64c170eeef92bce1799b715f89a27ebb245019.zip | |
Reworked PipelineResourceSignatureTest.VariableTypes to validate resource bindings
Diffstat (limited to 'Tests')
4 files changed, 275 insertions, 240 deletions
diff --git a/Tests/DiligentCoreAPITest/assets/shaders/PipelineResourceSignature/VariableTypes.hlsl b/Tests/DiligentCoreAPITest/assets/shaders/PipelineResourceSignature/VariableTypes.hlsl deleted file mode 100644 index 5f9ed026..00000000 --- a/Tests/DiligentCoreAPITest/assets/shaders/PipelineResourceSignature/VariableTypes.hlsl +++ /dev/null @@ -1,47 +0,0 @@ -Texture2D g_Tex2D_Static; -Texture2D g_Tex2D_Mut; -Texture2D g_Tex2D_Dyn; - -Texture2D g_Tex2DArr_Static[STATIC_TEX_ARRAY_SIZE]; // 2 -Texture2D g_Tex2DArr_Mut [MUTABLE_TEX_ARRAY_SIZE]; // 4 -Texture2D g_Tex2DArr_Dyn [DYNAMIC_TEX_ARRAY_SIZE]; // 3 - -SamplerState g_Sampler; - -float4 UseResources() -{ - float2 UV = float2(0.0, 0.0); - float4 f4Color = float4(0.0, 0.0, 0.0, 0.0); - f4Color += g_Tex2D_Static.SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2D_Mut. SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2D_Dyn. SampleLevel(g_Sampler, UV.xy, 0.0); - - // glslang is not smart enough to unroll the loops even when explicitly told to do so - - f4Color += g_Tex2DArr_Static[0].SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2DArr_Static[1].SampleLevel(g_Sampler, UV.xy, 0.0); - - f4Color += g_Tex2DArr_Mut[0].SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2DArr_Mut[1].SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2DArr_Mut[2].SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2DArr_Mut[3].SampleLevel(g_Sampler, UV.xy, 0.0); - - f4Color += g_Tex2DArr_Dyn[0].SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2DArr_Dyn[1].SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2DArr_Dyn[2].SampleLevel(g_Sampler, UV.xy, 0.0); - - return f4Color; -} - -void VSMain(out float4 f4Color : COLOR, - out float4 f4Position : SV_Position) -{ - f4Color = UseResources(); - f4Position = float4(0.0, 0.0, 0.0, 1.0); -} - -float4 PSMain(in float4 in_f4Color : COLOR, - in float4 f4Position : SV_Position) : SV_Target -{ - return in_f4Color + UseResources(); -} diff --git a/Tests/DiligentCoreAPITest/include/ResourceLayoutTestCommon.hpp b/Tests/DiligentCoreAPITest/include/ResourceLayoutTestCommon.hpp new file mode 100644 index 00000000..d6174578 --- /dev/null +++ b/Tests/DiligentCoreAPITest/include/ResourceLayoutTestCommon.hpp @@ -0,0 +1,216 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include <vector> + +#include "RenderDevice.h" +#include "DeviceContext.h" +#include "RefCntAutoPtr.hpp" +#include "BasicMath.hpp" + +#include "TestingEnvironment.hpp" + +namespace Diligent +{ + +namespace Testing +{ + +class ReferenceBuffers +{ +public: + ReferenceBuffers(Uint32 NumBuffers, + USAGE Usage, + BIND_FLAGS BindFlags, + BUFFER_VIEW_TYPE ViewType = BUFFER_VIEW_UNDEFINED, + BUFFER_MODE BufferMode = BUFFER_MODE_UNDEFINED) : + Buffers(NumBuffers), + Values(NumBuffers), + UsedValues(NumBuffers), + ppBuffObjects(NumBuffers), + Views(NumBuffers), + ppViewObjects(NumBuffers) + { + auto* pEnv = TestingEnvironment::GetInstance(); + auto* pDevice = pEnv->GetDevice(); + + for (Uint32 i = 0; i < NumBuffers; ++i) + { + auto& Value = Values[i]; + auto v = static_cast<float>(i * 10); + Value = float4(v + 1, v + 2, v + 3, v + 4); + + std::vector<float4> InitData(16, Value); + + BufferDesc BuffDesc; + + String Name = "Reference buffer " + std::to_string(i); + BuffDesc.Name = Name.c_str(); + + BuffDesc.Usage = Usage; + BuffDesc.BindFlags = BindFlags; + BuffDesc.Mode = BufferMode; + BuffDesc.uiSizeInBytes = static_cast<Uint32>(InitData.size() * sizeof(InitData[0])); + BuffDesc.ElementByteStride = BufferMode != BUFFER_MODE_UNDEFINED ? 16 : 0; + + auto& pBuffer = Buffers[i]; + BufferData BuffData{InitData.data(), BuffDesc.uiSizeInBytes}; + pDevice->CreateBuffer(BuffDesc, &BuffData, &pBuffer); + if (!pBuffer) + { + ADD_FAILURE() << "Unable to create buffer " << BuffDesc; + return; + } + ppBuffObjects[i] = pBuffer; + + if (ViewType != BUFFER_VIEW_UNDEFINED) + { + auto& pView = Views[i]; + if (BufferMode == BUFFER_MODE_FORMATTED) + { + BufferViewDesc BuffViewDesc; + BuffViewDesc.Name = "Formatted buffer SRV"; + BuffViewDesc.ViewType = ViewType; + BuffViewDesc.Format.ValueType = VT_FLOAT32; + BuffViewDesc.Format.NumComponents = 4; + BuffViewDesc.Format.IsNormalized = false; + + pBuffer->CreateView(BuffViewDesc, &pView); + } + else + { + pView = pBuffer->GetDefaultView(ViewType); + } + + if (!pView) + { + ADD_FAILURE() << "Unable to create buffer view"; + return; + } + + ppViewObjects[i] = pView; + } + } + } + + IDeviceObject** GetBuffObjects(size_t i) { return &ppBuffObjects[i]; }; + IDeviceObject** GetViewObjects(size_t i) { return &ppViewObjects[i]; }; + + const float4& GetValue(size_t i) + { + VERIFY(!UsedValues[i], "Buffer ", i, " has already been used. Every buffer is expected to be used once."); + UsedValues[i] = true; + VERIFY(Values[i] != float4{}, "Value must not be zero"); + return Values[i]; + } + + void ClearUsedValues() + { + std::fill(UsedValues.begin(), UsedValues.end(), false); + } + +private: + std::vector<RefCntAutoPtr<IBuffer>> Buffers; + std::vector<RefCntAutoPtr<IBufferView>> Views; + + std::vector<IDeviceObject*> ppBuffObjects; + std::vector<IDeviceObject*> ppViewObjects; + + std::vector<bool> UsedValues; + std::vector<float4> Values; +}; + +class ReferenceTextures +{ +public: + ReferenceTextures(Uint32 NumTextures, + Uint32 Width, + Uint32 Height, + USAGE Usage, + BIND_FLAGS BindFlags, + TEXTURE_VIEW_TYPE ViewType) : + Textures(NumTextures), + ppViewObjects(NumTextures), + UsedValues(NumTextures), + Values(NumTextures) + { + auto* pEnv = TestingEnvironment::GetInstance(); + + for (Uint32 i = 0; i < NumTextures; ++i) + { + auto& pTexture = Textures[i]; + auto& Value = Values[i]; + + int v = (i % 15) + 1; + Value = float4{ + (v & 0x01) ? 1.f : 0.f, + (v & 0x02) ? 1.f : 0.f, + (v & 0x04) ? 1.f : 0.f, + (v & 0x08) ? 1.f : 0.f // + }; + + std::vector<Uint32> TexData(Width * Height, F4Color_To_RGBA8Unorm(Value)); + + String Name = String{"Reference texture "} + std::to_string(i); + pTexture = pEnv->CreateTexture("Test texture", TEX_FORMAT_RGBA8_UNORM, BindFlags, Width, Height, TexData.data()); + ppViewObjects[i] = pTexture->GetDefaultView(ViewType); + } + } + + IDeviceObject** GetViewObjects(size_t i) { return &ppViewObjects[i]; }; + + const float4& GetColor(size_t i) + { + VERIFY(!UsedValues[i], "Texture ", i, " has already been used. Every texture is expected to be used once."); + UsedValues[i] = true; + VERIFY(Values[i] != float4{}, "Value must not be zero"); + return Values[i]; + } + + void ClearUsedValues() + { + std::fill(UsedValues.begin(), UsedValues.end(), false); + } + +private: + std::vector<RefCntAutoPtr<ITexture>> Textures; + + std::vector<IDeviceObject*> ppViewObjects; + + std::vector<bool> UsedValues; + std::vector<float4> Values; +}; + +void PrintShaderResources(IShader* pShader); +void RenderDrawCommandReference(ISwapChain* pSwapChain, const float* pClearColor = nullptr); +void ComputeShaderReference(ISwapChain* pSwapChain); + +} // namespace Testing + +} // namespace Diligent diff --git a/Tests/DiligentCoreAPITest/src/PipelineResourceSignatureTest.cpp b/Tests/DiligentCoreAPITest/src/PipelineResourceSignatureTest.cpp index e081e960..188ee227 100644 --- a/Tests/DiligentCoreAPITest/src/PipelineResourceSignatureTest.cpp +++ b/Tests/DiligentCoreAPITest/src/PipelineResourceSignatureTest.cpp @@ -31,6 +31,7 @@ #include "TestingEnvironment.hpp" #include "ShaderMacroHelper.hpp" #include "GraphicsAccessories.hpp" +#include "ResourceLayoutTestCommon.hpp" #include "gtest/gtest.h" @@ -129,6 +130,7 @@ protected: GraphicsPipeline.DSVFormat = TEX_FORMAT_UNKNOWN; GraphicsPipeline.DepthStencilDesc.DepthEnable = False; + GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_NONE; RefCntAutoPtr<IPipelineState> pPSO; pDevice->CreateGraphicsPipelineState(PSOCreateInfo, &pPSO); @@ -232,16 +234,56 @@ TEST_F(PipelineResourceSignatureTest, VariableTypes) TestingEnvironment::ScopedReset EnvironmentAutoReset; + auto* pSwapChain = pEnv->GetSwapChain(); + + float ClearColor[] = {0.125, 0.25, 0.375, 0.5}; + RenderDrawCommandReference(pSwapChain, ClearColor); + static constexpr Uint32 StaticTexArraySize = 2; static constexpr Uint32 MutableTexArraySize = 4; static constexpr Uint32 DynamicTexArraySize = 3; - ShaderMacroHelper Macros; + + ReferenceTextures RefTextures{ + 3 + StaticTexArraySize + MutableTexArraySize + DynamicTexArraySize, + 128, 128, + USAGE_DEFAULT, + BIND_SHADER_RESOURCE, + TEXTURE_VIEW_SHADER_RESOURCE // + }; + + // Texture indices for vertex/shader bindings + static constexpr size_t Tex2D_StaticIdx = 2; + static constexpr size_t Tex2D_MutIdx = 0; + static constexpr size_t Tex2D_DynIdx = 1; + + static constexpr size_t Tex2DArr_StaticIdx = 7; + static constexpr size_t Tex2DArr_MutIdx = 3; + static constexpr size_t Tex2DArr_DynIdx = 9; + + ShaderMacroHelper Macros; + Macros.AddShaderMacro("STATIC_TEX_ARRAY_SIZE", static_cast<int>(StaticTexArraySize)); Macros.AddShaderMacro("MUTABLE_TEX_ARRAY_SIZE", static_cast<int>(MutableTexArraySize)); Macros.AddShaderMacro("DYNAMIC_TEX_ARRAY_SIZE", static_cast<int>(DynamicTexArraySize)); - auto pVS = CreateShaderFromFile(SHADER_TYPE_VERTEX, "VariableTypes.hlsl", "VSMain", "PRS variable types test: VS", Macros); - auto pPS = CreateShaderFromFile(SHADER_TYPE_PIXEL, "VariableTypes.hlsl", "PSMain", "PRS variable types test: PS", Macros); + RefTextures.ClearUsedValues(); + + // Add macros that define reference colors + Macros.AddShaderMacro("Tex2D_Static_Ref", RefTextures.GetColor(Tex2D_StaticIdx)); + Macros.AddShaderMacro("Tex2D_Mut_Ref", RefTextures.GetColor(Tex2D_MutIdx)); + Macros.AddShaderMacro("Tex2D_Dyn_Ref", RefTextures.GetColor(Tex2D_DynIdx)); + + for (Uint32 i = 0; i < StaticTexArraySize; ++i) + Macros.AddShaderMacro((std::string{"Tex2DArr_Static_Ref"} + std::to_string(i)).c_str(), RefTextures.GetColor(Tex2DArr_StaticIdx + i)); + + for (Uint32 i = 0; i < MutableTexArraySize; ++i) + Macros.AddShaderMacro((std::string{"Tex2DArr_Mut_Ref"} + std::to_string(i)).c_str(), RefTextures.GetColor(Tex2DArr_MutIdx + i)); + + for (Uint32 i = 0; i < DynamicTexArraySize; ++i) + Macros.AddShaderMacro((std::string{"Tex2DArr_Dyn_Ref"} + std::to_string(i)).c_str(), RefTextures.GetColor(Tex2DArr_DynIdx + i)); + + auto pVS = CreateShaderFromFile(SHADER_TYPE_VERTEX, "shaders/ShaderResourceLayout/Textures.hlsl", "VSMain", "PRS variable types test: VS", Macros); + auto pPS = CreateShaderFromFile(SHADER_TYPE_PIXEL, "shaders/ShaderResourceLayout/Textures.hlsl", "PSMain", "PRS variable types test: PS", Macros); ASSERT_TRUE(pVS && pPS); PipelineResourceSignatureDesc PRSDesc; @@ -270,29 +312,30 @@ TEST_F(PipelineResourceSignatureTest, VariableTypes) auto pPSO = CreateGraphicsPSO(pVS, pPS, {pPRS}); ASSERT_TRUE(pPSO); - std::array<IDeviceObject*, 4> ppSRVs = {pTexSRVs[0], pTexSRVs[1], pTexSRVs[2], pTexSRVs[3]}; - - SET_STATIC_VAR(pPRS, SHADER_TYPE_VERTEX, "g_Tex2D_Static", Set, ppSRVs[0]); - SET_STATIC_VAR(pPRS, SHADER_TYPE_VERTEX, "g_Tex2DArr_Static", SetArray, ppSRVs.data(), 0, StaticTexArraySize); + SET_STATIC_VAR(pPRS, SHADER_TYPE_VERTEX, "g_Tex2D_Static", Set, RefTextures.GetViewObjects(Tex2D_StaticIdx)[0]); + SET_STATIC_VAR(pPRS, SHADER_TYPE_VERTEX, "g_Tex2DArr_Static", SetArray, RefTextures.GetViewObjects(Tex2DArr_StaticIdx), 0, StaticTexArraySize); SET_STATIC_VAR(pPRS, SHADER_TYPE_VERTEX, "g_Sampler", Set, pSampler); RefCntAutoPtr<IShaderResourceBinding> pSRB; pPRS->CreateShaderResourceBinding(&pSRB, true); - SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2D_Mut", Set, pTexSRVs[0]); - SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2DArr_Mut", SetArray, ppSRVs.data(), 0, MutableTexArraySize); - SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2D_Dyn", Set, pTexSRVs[0]); - SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2DArr_Dyn", SetArray, ppSRVs.data(), 0, DynamicTexArraySize); + SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2D_Mut", Set, RefTextures.GetViewObjects(Tex2D_MutIdx)[0]); + SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2DArr_Mut", SetArray, RefTextures.GetViewObjects(Tex2DArr_MutIdx), 0, MutableTexArraySize); + SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2D_Dyn", Set, RefTextures.GetViewObjects(Tex2D_DynIdx)[0]); + SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2DArr_Dyn", SetArray, RefTextures.GetViewObjects(Tex2DArr_DynIdx), 0, DynamicTexArraySize); pContext->CommitShaderResources(pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - ITextureView* ppRTVs[] = {pRTV}; + ITextureView* ppRTVs[] = {pSwapChain->GetCurrentBackBufferRTV()}; pContext->SetRenderTargets(1, ppRTVs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + pContext->ClearRenderTarget(ppRTVs[0], ClearColor, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); pContext->SetPipelineState(pPSO); - DrawAttribs DrawAttrs(3, DRAW_FLAG_VERIFY_ALL); + DrawAttribs DrawAttrs{6, DRAW_FLAG_VERIFY_ALL}; pContext->Draw(DrawAttrs); + + pSwapChain->Present(); } diff --git a/Tests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp b/Tests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp index 88137280..3d7d5768 100644 --- a/Tests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp +++ b/Tests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp @@ -29,10 +29,12 @@ #include <algorithm> #include <array> -#include "TestingEnvironment.hpp" #include "ShaderMacroHelper.hpp" #include "GraphicsAccessories.hpp" #include "BasicMath.hpp" + +#include "TestingEnvironment.hpp" +#include "ResourceLayoutTestCommon.hpp" #include "TestingSwapChainBase.hpp" #include "gtest/gtest.h" @@ -40,188 +42,9 @@ using namespace Diligent; using namespace Diligent::Testing; -namespace Diligent -{ - -namespace Testing -{ - -void PrintShaderResources(IShader* pShader); -void RenderDrawCommandReference(ISwapChain* pSwapChain, const float* pClearColor = nullptr); -void ComputeShaderReference(ISwapChain* pSwapChain); - -} // namespace Testing - -} // namespace Diligent - namespace { -class ReferenceBuffers -{ -public: - ReferenceBuffers(Uint32 NumBuffers, - USAGE Usage, - BIND_FLAGS BindFlags, - BUFFER_VIEW_TYPE ViewType = BUFFER_VIEW_UNDEFINED, - BUFFER_MODE BufferMode = BUFFER_MODE_UNDEFINED) : - Buffers(NumBuffers), - Values(NumBuffers), - UsedValues(NumBuffers), - ppBuffObjects(NumBuffers), - Views(NumBuffers), - ppViewObjects(NumBuffers) - { - auto* pEnv = TestingEnvironment::GetInstance(); - auto* pDevice = pEnv->GetDevice(); - - for (Uint32 i = 0; i < NumBuffers; ++i) - { - auto& Value = Values[i]; - auto v = static_cast<float>(i * 10); - Value = float4(v + 1, v + 2, v + 3, v + 4); - - std::vector<float4> InitData(16, Value); - - BufferDesc BuffDesc; - - String Name = "Reference buffer " + std::to_string(i); - BuffDesc.Name = Name.c_str(); - - BuffDesc.Usage = Usage; - BuffDesc.BindFlags = BindFlags; - BuffDesc.Mode = BufferMode; - BuffDesc.uiSizeInBytes = static_cast<Uint32>(InitData.size() * sizeof(InitData[0])); - BuffDesc.ElementByteStride = BufferMode != BUFFER_MODE_UNDEFINED ? 16 : 0; - - auto& pBuffer = Buffers[i]; - BufferData BuffData{InitData.data(), BuffDesc.uiSizeInBytes}; - pDevice->CreateBuffer(BuffDesc, &BuffData, &pBuffer); - if (!pBuffer) - { - ADD_FAILURE() << "Unable to create buffer " << BuffDesc; - return; - } - ppBuffObjects[i] = pBuffer; - - if (ViewType != BUFFER_VIEW_UNDEFINED) - { - auto& pView = Views[i]; - if (BufferMode == BUFFER_MODE_FORMATTED) - { - BufferViewDesc BuffViewDesc; - BuffViewDesc.Name = "Formatted buffer SRV"; - BuffViewDesc.ViewType = ViewType; - BuffViewDesc.Format.ValueType = VT_FLOAT32; - BuffViewDesc.Format.NumComponents = 4; - BuffViewDesc.Format.IsNormalized = false; - - pBuffer->CreateView(BuffViewDesc, &pView); - } - else - { - pView = pBuffer->GetDefaultView(ViewType); - } - - if (!pView) - { - ADD_FAILURE() << "Unable to create buffer view"; - return; - } - - ppViewObjects[i] = pView; - } - } - } - - IDeviceObject** GetBuffObjects(size_t i) { return &ppBuffObjects[i]; }; - IDeviceObject** GetViewObjects(size_t i) { return &ppViewObjects[i]; }; - - const float4& GetValue(size_t i) - { - VERIFY(!UsedValues[i], "Buffer ", i, " has already been used. Every buffer is expected to be used once."); - UsedValues[i] = true; - VERIFY(Values[i] != float4{}, "Value must not be zero"); - return Values[i]; - } - - void ClearUsedValues() - { - std::fill(UsedValues.begin(), UsedValues.end(), false); - } - -private: - std::vector<RefCntAutoPtr<IBuffer>> Buffers; - std::vector<RefCntAutoPtr<IBufferView>> Views; - - std::vector<IDeviceObject*> ppBuffObjects; - std::vector<IDeviceObject*> ppViewObjects; - - std::vector<bool> UsedValues; - std::vector<float4> Values; -}; - -class ReferenceTextures -{ -public: - ReferenceTextures(Uint32 NumTextures, - Uint32 Width, - Uint32 Height, - USAGE Usage, - BIND_FLAGS BindFlags, - TEXTURE_VIEW_TYPE ViewType) : - Textures(NumTextures), - ppViewObjects(NumTextures), - UsedValues(NumTextures), - Values(NumTextures) - { - auto* pEnv = TestingEnvironment::GetInstance(); - - for (Uint32 i = 0; i < NumTextures; ++i) - { - auto& pTexture = Textures[i]; - auto& Value = Values[i]; - - int v = (i % 15) + 1; - Value = float4{ - (v & 0x01) ? 1.f : 0.f, - (v & 0x02) ? 1.f : 0.f, - (v & 0x04) ? 1.f : 0.f, - (v & 0x08) ? 1.f : 0.f // - }; - - std::vector<Uint32> TexData(Width * Height, F4Color_To_RGBA8Unorm(Value)); - - String Name = String{"Reference texture "} + std::to_string(i); - pTexture = pEnv->CreateTexture("Test texture", TEX_FORMAT_RGBA8_UNORM, BindFlags, Width, Height, TexData.data()); - ppViewObjects[i] = pTexture->GetDefaultView(ViewType); - } - } - - IDeviceObject** GetViewObjects(size_t i) { return &ppViewObjects[i]; }; - - const float4& GetColor(size_t i) - { - VERIFY(!UsedValues[i], "Texture ", i, " has already been used. Every texture is expected to be used once."); - UsedValues[i] = true; - VERIFY(Values[i] != float4{}, "Value must not be zero"); - return Values[i]; - } - - void ClearUsedValues() - { - std::fill(UsedValues.begin(), UsedValues.end(), false); - } - -private: - std::vector<RefCntAutoPtr<ITexture>> Textures; - - std::vector<IDeviceObject*> ppViewObjects; - - std::vector<bool> UsedValues; - std::vector<float4> Values; -}; - class ShaderResourceLayoutTest : public ::testing::Test { protected: |
