Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test case 3/4: Disable PS output for ALU and memfetch #502

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/benchmarks/shaders/Benchmark_Texture.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Benchmark_Quad.hlsli"

Texture2D Tex[10] : register(t1); // Slot 0 is used by push constant.
RWStructuredBuffer<float> dataBuffer : register(u11);

float4 psmain(VSOutputPos input) : SV_TARGET
{
Expand All @@ -24,5 +25,7 @@ float4 psmain(VSOutputPos input) : SV_TARGET
{
color += Tex[i].Load(uint3(input.position.x, input.position.y, 0))/float(textureCount);
}
if (!any(color))
dataBuffer[0] = color.r;
return color;
}
30 changes: 29 additions & 1 deletion benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "SphereMesh.h"

#include "ppx/graphics_util.h"
#include "ppx/grfx/grfx_enums.h"
#include "ppx/grfx/grfx_format.h"
#include "ppx/math_config.h"
#include "ppx/timer.h"
Expand All @@ -38,6 +39,7 @@ static constexpr size_t SPHERE_METAL_ROUGHNESS_SAMPLER_REGISTER = 7;

static constexpr size_t QUADS_CONFIG_UNIFORM_BUFFER_REGISTER = 0;
static constexpr size_t QUADS_SAMPLED_IMAGE_REGISTER = 1;
static constexpr size_t QUADS_DUMMY_BUFFER_REGISTER = QUADS_SAMPLED_IMAGE_REGISTER + kMaxTextureCount;

#if defined(USE_DX12)
const grfx::Api kApi = grfx::API_DX_12_0;
Expand Down Expand Up @@ -190,6 +192,10 @@ void GraphicsBenchmarkApp::InitKnobs()
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.");

GetKnobManager().InitKnob(&pKnobDisablePsOutput, "disable-ps-output", false);
pKnobDisablePsOutput->SetDisplayName("Disable PS output");
pKnobDisablePsOutput->SetFlagDescription("Disable PS output.");
}

void GraphicsBenchmarkApp::Config(ppx::ApplicationSettings& settings)
Expand Down Expand Up @@ -243,6 +249,7 @@ void GraphicsBenchmarkApp::Setup()
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
RenfengLiu marked this conversation as resolved.
Show resolved Hide resolved
createInfo.uniformBuffer = 2 * GetNumFramesInFlight(); // 1 for skybox, 1 for spheres
createInfo.structuredBuffer = 1; // 1 for quads dummy buffer

PPX_CHECKED_CALL(GetDevice()->CreateDescriptorPool(&createInfo, &mDescriptorPool));
}
Expand Down Expand Up @@ -482,10 +489,22 @@ void GraphicsBenchmarkApp::SetupFullscreenQuadsResources()
}
}

// dummy buffer
{
grfx::BufferCreateInfo bufferCreateInfo = {};
bufferCreateInfo.size = PPX_MINIMUM_STRUCTURED_BUFFER_SIZE;
bufferCreateInfo.structuredElementStride = static_cast<uint32_t>(sizeof(float));
bufferCreateInfo.usageFlags.bits.rwStructuredBuffer = true;
bufferCreateInfo.memoryUsage = grfx::MEMORY_USAGE_GPU_ONLY;
bufferCreateInfo.initialState = grfx::RESOURCE_STATE_GENERAL;
PPX_CHECKED_CALL(GetDevice()->CreateBuffer(&bufferCreateInfo, &mQuadsDummyBuffer));
}

// Descriptor set layout for texture shader
{
grfx::DescriptorSetLayoutCreateInfo layoutCreateInfo = {};
layoutCreateInfo.bindings.push_back(grfx::DescriptorBinding(QUADS_SAMPLED_IMAGE_REGISTER, grfx::DESCRIPTOR_TYPE_SAMPLED_IMAGE, kMaxTextureCount));
layoutCreateInfo.bindings.push_back(grfx::DescriptorBinding(QUADS_DUMMY_BUFFER_REGISTER, grfx::DESCRIPTOR_TYPE_RW_STRUCTURED_BUFFER));
PPX_CHECKED_CALL(GetDevice()->CreateDescriptorSetLayout(&layoutCreateInfo, &mFullscreenQuads.descriptorSetLayout));
}

Expand Down Expand Up @@ -552,6 +571,15 @@ void GraphicsBenchmarkApp::UpdateFullscreenQuadsDescriptors()
for (uint32_t j = 0; j < kMaxTextureCount; j++) {
PPX_CHECKED_CALL(pDescriptorSet->UpdateSampledImage(QUADS_SAMPLED_IMAGE_REGISTER, j, mQuadsTextures[j]));
}
grfx::WriteDescriptor write = {};
write.binding = QUADS_DUMMY_BUFFER_REGISTER;
write.arrayIndex = 0;
write.type = grfx::DESCRIPTOR_TYPE_RW_STRUCTURED_BUFFER;
write.bufferOffset = 0;
write.bufferRange = PPX_WHOLE_SIZE;
write.structuredElementCount = 1;
write.pBuffer = mQuadsDummyBuffer;
PPX_CHECKED_CALL(pDescriptorSet->UpdateDescriptors(1, &write));
}
}

