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

Base melon ds20241127v2 #75

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
77 changes: 74 additions & 3 deletions src/GPU3D_Compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ bool ComputeRenderer::CompileShader(GLuint& shader, const std::string& source, c
std::string shaderName;
std::string shaderSource;
shaderSource += "#version 430 core\n";
shaderSource += "#define TileSize ";
shaderSource += std::to_string(TileSize);
shaderSource += "\n";
for (const char* define : defines)
{
shaderSource += "#define ";
Expand Down Expand Up @@ -299,6 +302,24 @@ void ComputeRenderer::SetRenderSettings(int scale, bool highResolutionCoordinate
{
CurGLCompositor.SetScaleFactor(scale);

// Adjust tile size based on scale
const int baseTileSize = 8; // Define the base tile size
if (scale >= 12) {
TileSize = baseTileSize * 4; // Use 32x32 tiles (suitable for high scale)
}
else if (scale >= 6) {
TileSize = baseTileSize * 2; // Use 16x16 tiles (suitable for medium scale)
}
else {
TileSize = baseTileSize; // Use 8x8 tiles (suitable for low scale)
}

CoarseTileW = CoarseTileCountX * TileSize;
CoarseTileH = CoarseTileCountY * TileSize;

TilesPerLine = ScreenWidth / TileSize;
TileLines = ScreenHeight / TileSize;

if (ScaleFactor != -1)
{
DeleteShaders();
Expand Down Expand Up @@ -947,7 +968,34 @@ void ComputeRenderer::RenderFrame(GPU& gpu)
// sort shader work
glUseProgram(ShaderSortWork);
glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, BinResultMemory);
glDispatchComputeIndirect(offsetof(BinResultHeader, SortWorkWorkCount));

uint32_t sortWorkCount[4];
glGetBufferSubData(GL_DISPATCH_INDIRECT_BUFFER,
offsetof(BinResultHeader, SortWorkWorkCount),
sizeof(sortWorkCount),
sortWorkCount);

const uint32_t maxWorkGroups = 65535;
uint32_t remaining = sortWorkCount[0];
uint32_t offset = 0;

while (remaining > 0) {
uint32_t count = std::min(remaining, maxWorkGroups);
sortWorkCount[0] = count;

glBufferSubData(GL_DISPATCH_INDIRECT_BUFFER,
offsetof(BinResultHeader, SortWorkWorkCount),
sizeof(sortWorkCount),
sortWorkCount);

glDispatchComputeIndirect(offsetof(BinResultHeader, SortWorkWorkCount));

remaining -= count;
offset += count * 32;
}



glMemoryBarrier(GL_SHADER_STORAGE_BUFFER);

glActiveTexture(GL_TEXTURE0);
Expand Down Expand Up @@ -1012,8 +1060,31 @@ void ComputeRenderer::RenderFrame(GPU& gpu)

glUniform1ui(UniformIdxCurVariant, i);
glUniform2f(UniformIdxTextureSize, 1.f / variants[i].Width, 1.f / variants[i].Height);
glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, BinResultMemory);
glDispatchComputeIndirect(offsetof(BinResultHeader, VariantWorkCount) + i*4*4);


uint32_t variantWorkCount[4];
glGetBufferSubData(GL_DISPATCH_INDIRECT_BUFFER,
offsetof(BinResultHeader, VariantWorkCount) + i * 4 * 4,
sizeof(variantWorkCount),
variantWorkCount);

remaining = variantWorkCount[0];
offset = 0;

while (remaining > 0) {
uint32_t count = std::min(remaining, maxWorkGroups);
variantWorkCount[0] = count;

glBufferSubData(GL_DISPATCH_INDIRECT_BUFFER,
offsetof(BinResultHeader, VariantWorkCount) + i * 4 * 4,
sizeof(variantWorkCount),
variantWorkCount);

glDispatchComputeIndirect(offsetof(BinResultHeader, VariantWorkCount) + i * 4 * 4);

remaining -= count;
offset += count * 32;
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/GPU3D_Compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ class ComputeRenderer : public Renderer3D
float TextureLayer;
};

static constexpr int TileSize = 8;
int TileSize;
static constexpr int CoarseTileCountX = 8;
static constexpr int CoarseTileCountY = 4;
static constexpr int CoarseTileW = CoarseTileCountX * TileSize;
static constexpr int CoarseTileH = CoarseTileCountY * TileSize;
int CoarseTileW;
int CoarseTileH;

static constexpr int BinStride = 2048/32;
static constexpr int CoarseBinStride = BinStride/32;
Expand Down
1 change: 0 additions & 1 deletion src/GPU3D_Compute_shaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ const uint ResultAttrStart = ResultDepthStart+ScreenWidth*ScreenHeight*2;

const char* Common = R"(

#define TileSize 8
const int CoarseTileCountX = 8;
const int CoarseTileCountY = 4;
const int CoarseTileW = (CoarseTileCountX * TileSize);
Expand Down
9 changes: 2 additions & 7 deletions src/frontend/qt_sdl/EmuThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,8 +1035,6 @@ void EmuThread::run()
hasInitialized = true;

// Hide cursor
//QGuiApplication::setOverrideCursor(Qt::BlankCursor);
// emuInstance->getMainWindow()->panel->setCursor(Qt::BlankCursor);
showCursor(false);


Expand Down Expand Up @@ -1106,10 +1104,9 @@ void EmuThread::run()
if (isInGame) {
// inGame

/* doing this in Screen.cpp
/*
* doing this in Screen.cpp
if(!wasLastFrameFocused){
// QGuiApplication::setOverrideCursor(Qt::BlankCursor);
// emuInstance->getMainWindow()->panel->setCursor(Qt::BlankCursor);
showCursor(false);
}
*/
Expand Down Expand Up @@ -1576,8 +1573,6 @@ void EmuThread::run()

if(hasInitialized){
hasInitialized = false;
// QGuiApplication::setOverrideCursor(Qt::ArrowCursor);
// emuInstance->getMainWindow()->panel->setCursor(Qt::ArrowCursor);
showCursor(true);
}

Expand Down
Loading