Skip to content

Commit

Permalink
Test case google#2: PS Mem fetch with output (google#501)
Browse files Browse the repository at this point in the history
The test cases add a new knob `texture-count`, and can be run with 

```
{
    "deterministic": true,
    "enable-skybox": false,
    "enable-spheres": false,
    "enable-metrics": false,
    "fullscreen-quads-count": 1,
    "fullscreen-quads-type": "Texture",
    "fullscreen-quads-single-renderpass": true,
    "vs-alu-instruction-count": 100,
    "texture-count": 2
}
```
  • Loading branch information
RenfengLiu committed Jan 23, 2025
1 parent 606bc18 commit 1de69dc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions assets/benchmarks/shaders/Benchmark_Quad.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
struct ConfigParams {
uint32_t InstCount;
uint32_t RandomSeed;
uint32_t TextureCount;
float3 ColorValue;
};

Expand Down
10 changes: 8 additions & 2 deletions assets/benchmarks/shaders/Benchmark_Texture.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Binary file added assets/benchmarks/textures/tiger.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 18 additions & 6 deletions benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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]));
}
}
}

Expand Down Expand Up @@ -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<int>(pFullscreenQuadsType->GetValue()));
Expand Down
7 changes: 5 additions & 2 deletions benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -432,6 +433,7 @@ class GraphicsBenchmarkApp
{
uint32_t InstCount;
uint32_t RandomSeed;
uint32_t TextureCount;
float3 ColorValue;
};

Expand Down Expand Up @@ -478,7 +480,7 @@ class GraphicsBenchmarkApp
// Fullscreen quads resources
Entity2D mFullscreenQuads;
grfx::ShaderModulePtr mVSQuads;
grfx::TexturePtr mQuadsTexture;
std::array<grfx::TexturePtr, kMaxTextureCount> mQuadsTextures;
QuadPipelineMap mQuadsPipelines;
std::array<grfx::PipelineInterfacePtr, kFullscreenQuadsTypes.size()> mQuadsPipelineInterfaces;
std::array<grfx::ShaderModulePtr, kFullscreenQuadsTypes.size()> mQuadsPs;
Expand Down Expand Up @@ -529,6 +531,7 @@ class GraphicsBenchmarkApp
std::shared_ptr<KnobDropdown<std::pair<int, int>>> pResolution;

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

private:
// =====================================================================
Expand Down

0 comments on commit 1de69dc

Please sign in to comment.