diff --git a/assets/benchmarks/shaders/Benchmark_Quad.hlsli b/assets/benchmarks/shaders/Benchmark_Quad.hlsli new file mode 100644 index 000000000..019b955f8 --- /dev/null +++ b/assets/benchmarks/shaders/Benchmark_Quad.hlsli @@ -0,0 +1,42 @@ +// Copyright 2024 Google LLC +// +// 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 +// +// https://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. + +#ifndef BENCHMARKS_QUAD_HLSLI +#define BENCHMARKS_QUAD_HLSLI + +struct ConfigParams { + uint32_t InstCount; + uint32_t RandomSeed; + float3 ColorValue; +}; + +#if defined(__spirv__) +[[vk::push_constant]] +#endif +ConstantBuffer Config : register(b0); + +struct VSOutputPos { + float4 position : SV_POSITION; +}; + +float randomCompute(uint32_t instCount, float4 Position) { + float randNum = frac(float(instCount) * 123.456f); + for (uint32_t i = 0; i < instCount; i++) { + Position.z += Position.x * (1 - randNum) + randNum * Position.y; + } + + return frac(Position.z);; +} + +#endif // BENCHMARKS_QUAD_HLSLI \ No newline at end of file diff --git a/assets/benchmarks/shaders/Benchmark_RandomNoise.hlsl b/assets/benchmarks/shaders/Benchmark_RandomNoise.hlsl index 60496b688..237751458 100644 --- a/assets/benchmarks/shaders/Benchmark_RandomNoise.hlsl +++ b/assets/benchmarks/shaders/Benchmark_RandomNoise.hlsl @@ -12,17 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "VsOutput.hlsli" - -struct RandomParams -{ - uint32_t Seed; -}; - -#if defined(__spirv__) -[[vk::push_constant]] -#endif -ConstantBuffer Random : register(b0); +#include "Benchmark_Quad.hlsli" float random(float2 st, uint32_t seed) { float underOne = sin(float(seed) + 0.5f); @@ -32,6 +22,6 @@ float random(float2 st, uint32_t seed) { float4 psmain(VSOutputPos input) : SV_TARGET { - float rnd = random(input.position.xy, Random.Seed); + float rnd = random(input.position.xy, Config.RandomSeed); return float4(rnd, rnd, rnd, 1.0f); } \ No newline at end of file diff --git a/assets/benchmarks/shaders/Benchmark_SolidColor.hlsl b/assets/benchmarks/shaders/Benchmark_SolidColor.hlsl index cb1df3df5..d423b7cbf 100644 --- a/assets/benchmarks/shaders/Benchmark_SolidColor.hlsl +++ b/assets/benchmarks/shaders/Benchmark_SolidColor.hlsl @@ -12,19 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "VsOutput.hlsli" - -struct ColorParams -{ - float3 Value; -}; - -#if defined(__spirv__) -[[vk::push_constant]] -#endif -ConstantBuffer Color : register(b0); +#include "Benchmark_Quad.hlsli" float4 psmain(VSOutputPos input) : SV_TARGET { - return float4(Color.Value, 1.0f); + float4 color = float4(Config.ColorValue, 1.0f); + color.a = randomCompute(Config.InstCount, input.position); + return color; } \ No newline at end of file diff --git a/assets/benchmarks/shaders/Benchmark_Texture.hlsl b/assets/benchmarks/shaders/Benchmark_Texture.hlsl index cfbc3441e..332eee14b 100644 --- a/assets/benchmarks/shaders/Benchmark_Texture.hlsl +++ b/assets/benchmarks/shaders/Benchmark_Texture.hlsl @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "VsOutput.hlsli" +#include "Benchmark_Quad.hlsli" -Texture2D Tex0 : register(t0); +Texture2D Tex0 : register(t1); // Slot 0 is used by push constant. float4 psmain(VSOutputPos input) : SV_TARGET { diff --git a/assets/benchmarks/shaders/Benchmark_VsSimpleQuads.hlsl b/assets/benchmarks/shaders/Benchmark_VsSimpleQuads.hlsl index 6dbda6261..88edecab3 100644 --- a/assets/benchmarks/shaders/Benchmark_VsSimpleQuads.hlsl +++ b/assets/benchmarks/shaders/Benchmark_VsSimpleQuads.hlsl @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "VsOutput.hlsli" +#include "Benchmark_Quad.hlsli" -VSOutputPos vsmain(float4 Position : POSITION) -{ - VSOutputPos result; - result.position = Position; - return result; +VSOutputPos vsmain(float4 Position : POSITION) { + VSOutputPos result; + result.position = Position; + result.position.z = randomCompute(Config.InstCount, result.position); + return result; } \ No newline at end of file diff --git a/assets/benchmarks/shaders/CMakeLists.txt b/assets/benchmarks/shaders/CMakeLists.txt index bda4883cb..fe16bdde2 100644 --- a/assets/benchmarks/shaders/CMakeLists.txt +++ b/assets/benchmarks/shaders/CMakeLists.txt @@ -82,22 +82,22 @@ generate_rules_for_shader("shader_benchmark_skybox" generate_rules_for_shader("shader_benchmark_vs_simple_quads" SOURCE "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_VsSimpleQuads.hlsl" - INCLUDES "${PPX_DIR}/assets/benchmarks/shaders/VsOutput.hlsli" + INCLUDES "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_Quad.hlsli" STAGES "vs") generate_rules_for_shader("shader_benchmark_random_noise" SOURCE "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_RandomNoise.hlsl" - INCLUDES "${PPX_DIR}/assets/benchmarks/shaders/VsOutput.hlsli" + INCLUDES "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_Quad.hlsli" STAGES "ps") generate_rules_for_shader("shader_benchmark_solid_color" SOURCE "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_SolidColor.hlsl" - INCLUDES "${PPX_DIR}/assets/benchmarks/shaders/VsOutput.hlsli" + INCLUDES "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_Quad.hlsli" STAGES "ps") generate_rules_for_shader("shader_benchmark_texture" SOURCE "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_Texture.hlsl" - INCLUDES "${PPX_DIR}/assets/benchmarks/shaders/VsOutput.hlsli" + INCLUDES "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_Quad.hlsli" STAGES "ps") generate_rules_for_shader("shader_foveation_benchmark" diff --git a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp index f33c14f8e..b02ff99ae 100644 --- a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp +++ b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp @@ -17,7 +17,9 @@ #include "ppx/graphics_util.h" #include "ppx/grfx/grfx_format.h" +#include "ppx/math_config.h" #include "ppx/timer.h" +#include using namespace ppx; @@ -34,7 +36,8 @@ static constexpr size_t SPHERE_NORMAL_SAMPLER_REGISTER = 5; static constexpr size_t SPHERE_METAL_ROUGHNESS_SAMPLED_IMAGE_REGISTER = 6; static constexpr size_t SPHERE_METAL_ROUGHNESS_SAMPLER_REGISTER = 7; -static constexpr size_t QUADS_SAMPLED_IMAGE_REGISTER = 0; +static constexpr size_t QUADS_CONFIG_UNIFORM_BUFFER_REGISTER = 0; +static constexpr size_t QUADS_SAMPLED_IMAGE_REGISTER = 1; #if defined(USE_DX12) const grfx::Api kApi = grfx::API_DX_12_0; @@ -42,6 +45,12 @@ const grfx::Api kApi = grfx::API_DX_12_0; const grfx::Api kApi = grfx::API_VK_1_1; #endif +template +size_t GetPushConstCount(const T&) +{ + return sizeof(T) / sizeof(uint32_t); +} + void GraphicsBenchmarkApp::InitKnobs() { const auto& cl_options = GetExtraOptions(); @@ -173,6 +182,10 @@ void GraphicsBenchmarkApp::InitKnobs() pResolution->SetFlagDescription("Select the size of offscreen framebuffer."); pResolution->SetIndent(1); } + + 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."); } void GraphicsBenchmarkApp::Config(ppx::ApplicationSettings& settings) @@ -187,7 +200,7 @@ void GraphicsBenchmarkApp::Config(ppx::ApplicationSettings& settings) #if defined(PPX_BUILD_XR) // XR specific settings settings.grfx.pacedFrameRate = 0; - settings.xr.enable = false; // Change this to true to enable the XR mode + settings.xr.enable = true; // Change this to true to enable the XR mode #endif settings.standardKnobsDefaultValue.enableMetrics = true; settings.standardKnobsDefaultValue.overwriteMetricsFile = true; @@ -785,8 +798,8 @@ void GraphicsBenchmarkApp::SetupFullscreenQuadsPipelines() { grfx::PipelineInterfaceCreateInfo piCreateInfo = {}; piCreateInfo.setCount = 0; - piCreateInfo.pushConstants.count = sizeof(uint32_t) / 4; - piCreateInfo.pushConstants.binding = 0; + piCreateInfo.pushConstants.count = GetPushConstCount(mQuadPushConstant); + piCreateInfo.pushConstants.binding = QUADS_CONFIG_UNIFORM_BUFFER_REGISTER; piCreateInfo.pushConstants.set = 0; PPX_CHECKED_CALL(GetDevice()->CreatePipelineInterface(&piCreateInfo, &mQuadsPipelineInterfaces[0])); @@ -795,8 +808,8 @@ void GraphicsBenchmarkApp::SetupFullscreenQuadsPipelines() { grfx::PipelineInterfaceCreateInfo piCreateInfo = {}; piCreateInfo.setCount = 0; - piCreateInfo.pushConstants.count = sizeof(float3) / 4; - piCreateInfo.pushConstants.binding = 0; + piCreateInfo.pushConstants.count = GetPushConstCount(mQuadPushConstant); + piCreateInfo.pushConstants.binding = QUADS_CONFIG_UNIFORM_BUFFER_REGISTER; piCreateInfo.pushConstants.set = 0; PPX_CHECKED_CALL(GetDevice()->CreatePipelineInterface(&piCreateInfo, &mQuadsPipelineInterfaces[1])); @@ -807,6 +820,9 @@ void GraphicsBenchmarkApp::SetupFullscreenQuadsPipelines() piCreateInfo.setCount = 1; piCreateInfo.sets[0].set = 0; piCreateInfo.sets[0].pLayout = mFullscreenQuads.descriptorSetLayout; + piCreateInfo.pushConstants.count = GetPushConstCount(mQuadPushConstant); + piCreateInfo.pushConstants.binding = QUADS_CONFIG_UNIFORM_BUFFER_REGISTER; + piCreateInfo.pushConstants.set = 0; PPX_CHECKED_CALL(GetDevice()->CreatePipelineInterface(&piCreateInfo, &mQuadsPipelineInterfaces[2])); } @@ -1393,7 +1409,7 @@ ppx::Result GraphicsBenchmarkApp::CreateOffscreenFrame(OffscreenFrame& frame, gr frame = OffscreenFrame{width, height, colorFormat, depthFormat}; { grfx::ImageCreateInfo colorCreateInfo = grfx::ImageCreateInfo::RenderTarget2D(width, height, colorFormat); - colorCreateInfo.initialState = grfx::RESOURCE_STATE_PRESENT; + colorCreateInfo.initialState = grfx::RESOURCE_STATE_RENDER_TARGET; colorCreateInfo.usageFlags.bits.sampled = true; ppx::Result ppxres = GetDevice()->CreateImage(&colorCreateInfo, &frame.colorImage); if (ppxres != ppx::SUCCESS) { @@ -1718,10 +1734,15 @@ void GraphicsBenchmarkApp::RecordCommandBufferSpheres(PerFrame& frame) void GraphicsBenchmarkApp::RecordCommandBufferFullscreenQuad(PerFrame& frame, size_t seed) { + // Vertex shader push constant + { + mQuadPushConstant.InstCount = pKnobAluCount->GetValue(); + frame.cmd->PushGraphicsConstants(mQuadsPipelineInterfaces[0], GetPushConstCount(mQuadPushConstant.InstCount), &mQuadPushConstant.InstCount, offsetof(QuadPushConstant, InstCount) / sizeof(uint32_t)); + } switch (pFullscreenQuadsType->GetValue()) { case FullscreenQuadsType::FULLSCREEN_QUADS_TYPE_NOISE: { - uint32_t noiseQuadRandomSeed = (uint32_t)seed; - frame.cmd->PushGraphicsConstants(mQuadsPipelineInterfaces[0], 1, &noiseQuadRandomSeed); + mQuadPushConstant.RandomSeed = seed; + frame.cmd->PushGraphicsConstants(mQuadsPipelineInterfaces[0], GetPushConstCount(mQuadPushConstant.RandomSeed), &mQuadPushConstant.RandomSeed, offsetof(QuadPushConstant, RandomSeed) / sizeof(uint32_t)); break; } case FullscreenQuadsType::FULLSCREEN_QUADS_TYPE_SOLID_COLOR: { @@ -1738,7 +1759,8 @@ void GraphicsBenchmarkApp::RecordCommandBufferFullscreenQuad(PerFrame& frame, si } float3 colorValues = pFullscreenQuadsColor->GetValue(); colorValues *= intensity; - frame.cmd->PushGraphicsConstants(mQuadsPipelineInterfaces[1], 3, &colorValues); + mQuadPushConstant.ColorValue = colorValues; + frame.cmd->PushGraphicsConstants(mQuadsPipelineInterfaces[0], GetPushConstCount(mQuadPushConstant.ColorValue), &mQuadPushConstant.ColorValue, offsetof(QuadPushConstant, ColorValue) / sizeof(uint32_t)); break; } case FullscreenQuadsType::FULLSCREEN_QUADS_TYPE_TEXTURE: @@ -1747,6 +1769,7 @@ void GraphicsBenchmarkApp::RecordCommandBufferFullscreenQuad(PerFrame& frame, si PPX_ASSERT_MSG(true, "unsupported FullscreenQuadsType: " << static_cast(pFullscreenQuadsType->GetValue())); break; } + frame.cmd->Draw(3, 1, 0, 0); } diff --git a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h index f59998ca1..27c505334 100644 --- a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h +++ b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h @@ -427,6 +427,14 @@ class GraphicsBenchmarkApp grfx::FullscreenQuadPtr quad; }; + // Needs to match with the definition at assets/benchmarks/shaders/Benchmark_Quad.hlsli + struct QuadPushConstant + { + uint32_t InstCount; + uint32_t RandomSeed; + float3 ColorValue; + }; + private: using SpherePipelineMap = std::unordered_map; using SkyboxPipelineMap = std::unordered_map; @@ -492,6 +500,8 @@ class GraphicsBenchmarkApp // This is used to skip first several frames after the knob of quad count being changed uint32_t mSkipRecordBandwidthMetricFrameCounter = 0; + QuadPushConstant mQuadPushConstant; + private: std::shared_ptr pEnableSkyBox; std::shared_ptr pEnableSpheres; @@ -518,6 +528,8 @@ class GraphicsBenchmarkApp std::shared_ptr> pFramebufferFormat; std::shared_ptr>> pResolution; + std::shared_ptr> pKnobAluCount; + private: // ===================================================================== // SETUP (One-time setup for objects) diff --git a/src/android/AndroidManifest.XR.xml b/src/android/AndroidManifest.XR.xml index 013a7509a..3845d7e32 100644 --- a/src/android/AndroidManifest.XR.xml +++ b/src/android/AndroidManifest.XR.xml @@ -14,7 +14,10 @@ - + + + +