Skip to content

Commit

Permalink
Test case to run number of ALU instructions (google#500)
Browse files Browse the repository at this point in the history
added a new knob `alu-instruction-count`. The sample can be run with
following knobs:
 "enable-skybox": false,
    "enable-spheres": false,
    "enable-metrics": false,
    "fullscreen-quads-count": 1,
    "fullscreen-quads-type": "Solid_Color",
    "fullscreen-quads-single-renderpass": true,
    "alu-instruction-count": 200
  • Loading branch information
RenfengLiu committed Jan 23, 2025
1 parent 001de7f commit 606bc18
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 47 deletions.
42 changes: 42 additions & 0 deletions assets/benchmarks/shaders/Benchmark_Quad.hlsli
Original file line number Diff line number Diff line change
@@ -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<ConfigParams> 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
14 changes: 2 additions & 12 deletions assets/benchmarks/shaders/Benchmark_RandomNoise.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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<RandomParams> Random : register(b0);
#include "Benchmark_Quad.hlsli"

float random(float2 st, uint32_t seed) {
float underOne = sin(float(seed) + 0.5f);
Expand All @@ -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);
}
16 changes: 4 additions & 12 deletions assets/benchmarks/shaders/Benchmark_SolidColor.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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<ColorParams> 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;
}
4 changes: 2 additions & 2 deletions assets/benchmarks/shaders/Benchmark_Texture.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
12 changes: 6 additions & 6 deletions assets/benchmarks/shaders/Benchmark_VsSimpleQuads.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 4 additions & 4 deletions assets/benchmarks/shaders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 33 additions & 10 deletions benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstdint>

using namespace ppx;

Expand All @@ -34,14 +36,21 @@ 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;
#elif defined(USE_VK)
const grfx::Api kApi = grfx::API_VK_1_1;
#endif

template <typename T>
size_t GetPushConstCount(const T&)
{
return sizeof(T) / sizeof(uint32_t);
}

void GraphicsBenchmarkApp::InitKnobs()
{
const auto& cl_options = GetExtraOptions();
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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]));
Expand All @@ -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]));
Expand All @@ -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]));
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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: {
Expand All @@ -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:
Expand All @@ -1747,6 +1769,7 @@ void GraphicsBenchmarkApp::RecordCommandBufferFullscreenQuad(PerFrame& frame, si
PPX_ASSERT_MSG(true, "unsupported FullscreenQuadsType: " << static_cast<int>(pFullscreenQuadsType->GetValue()));
break;
}

frame.cmd->Draw(3, 1, 0, 0);
}

Expand Down
12 changes: 12 additions & 0 deletions benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpherePipelineKey, grfx::GraphicsPipelinePtr, SpherePipelineKey::Hash>;
using SkyboxPipelineMap = std::unordered_map<SkyBoxPipelineKey, grfx::GraphicsPipelinePtr, SkyBoxPipelineKey::Hash>;
Expand Down Expand Up @@ -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<KnobCheckbox> pEnableSkyBox;
std::shared_ptr<KnobCheckbox> pEnableSpheres;
Expand All @@ -518,6 +528,8 @@ class GraphicsBenchmarkApp
std::shared_ptr<KnobDropdown<grfx::Format>> pFramebufferFormat;
std::shared_ptr<KnobDropdown<std::pair<int, int>>> pResolution;

std::shared_ptr<KnobFlag<int>> pKnobAluCount;

private:
// =====================================================================
// SETUP (One-time setup for objects)
Expand Down
5 changes: 4 additions & 1 deletion src/android/AndroidManifest.XR.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
<meta-data android:name="com.oculus.intent.category.VR" android:value="vr_only"/>
<meta-data android:name="com.oculus.supportedDevices" android:value="quest|quest2|cambria"/>
<!-- -->

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@android:drawable/ic_info"
Expand Down

0 comments on commit 606bc18

Please sign in to comment.