diff --git a/assets/benchmarks/shaders/Benchmark_Quad.hlsli b/assets/benchmarks/shaders/Benchmark_Quad.hlsli index 019b955f8..24c98af15 100644 --- a/assets/benchmarks/shaders/Benchmark_Quad.hlsli +++ b/assets/benchmarks/shaders/Benchmark_Quad.hlsli @@ -18,6 +18,7 @@ struct ConfigParams { uint32_t InstCount; uint32_t RandomSeed; + uint32_t TextureCount; float3 ColorValue; }; diff --git a/assets/benchmarks/shaders/Benchmark_Texture.hlsl b/assets/benchmarks/shaders/Benchmark_Texture.hlsl index 332eee14b..e9fac5e4e 100644 --- a/assets/benchmarks/shaders/Benchmark_Texture.hlsl +++ b/assets/benchmarks/shaders/Benchmark_Texture.hlsl @@ -14,9 +14,15 @@ #include "Benchmark_Quad.hlsli" -Texture2D Tex0 : register(t1); // Slot 0 is used by push constant. +Texture2D Tex[10] : register(t1); // Slot 0 is used by push constant. float4 psmain(VSOutputPos input) : SV_TARGET { - return Tex0.Load(uint3(input.position.x, input.position.y, /* mipmap */ 0)); + uint32_t textureCount = Config.TextureCount; + float4 color = {0.0f, 0.0f, 0.0f, 0.0f}; + for(uint32_t i = 0; i < textureCount; i++) + { + color += Tex[i].Load(uint3(input.position.x, input.position.y, 0))/float(textureCount); + } + return color; } \ No newline at end of file diff --git a/assets/benchmarks/textures/tiger.jpg b/assets/benchmarks/textures/tiger.jpg new file mode 100644 index 000000000..7a6795228 Binary files /dev/null and b/assets/benchmarks/textures/tiger.jpg differ diff --git a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp index b02ff99ae..974123949 100644 --- a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp +++ b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp @@ -186,6 +186,10 @@ void GraphicsBenchmarkApp::InitKnobs() GetKnobManager().InitKnob(&pKnobAluCount, "alu-instruction-count", /* defaultValue = */ 100, /* minValue = */ 100, 400); pKnobAluCount->SetDisplayName("Number of ALU instructions in the shader"); pKnobAluCount->SetFlagDescription("Select the number of ALU instructions in the shader."); + + GetKnobManager().InitKnob(&pKnobTextureCount, "texture-count", /* defaultValue = */ 1, /* minValue = */ 1, kMaxTextureCount); + pKnobTextureCount->SetDisplayName("Number of texture to load in the shader"); + pKnobTextureCount->SetFlagDescription("Select the number of texture to load in the shader."); } void GraphicsBenchmarkApp::Config(ppx::ApplicationSettings& settings) @@ -236,9 +240,9 @@ void GraphicsBenchmarkApp::Setup() // Descriptor Pool { grfx::DescriptorPoolCreateInfo createInfo = {}; - createInfo.sampler = 5 * GetNumFramesInFlight(); // 1 for skybox, 3 for spheres, 1 for blit - createInfo.sampledImage = 6 * GetNumFramesInFlight(); // 1 for skybox, 3 for spheres, 1 for quads, 1 for blit - createInfo.uniformBuffer = 2 * GetNumFramesInFlight(); // 1 for skybox, 1 for spheres + createInfo.sampler = 5 * GetNumFramesInFlight(); // 1 for skybox, 3 for spheres, 1 for blit + createInfo.sampledImage = 15 * GetNumFramesInFlight(); // 1 for skybox, 3 for spheres, 10 for quads, 1 for blit + createInfo.uniformBuffer = 2 * GetNumFramesInFlight(); // 1 for skybox, 1 for spheres PPX_CHECKED_CALL(GetDevice()->CreateDescriptorPool(&createInfo, &mDescriptorPool)); } @@ -472,13 +476,16 @@ void GraphicsBenchmarkApp::SetupFullscreenQuadsResources() { // Large resolution image grfx_util::TextureOptions options = grfx_util::TextureOptions().MipLevelCount(1); - PPX_CHECKED_CALL(CreateTextureFromFile(GetDevice()->GetGraphicsQueue(), GetAssetPath(pQuadTextureFile->GetValue()), &mQuadsTexture, options)); + for (uint32_t i = 0; i < kMaxTextureCount; i++) { + // Load the same image. + PPX_CHECKED_CALL(CreateTextureFromFile(GetDevice()->GetGraphicsQueue(), GetAssetPath(pQuadTextureFile->GetValue()), &mQuadsTextures[i], options)); + } } // Descriptor set layout for texture shader { grfx::DescriptorSetLayoutCreateInfo layoutCreateInfo = {}; - layoutCreateInfo.bindings.push_back(grfx::DescriptorBinding(QUADS_SAMPLED_IMAGE_REGISTER, grfx::DESCRIPTOR_TYPE_SAMPLED_IMAGE)); + layoutCreateInfo.bindings.push_back(grfx::DescriptorBinding(QUADS_SAMPLED_IMAGE_REGISTER, grfx::DESCRIPTOR_TYPE_SAMPLED_IMAGE, kMaxTextureCount)); PPX_CHECKED_CALL(GetDevice()->CreateDescriptorSetLayout(&layoutCreateInfo, &mFullscreenQuads.descriptorSetLayout)); } @@ -542,7 +549,9 @@ void GraphicsBenchmarkApp::UpdateFullscreenQuadsDescriptors() uint32_t n = GetNumFramesInFlight(); for (size_t i = 0; i < n; i++) { grfx::DescriptorSetPtr pDescriptorSet = mFullscreenQuads.descriptorSets[i]; - PPX_CHECKED_CALL(pDescriptorSet->UpdateSampledImage(QUADS_SAMPLED_IMAGE_REGISTER, 0, mQuadsTexture)); + for (uint32_t j = 0; j < kMaxTextureCount; j++) { + PPX_CHECKED_CALL(pDescriptorSet->UpdateSampledImage(QUADS_SAMPLED_IMAGE_REGISTER, j, mQuadsTextures[j])); + } } } @@ -1764,6 +1773,9 @@ void GraphicsBenchmarkApp::RecordCommandBufferFullscreenQuad(PerFrame& frame, si break; } case FullscreenQuadsType::FULLSCREEN_QUADS_TYPE_TEXTURE: + mQuadPushConstant.TextureCount = pKnobTextureCount->GetValue(); + frame.cmd->PushGraphicsConstants(mQuadsPipelineInterfaces[0], GetPushConstCount(mQuadPushConstant.TextureCount), &mQuadPushConstant.TextureCount, offsetof(QuadPushConstant, TextureCount) / sizeof(uint32_t)); + break; default: PPX_ASSERT_MSG(true, "unsupported FullscreenQuadsType: " << static_cast(pFullscreenQuadsType->GetValue())); diff --git a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h index 27c505334..74aa2b278 100644 --- a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h +++ b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h @@ -34,12 +34,13 @@ static constexpr uint32_t kMaxSphereInstanceCount = 3000; static constexpr uint32_t kDefaultSphereInstanceCount = 50; static constexpr uint32_t kSeed = 89977; static constexpr uint32_t kMaxFullscreenQuadsCount = 1000; +static constexpr uint32_t kMaxTextureCount = 10; static constexpr float4 kDefaultDrawCallColor = float4(1.0f, 0.175f, 0.365f, 0.5f); static constexpr uint32_t kDebugColorPushConstantCount = sizeof(float4) / sizeof(uint32_t); static constexpr const char* kShaderBaseDir = "benchmarks/shaders"; -static constexpr const char* kQuadTextureFile = "benchmarks/textures/resolution.jpg"; +static constexpr const char* kQuadTextureFile = "benchmarks/textures/tiger.jpg"; enum class DebugView { @@ -432,6 +433,7 @@ class GraphicsBenchmarkApp { uint32_t InstCount; uint32_t RandomSeed; + uint32_t TextureCount; float3 ColorValue; }; @@ -478,7 +480,7 @@ class GraphicsBenchmarkApp // Fullscreen quads resources Entity2D mFullscreenQuads; grfx::ShaderModulePtr mVSQuads; - grfx::TexturePtr mQuadsTexture; + std::array mQuadsTextures; QuadPipelineMap mQuadsPipelines; std::array mQuadsPipelineInterfaces; std::array mQuadsPs; @@ -529,6 +531,7 @@ class GraphicsBenchmarkApp std::shared_ptr>> pResolution; std::shared_ptr> pKnobAluCount; + std::shared_ptr> pKnobTextureCount; private: // =====================================================================