mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-12-01 21:44:17 +01:00
implement transform feedback
This commit is contained in:
parent
e0791c3bf4
commit
5c246d55bd
@ -9,6 +9,7 @@
|
||||
#include "Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h"
|
||||
#include "Cafe/OS/libs/gx2/GX2.h" // todo - remove dependency
|
||||
#include "Cafe/GraphicPack/GraphicPack2.h"
|
||||
#include "HW/Latte/Renderer/Renderer.h"
|
||||
#include "util/helpers/StringParser.h"
|
||||
#include "config/ActiveSettings.h"
|
||||
#include "Cafe/GameProfile/GameProfile.h"
|
||||
@ -688,9 +689,9 @@ void LatteShader_GetDecompilerOptions(LatteDecompilerOptions& options, LatteCons
|
||||
{
|
||||
options.usesGeometryShader = geometryShaderEnabled;
|
||||
options.spirvInstrinsics.hasRoundingModeRTEFloat32 = false;
|
||||
options.useTFViaSSBO = g_renderer->UseTFViaSSBO();
|
||||
if (g_renderer->GetType() == RendererAPI::Vulkan)
|
||||
{
|
||||
options.useTFViaSSBO = VulkanRenderer::GetInstance()->UseTFViaSSBO();
|
||||
options.spirvInstrinsics.hasRoundingModeRTEFloat32 = VulkanRenderer::GetInstance()->HasSPRIVRoundingModeRTE32();
|
||||
}
|
||||
options.strictMul = g_current_game_profile->GetAccurateShaderMul() != AccurateShaderMulOption::False;
|
||||
|
@ -2752,9 +2752,9 @@ static void _emitTEXGetGradientsHV(LatteDecompilerShaderContext* shaderContext,
|
||||
|
||||
const char* funcName;
|
||||
if (texInstruction->opcode == GPU7_TEX_INST_GET_GRADIENTS_H)
|
||||
funcName = "dFdx";
|
||||
funcName = "dfdx";
|
||||
else
|
||||
funcName = "dFdy";
|
||||
funcName = "dfdy";
|
||||
|
||||
src->add(" = ");
|
||||
|
||||
@ -3273,15 +3273,8 @@ static void _emitCFRingWriteCode(LatteDecompilerShaderContext* shaderContext, La
|
||||
if ((cfInstruction->memWriteCompMask&(1 << i)) == 0)
|
||||
continue;
|
||||
|
||||
if (shaderContext->options->useTFViaSSBO)
|
||||
{
|
||||
uint32 u32Offset = streamWrite->exportArrayBase + i;
|
||||
src->addFmt("sb_buffer[sbBase{} + {}]", streamWrite->bufferIndex, u32Offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
src->addFmt("sb{}[{}]", streamWrite->bufferIndex, streamWrite->exportArrayBase + i);
|
||||
}
|
||||
src->addFmt("sb[sbBase{} + {}]", streamWrite->bufferIndex, u32Offset);
|
||||
|
||||
src->add(" = ");
|
||||
|
||||
@ -3393,15 +3386,8 @@ static void _emitStreamWriteCode(LatteDecompilerShaderContext* shaderContext, La
|
||||
if ((cfInstruction->memWriteCompMask&(1 << i)) == 0)
|
||||
continue;
|
||||
|
||||
if (shaderContext->options->useTFViaSSBO)
|
||||
{
|
||||
uint32 u32Offset = cfInstruction->exportArrayBase + i;
|
||||
src->addFmt("sb_buffer[sbBase{} + {}]", streamoutBufferIndex, u32Offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
src->addFmt("sb{}[{}]", streamoutBufferIndex, cfInstruction->exportArrayBase + i);
|
||||
}
|
||||
src->addFmt("sb[sbBase{} + {}]", streamoutBufferIndex, u32Offset);
|
||||
|
||||
src->add(" = ");
|
||||
|
||||
@ -3595,8 +3581,6 @@ void LatteDecompiler_emitClauseCodeMSL(LatteDecompilerShaderContext* shaderConte
|
||||
// emit vertex
|
||||
src->add("EmitVertex();" _CRLF);
|
||||
// increment transform feedback pointer
|
||||
if (shaderContext->analyzer.useSSBOForStreamout)
|
||||
{
|
||||
for (sint32 i = 0; i < LATTE_NUM_STREAMOUT_BUFFER; i++)
|
||||
{
|
||||
if (!shaderContext->output->streamoutBufferWriteMask[i])
|
||||
@ -3604,7 +3588,6 @@ void LatteDecompiler_emitClauseCodeMSL(LatteDecompilerShaderContext* shaderConte
|
||||
cemu_assert_debug((shaderContext->output->streamoutBufferStride[i] & 3) == 0);
|
||||
src->addFmt("sbBase{} += {};" _CRLF, i, shaderContext->output->streamoutBufferStride[i] / 4);
|
||||
}
|
||||
}
|
||||
|
||||
if( shaderContext->analyzer.modifiesPixelActiveState )
|
||||
src->add("}" _CRLF);
|
||||
@ -3970,7 +3953,7 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
|
||||
src->addFmt("float cubeMapArrayIndex{} = 0.0;" _CRLF, i);
|
||||
}
|
||||
// init base offset for streamout buffer writes
|
||||
if (shaderContext->analyzer.useSSBOForStreamout && (shader->shaderType == LatteConst::ShaderType::Vertex || shader->shaderType == LatteConst::ShaderType::Geometry))
|
||||
if (shader->shaderType == LatteConst::ShaderType::Vertex || shader->shaderType == LatteConst::ShaderType::Geometry)
|
||||
{
|
||||
for (sint32 i = 0; i < LATTE_NUM_STREAMOUT_BUFFER; i++)
|
||||
{
|
||||
|
@ -94,8 +94,7 @@ namespace LatteDecompiler
|
||||
uniformCurrentOffset += 8;
|
||||
}
|
||||
// define verticesPerInstance + streamoutBufferBaseX
|
||||
if (decompilerContext->analyzer.useSSBOForStreamout &&
|
||||
(shader->shaderType == LatteConst::ShaderType::Vertex && decompilerContext->options->usesGeometryShader == false) ||
|
||||
if ((shader->shaderType == LatteConst::ShaderType::Vertex && decompilerContext->options->usesGeometryShader == false) ||
|
||||
(shader->shaderType == LatteConst::ShaderType::Geometry))
|
||||
{
|
||||
src->add("int verticesPerInstance;" _CRLF);
|
||||
@ -251,8 +250,6 @@ namespace LatteDecompiler
|
||||
{
|
||||
_emitAttributes(decompilerContext);
|
||||
_emitVSOutputs(decompilerContext);
|
||||
|
||||
// TODO: transform feedback
|
||||
}
|
||||
else if (decompilerContext->shaderType == LatteConst::ShaderType::Pixel)
|
||||
{
|
||||
@ -379,6 +376,13 @@ namespace LatteDecompiler
|
||||
case LatteConst::ShaderType::Vertex:
|
||||
src->add(", uint vid [[vertex_id]]");
|
||||
src->add(", uint iid [[instance_id]]");
|
||||
|
||||
// streamout buffer (transform feedback)
|
||||
if (decompilerContext->analyzer.hasStreamoutEnable && decompilerContext->analyzer.hasStreamoutWrite)
|
||||
{
|
||||
src->addFmt(", device int* sb [[buffer({})]]" _CRLF, decompilerContext->output->resourceMappingVK.getTFStorageBufferBindingPoint());
|
||||
}
|
||||
|
||||
break;
|
||||
case LatteConst::ShaderType::Pixel:
|
||||
src->add(", bool frontFacing [[front_facing]]");
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "Cemu/Logging/CemuDebugLogging.h"
|
||||
#include "HW/Latte/Core/Latte.h"
|
||||
#include "HW/Latte/ISA/LatteReg.h"
|
||||
#include "Metal/MTLResource.hpp"
|
||||
#include "Metal/MTLTypes.hpp"
|
||||
#include "gui/guiWrapper.h"
|
||||
|
||||
@ -39,6 +40,9 @@ MetalRenderer::MetalRenderer()
|
||||
// Texture readback
|
||||
m_readbackBuffer = m_device->newBuffer(TEXTURE_READBACK_SIZE, MTL::StorageModeShared);
|
||||
|
||||
// Transform feedback
|
||||
m_xfbRingBuffer = m_device->newBuffer(LatteStreamout_GetRingBufferSize(), MTL::StorageModeShared);
|
||||
|
||||
// Initialize state
|
||||
for (uint32 i = 0; i < (uint32)LatteConst::ShaderType::TotalCount; i++)
|
||||
{
|
||||
@ -1185,7 +1189,21 @@ void MetalRenderer::BindStageResources(MTL::RenderCommandEncoder* renderCommandE
|
||||
// Storage buffer
|
||||
if (shader->resourceMapping.tfStorageBindingPoint >= 0)
|
||||
{
|
||||
debug_printf("storage buffer not implemented, index: %i\n", shader->resourceMapping.tfStorageBindingPoint);
|
||||
switch (shader->shaderType)
|
||||
{
|
||||
case LatteConst::ShaderType::Vertex:
|
||||
{
|
||||
renderCommandEncoder->setVertexBuffer(m_xfbRingBuffer, 0, shader->resourceMapping.tfStorageBindingPoint);
|
||||
break;
|
||||
}
|
||||
case LatteConst::ShaderType::Pixel:
|
||||
{
|
||||
renderCommandEncoder->setFragmentBuffer(m_xfbRingBuffer, 0, shader->resourceMapping.tfStorageBindingPoint);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,6 +147,7 @@ public:
|
||||
cemuLog_log(LogType::MetalLogging, "Imgui is not yet supported on Metal");
|
||||
};
|
||||
|
||||
bool UseTFViaSSBO() const override { return true; }
|
||||
void AppendOverlayDebugInfo() override;
|
||||
|
||||
// rendertarget
|
||||
@ -265,6 +266,9 @@ private:
|
||||
MTL::Buffer* m_readbackBuffer;
|
||||
uint32 m_readbackBufferWriteOffset = 0;
|
||||
|
||||
// Transform feedback
|
||||
MTL::Buffer* m_xfbRingBuffer;
|
||||
|
||||
// Active objects
|
||||
MTL::CommandBuffer* m_commandBuffer = nullptr;
|
||||
MetalEncoderType m_encoderType = MetalEncoderType::None;
|
||||
|
@ -85,6 +85,7 @@ public:
|
||||
virtual void DeleteFontTextures() = 0;
|
||||
|
||||
GfxVendor GetVendor() const { return m_vendor; }
|
||||
virtual bool UseTFViaSSBO() const { return false; }
|
||||
virtual void AppendOverlayDebugInfo() = 0;
|
||||
|
||||
// rendertarget
|
||||
|
@ -278,7 +278,6 @@ public:
|
||||
void* texture_acquireTextureUploadBuffer(uint32 size) override;
|
||||
void texture_releaseTextureUploadBuffer(uint8* mem) override;
|
||||
|
||||
|
||||
TextureDecoder* texture_chooseDecodedFormat(Latte::E_GX2SURFFMT format, bool isDepth, Latte::E_DIM dim, uint32 width, uint32 height) override;
|
||||
|
||||
void texture_clearSlice(LatteTexture* hostTexture, sint32 sliceIndex, sint32 mipIndex) override;
|
||||
@ -512,6 +511,8 @@ private:
|
||||
void DeleteFontTextures() override;
|
||||
bool BeginFrame(bool mainWindow) override;
|
||||
|
||||
bool UseTFViaSSBO() const override { return m_featureControl.mode.useTFEmulationViaSSBO; }
|
||||
|
||||
// drawcall emulation
|
||||
PipelineInfo* draw_createGraphicsPipeline(uint32 indexCount);
|
||||
PipelineInfo* draw_getOrCreateGraphicsPipeline(uint32 indexCount);
|
||||
@ -921,7 +922,6 @@ private:
|
||||
|
||||
public:
|
||||
bool GetDisableMultithreadedCompilation() const { return m_featureControl.disableMultithreadedCompilation; }
|
||||
bool UseTFViaSSBO() const { return m_featureControl.mode.useTFEmulationViaSSBO; }
|
||||
bool HasSPRIVRoundingModeRTE32() const { return m_featureControl.shaderFloatControls.shaderRoundingModeRTEFloat32; }
|
||||
bool IsDebugUtilsEnabled() const { return m_featureControl.debugMarkersSupported && m_featureControl.instanceExtensions.debug_utils; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user