diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b16f7df3..324e7f733 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 \ @@ -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) diff --git a/assets/benchmarks/shaders/Benchmark_Texture.hlsl b/assets/benchmarks/shaders/Benchmark_Texture.hlsl index e9fac5e4e..9257f2047 100644 --- a/assets/benchmarks/shaders/Benchmark_Texture.hlsl +++ b/assets/benchmarks/shaders/Benchmark_Texture.hlsl @@ -15,6 +15,7 @@ #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 { @@ -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; } \ No newline at end of file diff --git a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp index 974123949..fd1a54188 100644 --- a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp +++ b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp @@ -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" @@ -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; @@ -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) @@ -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)); } @@ -482,10 +489,22 @@ void GraphicsBenchmarkApp::SetupFullscreenQuadsResources() } } + // dummy buffer + { + grfx::BufferCreateInfo bufferCreateInfo = {}; + bufferCreateInfo.size = PPX_MINIMUM_STRUCTURED_BUFFER_SIZE; + bufferCreateInfo.structuredElementStride = static_cast(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)); } @@ -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)); } } @@ -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(); diff --git a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h index 74aa2b278..c23c373e4 100644 --- a/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h +++ b/benchmarks/graphics_pipeline/GraphicsBenchmarkApp.h @@ -481,6 +481,7 @@ class GraphicsBenchmarkApp Entity2D mFullscreenQuads; grfx::ShaderModulePtr mVSQuads; std::array mQuadsTextures; + grfx::BufferPtr mQuadsDummyBuffer; QuadPipelineMap mQuadsPipelines; std::array mQuadsPipelineInterfaces; std::array mQuadsPs; @@ -532,6 +533,7 @@ class GraphicsBenchmarkApp std::shared_ptr> pKnobAluCount; std::shared_ptr> pKnobTextureCount; + std::shared_ptr pKnobDisablePsOutput; private: // ===================================================================== diff --git a/include/ppx/grfx/grfx_enums.h b/include/ppx/grfx/grfx_enums.h index 16f3e81ff..67aad7814 100644 --- a/include/ppx/grfx/grfx_enums.h +++ b/include/ppx/grfx/grfx_enums.h @@ -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 diff --git a/include/ppx/grfx/grfx_pipeline.h b/include/ppx/grfx/grfx_pipeline.h index c82ea5d4c..71963b44a 100644 --- a/include/ppx/grfx/grfx_pipeline.h +++ b/include/ppx/grfx/grfx_pipeline.h @@ -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 diff --git a/src/ppx/grfx/grfx_pipeline.cpp b/src/ppx/grfx/grfx_pipeline.cpp index 92f4fde13..3a144d335 100644 --- a/src/ppx/grfx/grfx_pipeline.cpp +++ b/src/ppx/grfx/grfx_pipeline.cpp @@ -12,9 +12,11 @@ // 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 { @@ -22,6 +24,15 @@ 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 = {}; @@ -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 { // ------------------------------------------------------------------------------------------------- @@ -123,7 +143,7 @@ void FillOutGraphicsPipelineCreateInfo( } } - // Input aasembly + // Input assembly { pDstCreateInfo->inputAssemblyState.topology = pSrcCreateInfo->topology; } @@ -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(); @@ -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(); } }