diff --git a/assets/benchmarks/shaders/Benchmark_Texture-100.hlsl b/assets/benchmarks/shaders/Benchmark_Texture-100.hlsl new file mode 100644 index 000000000..88adef299 --- /dev/null +++ b/assets/benchmarks/shaders/Benchmark_Texture-100.hlsl @@ -0,0 +1,43 @@ +// Copyright 2023 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. + +#include "Benchmark_Quad.hlsli" + +Texture2D Tex[10] : register(t1); // Slot 0 is used by push constant. +RWStructuredBuffer dataBuffer : register(u11); + +float4 psmain(VSOutputPos input) : SV_TARGET +{ + uint32_t textureCount = Config.TextureCount; + float4 color1 = {0.0f, 0.0f, 0.0f, 0.0f}; + float4 color2 = {0.0f, 0.0f, 0.0f, 0.0f}; + float4 color3 = {0.0f, 0.0f, 0.0f, 0.0f}; + for(uint32_t i = 0; i < textureCount; i++) + { + color1 += Tex[i].Load(uint3(input.position.x, input.position.y, 0))/float(textureCount); + } + for(uint32_t i = 0; i < textureCount; i++) + { + color2 += Tex[i].Load(uint3(input.position.x, input.position.y, 0)); + } + for(uint32_t i = 0; i < textureCount; i++) + { + color3 += Tex[i].Load(uint3(input.position.x + 1, input.position.y + 1, 0))/float(textureCount); + } + float4 color = color1 + 0.5f * color2 + 0.25f * color3; + if (!any(color)) + dataBuffer[0] = color.r; + color.a = randomCompute(Config.InstCount, input.position); + return color; +} \ No newline at end of file diff --git a/assets/benchmarks/shaders/Benchmark_Texture-62.hlsl b/assets/benchmarks/shaders/Benchmark_Texture-62.hlsl new file mode 100644 index 000000000..969e35f5d --- /dev/null +++ b/assets/benchmarks/shaders/Benchmark_Texture-62.hlsl @@ -0,0 +1,42 @@ +// Copyright 2023 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. + +#include "Benchmark_Quad.hlsli" + +Texture2D Tex[10] : register(t1); // Slot 0 is used by push constant. +RWStructuredBuffer dataBuffer : register(u11); + +float4 psmain(VSOutputPos input) : SV_TARGET +{ + uint32_t textureCount = Config.TextureCount; + float4 color1 = {0.0f, 0.0f, 0.0f, 0.0f}; + float4 color2 = {0.0f, 0.0f, 0.0f, 0.0f}; + + for(uint32_t i = 0; i < textureCount; i++) + { + color1 += Tex[i].Load(uint3(input.position.x, input.position.y, 0))/float(textureCount); + } + + for(uint32_t i = 0; i < textureCount; i++) + { + color2 += Tex[i].Load(uint3(input.position.x, input.position.y, 0)); + } + + float4 color = color1 + 0.5f * color2; + + if (!any(color)) + dataBuffer[0] = color.r; + 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-75.hlsl similarity index 80% rename from assets/benchmarks/shaders/Benchmark_Texture.hlsl rename to assets/benchmarks/shaders/Benchmark_Texture-75.hlsl index a3aceff58..902de0996 100644 --- a/assets/benchmarks/shaders/Benchmark_Texture.hlsl +++ b/assets/benchmarks/shaders/Benchmark_Texture-75.hlsl @@ -20,13 +20,16 @@ RWStructuredBuffer dataBuffer : register(u11); float4 psmain(VSOutputPos input) : SV_TARGET { uint32_t textureCount = Config.TextureCount; - float4 color = {0.0f, 0.0f, 0.0f, 0.0f}; + float4 color1 = {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); + color1 += Tex[i].Load(uint3(input.position.x, input.position.y, 0))/float(textureCount); } + + float4 color = color1; if (!any(color)) dataBuffer[0] = color.r; - color.a = randomCompute(Config.InstCount, input.position); + color.a = randomCompute(Config.InstCount, input.position); return color; -} \ No newline at end of file +} diff --git a/assets/benchmarks/shaders/CMakeLists.txt b/assets/benchmarks/shaders/CMakeLists.txt index fe16bdde2..908bfee25 100644 --- a/assets/benchmarks/shaders/CMakeLists.txt +++ b/assets/benchmarks/shaders/CMakeLists.txt @@ -95,8 +95,18 @@ generate_rules_for_shader("shader_benchmark_solid_color" 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" +generate_rules_for_shader("shader_benchmark_texture-75" + SOURCE "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_Texture-75.hlsl" + INCLUDES "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_Quad.hlsli" + STAGES "ps") + +generate_rules_for_shader("shader_benchmark_texture-100" + SOURCE "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_Texture-100.hlsl" + INCLUDES "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_Quad.hlsli" + STAGES "ps") + +generate_rules_for_shader("shader_benchmark_texture-62" + SOURCE "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_Texture-62.hlsl" INCLUDES "${PPX_DIR}/assets/benchmarks/shaders/Benchmark_Quad.hlsli" STAGES "ps") diff --git a/benchmarks/graphics_pipeline/CMakeLists.txt b/benchmarks/graphics_pipeline/CMakeLists.txt index cc9015e0a..842cd2df4 100644 --- a/benchmarks/graphics_pipeline/CMakeLists.txt +++ b/benchmarks/graphics_pipeline/CMakeLists.txt @@ -15,7 +15,7 @@ project(graphics_pipeline) add_samples_for_all_apis( NAME ${PROJECT_NAME} - SOURCES + SOURCES "FreeCamera.h" "FreeCamera.cpp" "GraphicsBenchmarkApp.h" @@ -34,6 +34,8 @@ add_samples_for_all_apis( "shader_benchmark_random_noise" "shader_benchmark_skybox" "shader_benchmark_solid_color" - "shader_benchmark_texture" + "shader_benchmark_texture-75" + "shader_benchmark_texture-100" + "shader_benchmark_texture-62" "shader_benchmark_vs_simple_quads" "shader_fullscreen_triangle") diff --git a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp index 663a33f3a..660296a84 100644 --- a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp +++ b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp @@ -131,6 +131,11 @@ void GraphicsBenchmarkApp::InitKnobs() pFullscreenQuadsType->SetFlagDescription("Select the type of the fullscreen quads. See also `--fullscreen-quads-count`."); pFullscreenQuadsType->SetIndent(1); + GetKnobManager().InitKnob(&pTextureShaderALU, "alu-ocupancy-level", /* defaultValue = */ 0, /* minValue = */ 0, 3); + pTextureShaderALU->SetDisplayName("ALU ocuppancy level for texture shader."); + pTextureShaderALU->SetFlagDescription("Select occupancy level: 0 -> 75, 1 -> 100, 2 -> 62."); + pTextureShaderALU->SetVisible(false); + GetKnobManager().InitKnob(&pFullscreenQuadsColor, "fullscreen-quads-color", 0, kFullscreenQuadsColors); pFullscreenQuadsColor->SetDisplayName("Color"); pFullscreenQuadsColor->SetFlagDescription("Select the hue for the solid color fullscreen quads. See also `--fullscreen-quads-count`."); @@ -542,7 +547,28 @@ void GraphicsBenchmarkApp::SetupFullscreenQuadsResources() SetupShader("Benchmark_VsSimpleQuads.vs", &mVSQuads); SetupShader("Benchmark_RandomNoise.ps", &mQuadsPs[0]); SetupShader("Benchmark_SolidColor.ps", &mQuadsPs[1]); - SetupShader("Benchmark_Texture.ps", &mQuadsPs[2]); + // We choose a shader based on ALU occupancy + switch (pTextureShaderALU->GetValue()) { + case 0: + // This shader has 75% of ALU occupancy + SetupShader("Benchmark_Texture-75.ps", &mQuadsPs[2]); + break; + + case 1: + // This shader has 100% of ALU occupancy + SetupShader("Benchmark_Texture-100.ps", &mQuadsPs[2]); + break; + + case 2: + // This shader has 62% of ALU occupancy + SetupShader("Benchmark_Texture-62.ps", &mQuadsPs[2]); + break; + + default: + // This shader has 75% of ALU occupancy + // We use it as default since it has less operations + SetupShader("Benchmark_Texture-75.ps", &mQuadsPs[2]); + } } void GraphicsBenchmarkApp::UpdateSkyBoxDescriptors() diff --git a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h index d716feb0b..b0bcb25ee 100644 --- a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h +++ b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h @@ -540,6 +540,7 @@ class GraphicsBenchmarkApp std::shared_ptr> pFullscreenQuadsCount; std::shared_ptr> pFullscreenQuadsType; + std::shared_ptr> pTextureShaderALU; std::shared_ptr> pFullscreenQuadsColor; std::shared_ptr pFullscreenQuadsSingleRenderpass; std::shared_ptr> pQuadTextureFile;