Skip to content

Commit

Permalink
Test case 3/4: Disable PS output for ALU and memfetch (#502)
Browse files Browse the repository at this point in the history
Added knob `disable-ps-output` to disable PS output.
For test case 3, use ` "fullscreen-quads-type": "Solid_Color"` and for
test case 4 use ` "fullscreen-quads-type": "Texture"`
{
    "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,
    "disable-ps-output": true
}
  • Loading branch information
RenfengLiu authored Aug 15, 2024
1 parent 6d1a173 commit 657f22a
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 20 deletions.
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_DISABLED_WARNINGS} /MP /Zc:__cplusplus /std:c++17")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Werror \
-std=c++17 \
-fdiagnostics-color=always \
-Wno-nullability-completeness \
Expand All @@ -153,12 +154,6 @@ else()
-Wno-pointer-bool-conversion \
")

if (NOT PPX_BUILD_XR)
# OpenXR has way too many warnings to enable -Werror with it.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Werror \
")
endif ()
endif()

set(CMAKE_CXX_STANDARD 17)
Expand Down
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;
}
36 changes: 32 additions & 4 deletions 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 @@ -240,9 +246,10 @@ void GraphicsBenchmarkApp::Setup()
// Descriptor Pool
{
grfx::DescriptorPoolCreateInfo createInfo = {};
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
createInfo.sampler = 5 * GetNumFramesInFlight(); // 1 for skybox, 3 for spheres, 1 for blit
createInfo.sampledImage = (5 + kMaxTextureCount) * GetNumFramesInFlight(); // 1 for skybox, 3 for spheres, kMaxTextureCount for quads, 1 for blit
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_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_DISABLE_OUTPUT = 6, // Mode used to disable vs output.
};

enum BlendOp
Expand Down
4 changes: 3 additions & 1 deletion include/ppx/grfx/grfx_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ struct BlendAttachmentState
grfx::ColorComponentFlags colorWriteMask = grfx::ColorComponentFlags::RGBA();

// These are best guesses based on random formulas off of the internet.
// Correct later when authorative literature is found.
// Correct later when authoritative literature is found.
//
static grfx::BlendAttachmentState BlendModeNone();
static grfx::BlendAttachmentState BlendModeAdditive();
static grfx::BlendAttachmentState BlendModeAlpha();
static grfx::BlendAttachmentState BlendModeOver();
static grfx::BlendAttachmentState BlendModeUnder();
static grfx::BlendAttachmentState BlendModePremultAlpha();
static grfx::BlendAttachmentState BlendModeDisableOutput();
};

struct ColorBlendState
Expand Down
38 changes: 35 additions & 3 deletions src/ppx/grfx/grfx_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,27 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "ppx/config.h"
#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 {

// -------------------------------------------------------------------------------------------------
// BlendAttachmentState
// -------------------------------------------------------------------------------------------------
grfx::BlendAttachmentState BlendAttachmentState::BlendModeNone()
{
grfx::BlendAttachmentState state = {};
state.blendEnable = false;
state.colorWriteMask = grfx::ColorComponentFlags::RGBA();

return state;
}

grfx::BlendAttachmentState BlendAttachmentState::BlendModeAdditive()
{
grfx::BlendAttachmentState state = {};
Expand Down Expand Up @@ -97,6 +108,15 @@ grfx::BlendAttachmentState BlendAttachmentState::BlendModePremultAlpha()
return state;
}

grfx::BlendAttachmentState BlendAttachmentState::BlendModeDisableOutput()
{
grfx::BlendAttachmentState state = {};
state.blendEnable = false;
state.colorWriteMask = grfx::ColorComponentFlags(0);

return state;
}

namespace internal {

// -------------------------------------------------------------------------------------------------
Expand All @@ -123,7 +143,7 @@ void FillOutGraphicsPipelineCreateInfo(
}
}

// Input aasembly
// Input assembly
{
pDstCreateInfo->inputAssemblyState.topology = pSrcCreateInfo->topology;
}
Expand Down Expand Up @@ -153,7 +173,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;
case grfx::BLEND_MODE_NONE: {
pDstCreateInfo->colorBlendState.blendAttachments[i] = grfx::BlendAttachmentState::BlendModeNone();
break;
}

case grfx::BLEND_MODE_ADDITIVE: {
pDstCreateInfo->colorBlendState.blendAttachments[i] = grfx::BlendAttachmentState::BlendModeAdditive();
Expand All @@ -174,8 +197,17 @@ void FillOutGraphicsPipelineCreateInfo(
case grfx::BLEND_MODE_PREMULT_ALPHA: {
pDstCreateInfo->colorBlendState.blendAttachments[i] = grfx::BlendAttachmentState::BlendModePremultAlpha();
} break;

case grfx::BLEND_MODE_DISABLE_OUTPUT: {
pDstCreateInfo->colorBlendState.blendAttachments[i] = grfx::BlendAttachmentState::BlendModeDisableOutput();
break;
}

default: {
PPX_ASSERT_MSG(false, "Unknown BlendMode");
break;
}
}
pDstCreateInfo->colorBlendState.blendAttachments[i].colorWriteMask = grfx::ColorComponentFlags::RGBA();
}
}

Expand Down

0 comments on commit 657f22a

Please sign in to comment.