Expand Down Expand Up @@ -751,7 +779,7 @@ Result GraphicsBenchmarkApp::CompilePipeline(const QuadPipelineKey& key)
gpCreateInfo.frontFace = grfx::FRONT_FACE_CW;
gpCreateInfo.depthReadEnable = false;
gpCreateInfo.depthWriteEnable = false;
gpCreateInfo.blendModes[0] = grfx::BLEND_MODE_NONE;
gpCreateInfo.blendModes[0] = pKnobDisablePsOutput->GetValue() ? grfx::BLEND_MODE_BENCHMARK_DISABLE_OUTPUT : grfx::BLEND_MODE_NONE;
gpCreateInfo.outputState.renderTargetCount = 1;
gpCreateInfo.outputState.renderTargetFormats[0] = key.renderFormat;
gpCreateInfo.outputState.depthStencilFormat = GetSwapchain()->GetDepthFormat();
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ class GraphicsBenchmarkApp
Entity2D mFullscreenQuads;
grfx::ShaderModulePtr mVSQuads;
std::array<grfx::TexturePtr, kMaxTextureCount> mQuadsTextures;
grfx::BufferPtr mQuadsDummyBuffer;
QuadPipelineMap mQuadsPipelines;
std::array<grfx::PipelineInterfacePtr, kFullscreenQuadsTypes.size()> mQuadsPipelineInterfaces;
std::array<grfx::ShaderModulePtr, kFullscreenQuadsTypes.size()> mQuadsPs;
Expand Down Expand Up @@ -532,6 +533,7 @@ class GraphicsBenchmarkApp

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

private:
// =====================================================================
Expand Down
13 changes: 7 additions & 6 deletions include/ppx/grfx/grfx_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ enum BlendFactor
//!
enum BlendMode
{
BLEND_MODE_NONE = 0,
BLEND_MODE_ADDITIVE = 1,
BLEND_MODE_ALPHA = 2,
BLEND_MODE_OVER = 3,
BLEND_MODE_UNDER = 4,
BLEND_MODE_PREMULT_ALPHA = 5,
BLEND_MODE_NONE = 0,
BLEND_MODE_ADDITIVE = 1,
BLEND_MODE_ALPHA = 2,
BLEND_MODE_OVER = 3,
BLEND_MODE_UNDER = 4,
BLEND_MODE_PREMULT_ALPHA = 5,
BLEND_MODE_BENCHMARK_DISABLE_OUTPUT = 6, // Mode used for benchmark app to disable vs output.
};

enum BlendOp
Expand Down
1 change: 1 addition & 0 deletions include/ppx/grfx/grfx_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ struct BlendAttachmentState
static grfx::BlendAttachmentState BlendModeOver();
static grfx::BlendAttachmentState BlendModeUnder();
static grfx::BlendAttachmentState BlendModePremultAlpha();
static grfx::BlendAttachmentState BlendModeBenchmarkDisableOutput();
};

struct ColorBlendState
Expand Down
25 changes: 23 additions & 2 deletions src/ppx/grfx/grfx_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "ppx/grfx/grfx_device.h"
#include "ppx/grfx/grfx_pipeline.h"
#include "ppx/grfx/grfx_descriptor.h"
#include "ppx/grfx/grfx_enums.h"

namespace ppx {
namespace grfx {
Expand Down Expand Up @@ -97,6 +98,21 @@ grfx::BlendAttachmentState BlendAttachmentState::BlendModePremultAlpha()
return state;
}

grfx::BlendAttachmentState BlendAttachmentState::BlendModeBenchmarkDisableOutput()
{
RenfengLiu marked this conversation as resolved.
Show resolved Hide resolved
grfx::BlendAttachmentState state = {};
state.blendEnable = false;
state.srcColorBlendFactor = grfx::BLEND_FACTOR_ONE;
RenfengLiu marked this conversation as resolved.
Show resolved Hide resolved
state.dstColorBlendFactor = grfx::BLEND_FACTOR_ONE;
state.colorBlendOp = grfx::BLEND_OP_ADD;
state.srcAlphaBlendFactor = grfx::BLEND_FACTOR_ONE;
state.dstAlphaBlendFactor = grfx::BLEND_FACTOR_ONE;
state.alphaBlendOp = grfx::BLEND_OP_ADD;
state.colorWriteMask = grfx::ColorComponentFlags(0);

return state;
}

namespace internal {

// -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -153,7 +169,10 @@ void FillOutGraphicsPipelineCreateInfo(
pDstCreateInfo->colorBlendState.blendAttachmentCount = pSrcCreateInfo->outputState.renderTargetCount;
for (uint32_t i = 0; i < pDstCreateInfo->colorBlendState.blendAttachmentCount; ++i) {
switch (pSrcCreateInfo->blendModes[i]) {
default: break;
default: {
pDstCreateInfo->colorBlendState.blendAttachments[i].colorWriteMask = grfx::ColorComponentFlags::RGBA();
RenfengLiu marked this conversation as resolved.
Show resolved Hide resolved
break;
}

case grfx::BLEND_MODE_ADDITIVE: {
pDstCreateInfo->colorBlendState.blendAttachments[i] = grfx::BlendAttachmentState::BlendModeAdditive();
Expand All @@ -174,8 +193,10 @@ void FillOutGraphicsPipelineCreateInfo(
case grfx::BLEND_MODE_PREMULT_ALPHA: {
pDstCreateInfo->colorBlendState.blendAttachments[i] = grfx::BlendAttachmentState::BlendModePremultAlpha();
} break;
case grfx::BLEND_MODE_BENCHMARK_DISABLE_OUTPUT: {
pDstCreateInfo->colorBlendState.blendAttachments[i] = grfx::BlendAttachmentState::BlendModeBenchmarkDisableOutput();
}
}
pDstCreateInfo->colorBlendState.blendAttachments[i].colorWriteMask = grfx::ColorComponentFlags::RGBA();
}
}

Expand Down
Loading