From bba07fb101e92a9faffe417cd877e0f7043cf762 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Thu, 24 Nov 2022 19:03:06 +0000 Subject: [PATCH] Update for new hades --- .../main/cpp/skyline/common/dirty_tracking.h | 2 +- .../interconnect/maxwell_3d/active_state.cpp | 21 +++-- .../interconnect/maxwell_3d/active_state.h | 1 + .../maxwell_3d/packed_pipeline_state.h | 1 + .../maxwell_3d/pipeline_manager.cpp | 1 + .../maxwell_3d/pipeline_state.cpp | 3 +- .../interconnect/maxwell_3d/pipeline_state.h | 1 + .../main/cpp/skyline/gpu/shader_manager.cpp | 79 ++++++++++++------- app/src/main/cpp/skyline/gpu/shader_manager.h | 25 +----- .../skyline/soc/gm20b/engines/maxwell_3d.cpp | 4 +- 10 files changed, 76 insertions(+), 62 deletions(-) diff --git a/app/src/main/cpp/skyline/common/dirty_tracking.h b/app/src/main/cpp/skyline/common/dirty_tracking.h index 4f27d656..04342eed 100644 --- a/app/src/main/cpp/skyline/common/dirty_tracking.h +++ b/app/src/main/cpp/skyline/common/dirty_tracking.h @@ -33,7 +33,7 @@ namespace skyline::dirty { * @tparam OverlapPoolSize Size of the pool used to store handles when there are multiple bound to the same subresource * @note This class is *NOT* thread-safe */ - template + template class Manager { private: struct BindingState { diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/active_state.cpp b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/active_state.cpp index fadaae0f..36ba2226 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/active_state.cpp +++ b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/active_state.cpp @@ -218,7 +218,8 @@ namespace skyline::gpu::interconnect::maxwell3d { viewport.offsetX, viewport.offsetY, viewport.scaleX, viewport.scaleY, viewport.swizzle, viewportClip, windowOrigin, - viewportScaleOffsetEnable); + viewportScaleOffsetEnable, + surfaceClip); } ViewportState::ViewportState(dirty::Handle dirtyHandle, DirtyManager &manager, const EngineRegisters &engine, u32 index) : engine{manager, dirtyHandle, engine}, index{index} {} @@ -258,14 +259,20 @@ namespace skyline::gpu::interconnect::maxwell3d { if (index != 0 && !ctx.gpu.traits.supportsMultipleViewports) return; - if (!engine->viewportScaleOffsetEnable) - // https://github.com/Ryujinx/Ryujinx/pull/3328 - Logger::Warn("Viewport scale/offset disable is unimplemented"); - - if (engine->viewport.scaleX == 0.0f || engine->viewport.scaleY == 0.0f) + if (!engine->viewportScaleOffsetEnable) { + builder.SetViewport(index, vk::Viewport{ + .x = static_cast(engine->surfaceClip.horizontal.x), + .y = static_cast(engine->surfaceClip.vertical.y), + .width = engine->surfaceClip.horizontal.width ? static_cast(engine->surfaceClip.horizontal.width) : 1.0f, + .height = engine->surfaceClip.vertical.height ? static_cast(engine->surfaceClip.vertical.height) : 1.0f, + .minDepth = 0.0f, + .maxDepth = 1.0f, + }); + } else if (engine->viewport.scaleX == 0.0f || engine->viewport.scaleY == 0.0f) { builder.SetViewport(index, ConvertViewport(engine->viewport0, engine->viewportClip0, engine->windowOrigin, engine->viewportScaleOffsetEnable)); - else + } else { builder.SetViewport(index, ConvertViewport(engine->viewport, engine->viewportClip, engine->windowOrigin, engine->viewportScaleOffsetEnable)); + } } /* Scissor */ diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/active_state.h b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/active_state.h index 99de6442..78acd081 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/active_state.h +++ b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/active_state.h @@ -92,6 +92,7 @@ namespace skyline::gpu::interconnect::maxwell3d { const engine::ViewportClip &viewportClip; const engine::WindowOrigin &windowOrigin; const u32 &viewportScaleOffsetEnable; + const engine::SurfaceClip &surfaceClip; void DirtyBind(DirtyManager &manager, dirty::Handle handle) const; }; diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/packed_pipeline_state.h b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/packed_pipeline_state.h index 1424a629..d0918033 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/packed_pipeline_state.h +++ b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/packed_pipeline_state.h @@ -59,6 +59,7 @@ namespace skyline::gpu::interconnect::maxwell3d { bool alphaTestEnable : 1; bool depthClampEnable : 1; // Use SetDepthClampEnable bool dynamicStateActive : 1; + bool viewportTransformEnable : 1; }; u32 patchSize; diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_manager.cpp b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_manager.cpp index 2daf4a26..b5127bce 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_manager.cpp +++ b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_manager.cpp @@ -192,6 +192,7 @@ namespace skyline::gpu::interconnect::maxwell3d { ConvertCompilerShaderStage(static_cast(i)), shaderBinaries[i].binary, shaderBinaries[i].baseOffset, packedState.bindlessTextureConstantBufferSlotSelect, + packedState.viewportTransformEnable, [&](u32 index, u32 offset) { size_t shaderStage{i > 0 ? (i - 1) : 0}; return constantBuffers[shaderStage][index].Read(ctx.executor, offset); diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.cpp b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.cpp index 027022c7..042c7455 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.cpp +++ b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.cpp @@ -444,7 +444,7 @@ namespace skyline::gpu::interconnect::maxwell3d { /* Global Shader Config State */ void GlobalShaderConfigState::EngineRegisters::DirtyBind(DirtyManager &manager, dirty::Handle handle) const { - manager.Bind(handle, postVtgShaderAttributeSkipMask, bindlessTexture, apiMandatedEarlyZ); + manager.Bind(handle, postVtgShaderAttributeSkipMask, bindlessTexture, apiMandatedEarlyZ, viewportScaleOffsetEnable); } GlobalShaderConfigState::GlobalShaderConfigState(const EngineRegisters &engine) : engine{engine} {} @@ -453,6 +453,7 @@ namespace skyline::gpu::interconnect::maxwell3d { packedState.postVtgShaderAttributeSkipMask = engine.postVtgShaderAttributeSkipMask; packedState.bindlessTextureConstantBufferSlotSelect = engine.bindlessTexture.constantBufferSlotSelect; packedState.apiMandatedEarlyZ = engine.apiMandatedEarlyZ; + packedState.viewportTransformEnable = engine.viewportScaleOffsetEnable; } /* Pipeline State */ diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.h b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.h index 07462f4f..a533e829 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.h +++ b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.h @@ -258,6 +258,7 @@ namespace skyline::gpu::interconnect::maxwell3d { const std::array &postVtgShaderAttributeSkipMask; const engine_common::BindlessTexture &bindlessTexture; const u32 &apiMandatedEarlyZ; + const u32 &viewportScaleOffsetEnable; void DirtyBind(DirtyManager &manager, dirty::Handle handle) const; }; diff --git a/app/src/main/cpp/skyline/gpu/shader_manager.cpp b/app/src/main/cpp/skyline/gpu/shader_manager.cpp index 496382c8..7ecba6b4 100644 --- a/app/src/main/cpp/skyline/gpu/shader_manager.cpp +++ b/app/src/main/cpp/skyline/gpu/shader_manager.cpp @@ -32,6 +32,7 @@ namespace skyline::gpu { .support_float16 = traits.supportsFloat16, .support_int64 = traits.supportsInt64, .needs_demote_reorder = false, + .support_snorm_render_buffer = true }; constexpr u32 TegraX1WarpSize{32}; //!< The amount of threads in a warp on the Tegra X1 @@ -90,14 +91,21 @@ namespace skyline::gpu { span binary; u32 baseOffset; u32 textureBufferIndex; + bool viewportTransformEnabled; ShaderManager::ConstantBufferRead constantBufferRead; ShaderManager::GetTextureType getTextureType; public: - std::vector constantBufferWords; - std::vector textureTypes; - - GraphicsEnvironment(const std::array &postVtgShaderAttributeSkipMask, Shader::Stage pStage, span pBinary, u32 baseOffset, u32 textureBufferIndex, ShaderManager::ConstantBufferRead constantBufferRead, ShaderManager::GetTextureType getTextureType) : binary{pBinary}, baseOffset{baseOffset}, textureBufferIndex{textureBufferIndex}, constantBufferRead{std::move(constantBufferRead)}, getTextureType{std::move(getTextureType)} { + GraphicsEnvironment(const std::array &postVtgShaderAttributeSkipMask, + Shader::Stage pStage, + span pBinary, u32 baseOffset, + u32 textureBufferIndex, + bool viewportTransformEnabled, + ShaderManager::ConstantBufferRead constantBufferRead, ShaderManager::GetTextureType getTextureType) + : binary{pBinary}, baseOffset{baseOffset}, + textureBufferIndex{textureBufferIndex}, + viewportTransformEnabled{viewportTransformEnabled}, + constantBufferRead{std::move(constantBufferRead)}, getTextureType{std::move(getTextureType)} { gp_passthrough_mask = postVtgShaderAttributeSkipMask; stage = pStage; sph = *reinterpret_cast(binary.data()); @@ -112,15 +120,19 @@ namespace skyline::gpu { } [[nodiscard]] u32 ReadCbufValue(u32 index, u32 offset) final { - auto value{constantBufferRead(index, offset)}; - constantBufferWords.emplace_back(index, offset, value); - return value; + return constantBufferRead(index, offset); + } + + [[nodiscard]] Shader::TexturePixelFormat ReadTexturePixelFormat(u32 handle) final { + throw exception("ReadTexturePixelFormat not implemented"); } [[nodiscard]] Shader::TextureType ReadTextureType(u32 handle) final { - auto type{getTextureType(handle)}; - textureTypes.emplace_back(handle, type); - return type; + return getTextureType(handle); + } + + [[nodiscard]] u32 ReadViewportTransformState() final { + return viewportTransformEnabled ? 1 : 0; // Only relevant for graphics shaders } [[nodiscard]] u32 TextureBoundBuffer() const final { @@ -156,11 +168,7 @@ namespace skyline::gpu { ShaderManager::ConstantBufferRead constantBufferRead; ShaderManager::GetTextureType getTextureType; - public: - std::vector constantBufferWords; - std::vector textureTypes; - ComputeEnvironment(span pBinary, u32 baseOffset, u32 textureBufferIndex, @@ -187,15 +195,19 @@ namespace skyline::gpu { } [[nodiscard]] u32 ReadCbufValue(u32 index, u32 offset) final { - auto value{constantBufferRead(index, offset)}; - constantBufferWords.emplace_back(index, offset, value); - return value; + return constantBufferRead(index, offset); + } + + [[nodiscard]] Shader::TexturePixelFormat ReadTexturePixelFormat(u32 handle) final { + throw exception("ReadTexturePixelFormat not implemented"); } [[nodiscard]] Shader::TextureType ReadTextureType(u32 handle) final { - auto type{getTextureType(handle)}; - textureTypes.emplace_back(handle, type); - return type; + return getTextureType(handle); + } + + [[nodiscard]] u32 ReadViewportTransformState() final { + return 0; // Only relevant for graphics shaders } [[nodiscard]] u32 TextureBoundBuffer() const final { @@ -240,6 +252,14 @@ namespace skyline::gpu { throw exception("Not implemented"); } + [[nodiscard]] Shader::TexturePixelFormat ReadTexturePixelFormat(u32 handle) final { + throw exception("Not implemented"); + } + + [[nodiscard]] u32 ReadViewportTransformState() final { + throw exception("Not implemented"); + } + [[nodiscard]] u32 TextureBoundBuffer() const final { throw exception("Not implemented"); } @@ -259,14 +279,15 @@ namespace skyline::gpu { void Dump(u64 hash) final {} }; - constexpr ShaderManager::ConstantBufferWord::ConstantBufferWord(u32 index, u32 offset, u32 value) : index(index), offset(offset), value(value) {} - - constexpr ShaderManager::CachedTextureType::CachedTextureType(u32 handle, Shader::TextureType type) : handle(handle), type(type) {} - - Shader::IR::Program ShaderManager::ParseGraphicsShader(const std::array &postVtgShaderAttributeSkipMask, Shader::Stage stage, span binary, u32 baseOffset, u32 textureConstantBufferIndex, const ConstantBufferRead &constantBufferRead, const GetTextureType &getTextureType) { + Shader::IR::Program ShaderManager::ParseGraphicsShader(const std::array &postVtgShaderAttributeSkipMask, + Shader::Stage stage, + span binary, u32 baseOffset, + u32 textureConstantBufferIndex, + bool viewportTransformEnabled, + const ConstantBufferRead &constantBufferRead, const GetTextureType &getTextureType) { std::scoped_lock lock{poolMutex}; - GraphicsEnvironment environment{postVtgShaderAttributeSkipMask, stage, binary, baseOffset, textureConstantBufferIndex, constantBufferRead, getTextureType}; + GraphicsEnvironment environment{postVtgShaderAttributeSkipMask, stage, binary, baseOffset, textureConstantBufferIndex, viewportTransformEnabled, constantBufferRead, getTextureType}; Shader::Maxwell::Flow::CFG cfg{environment, flowBlockPool, Shader::Maxwell::Location{static_cast(baseOffset + sizeof(Shader::ProgramHeader))}}; return Shader::Maxwell::TranslateProgram(instructionPool, blockPool, environment, cfg, hostTranslateInfo); } @@ -278,7 +299,11 @@ namespace skyline::gpu { return Shader::Maxwell::MergeDualVertexPrograms(vertexA, vertexB, env); } - Shader::IR::Program ShaderManager::ParseComputeShader(span binary, u32 baseOffset, u32 textureConstantBufferIndex, u32 localMemorySize, u32 sharedMemorySize, std::array workgroupDimensions, const ConstantBufferRead &constantBufferRead, const GetTextureType &getTextureType) { + Shader::IR::Program ShaderManager::ParseComputeShader(span binary, u32 baseOffset, + u32 textureConstantBufferIndex, + u32 localMemorySize, u32 sharedMemorySize, + std::array workgroupDimensions, + const ConstantBufferRead &constantBufferRead, const GetTextureType &getTextureType) { std::scoped_lock lock{poolMutex}; ComputeEnvironment environment{binary, baseOffset, textureConstantBufferIndex, localMemorySize, sharedMemorySize, workgroupDimensions, constantBufferRead, getTextureType}; diff --git a/app/src/main/cpp/skyline/gpu/shader_manager.h b/app/src/main/cpp/skyline/gpu/shader_manager.h index 00892ee7..a4090e96 100644 --- a/app/src/main/cpp/skyline/gpu/shader_manager.h +++ b/app/src/main/cpp/skyline/gpu/shader_manager.h @@ -31,37 +31,14 @@ namespace skyline::gpu { public: using ConstantBufferRead = std::function; //!< A function which reads a constant buffer at the specified offset and returns the value - - /** - * @brief A single u32 word from a constant buffer with the offset it was read from, utilized to ensure constant buffer state is consistent - */ - struct ConstantBufferWord { - u32 index; //!< The index of the constant buffer - u32 offset; //!< The offset of the constant buffer word - u32 value; //!< The contents of the word - - constexpr ConstantBufferWord(u32 index, u32 offset, u32 value); - - constexpr bool operator==(const ConstantBufferWord &other) const = default; - }; - using GetTextureType = std::function; //!< A function which determines the type of a texture from its handle by checking the corresponding TIC - struct CachedTextureType { - u32 handle; - Shader::TextureType type; - - constexpr CachedTextureType(u32 handle, Shader::TextureType type); - - constexpr bool operator==(const CachedTextureType &other) const = default; - }; - ShaderManager(const DeviceState &state, GPU &gpu); /** * @return A shader program that corresponds to all the supplied state including the current state of the constant buffers */ - Shader::IR::Program ParseGraphicsShader(const std::array &postVtgShaderAttributeSkipMask, Shader::Stage stage, span binary, u32 baseOffset, u32 textureConstantBufferIndex, const ConstantBufferRead &constantBufferRead, const GetTextureType &getTextureType); + Shader::IR::Program ParseGraphicsShader(const std::array &postVtgShaderAttributeSkipMask, Shader::Stage stage, span binary, u32 baseOffset, u32 textureConstantBufferIndex, bool viewportTransformEnabled, const ConstantBufferRead &constantBufferRead, const GetTextureType &getTextureType); /** * @brief Combines the VertexA and VertexB shader programs into a single program diff --git a/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell_3d.cpp b/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell_3d.cpp index 0cdac2e5..aed066f3 100644 --- a/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell_3d.cpp +++ b/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell_3d.cpp @@ -24,7 +24,7 @@ namespace skyline::soc::gm20b::engine::maxwell3d { .depthStencilRegisters = {*registers.depthTestEnable, *registers.depthWriteEnable, *registers.depthFunc, *registers.depthBoundsTestEnable, *registers.stencilTestEnable, *registers.twoSidedStencilTestEnable, *registers.stencilOps, *registers.stencilBack, *registers.alphaTestEnable, *registers.alphaFunc, *registers.alphaRef}, .colorBlendRegisters = {*registers.logicOp, *registers.singleCtWriteControl, *registers.ctWrites, *registers.blendStatePerTargetEnable, *registers.blendPerTargets, *registers.blend}, .transformFeedbackRegisters = {*registers.streamOutputEnable, *registers.streamOutControls, *registers.streamOutLayoutSelect}, - .globalShaderConfigRegisters = {*registers.postVtgShaderAttributeSkipMask, *registers.bindlessTexture, *registers.apiMandatedEarlyZEnable}, + .globalShaderConfigRegisters = {*registers.postVtgShaderAttributeSkipMask, *registers.bindlessTexture, *registers.apiMandatedEarlyZEnable, *registers.viewportScaleOffsetEnable}, .ctSelect = *registers.ctSelect }; } @@ -35,7 +35,7 @@ namespace skyline::soc::gm20b::engine::maxwell3d { .vertexBuffersRegisters = util::MergeInto(*registers.vertexStreams, *registers.vertexStreamLimits), .indexBufferRegisters = {*registers.indexBuffer}, .transformFeedbackBuffersRegisters = util::MergeInto(*registers.streamOutBuffers, *registers.streamOutputEnable), - .viewportsRegisters = util::MergeInto(registers.viewports[0], registers.viewportClips[0], *registers.viewports, *registers.viewportClips, *registers.windowOrigin, *registers.viewportScaleOffsetEnable), + .viewportsRegisters = util::MergeInto(registers.viewports[0], registers.viewportClips[0], *registers.viewports, *registers.viewportClips, *registers.windowOrigin, *registers.viewportScaleOffsetEnable, *registers.surfaceClip), .scissorsRegisters = util::MergeInto(*registers.scissors), .lineWidthRegisters = {*registers.lineWidth, *registers.lineWidthAliased, *registers.aliasedLineWidthEnable}, .depthBiasRegisters = {*registers.depthBias, *registers.depthBiasClamp, *registers.slopeScaleDepthBias},