Skip to content

Commit

Permalink
Merge pull request #17568 from hrydgard/extract-some-changes
Browse files Browse the repository at this point in the history
Extract some minor changes from #17497
  • Loading branch information
hrydgard committed Jun 12, 2023
2 parents 17a723e + 880379c commit 5ae9c9c
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 20 deletions.
16 changes: 13 additions & 3 deletions Common/GPU/OpenGL/GLMemory.h
Expand Up @@ -84,7 +84,7 @@ class GLPushBuffer : public GPUMemoryManager {
const char *Name() const override { return tag_; }; // for sorting

// Utility for users of this class, not used internally.
const uint32_t INVALID_OFFSET = 0xFFFFFFFF;
enum { INVALID_OFFSET = 0xFFFFFFFF };

private:
// Needs context in case of defragment.
Expand Down Expand Up @@ -142,10 +142,20 @@ class GLPushBuffer : public GPUMemoryManager {
return bindOffset;
}

uint8_t *GetPtr(uint32_t offset) {
return writePtr_ + offset;
}

// If you didn't use all of the previous allocation you just made (obviously can't be another one),
// you can return memory to the buffer by specifying the offset up until which you wrote data.
void Rewind(uint32_t offset) {
offset_ = offset;
// Pass in the buffer you got last time. If that buffer has been filled already, no rewind can be safely done.
// (well technically would be possible but not worth the trouble).
void Rewind(GLRBuffer *buffer, uint32_t offset) {
if (buffer == buffers_[buf_].buffer) {
_dbg_assert_(offset != INVALID_OFFSET);
_dbg_assert_(offset <= offset_);
offset_ = offset;
}
}

size_t GetOffset() const { return offset_; }
Expand Down
7 changes: 3 additions & 4 deletions Common/GPU/OpenGL/GLQueueRunner.cpp
Expand Up @@ -1236,10 +1236,9 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last
}
case GLRRenderCommand::DRAW:
{
// TODO: Add fast path for glBindVertexBuffer
GLRInputLayout *layout = c.draw.inputLayout;
GLuint buf = c.draw.vertexBuffer ? c.draw.vertexBuffer->buffer_ : 0;
_dbg_assert_(!c.draw.vertexBuffer || !c.draw.vertexBuffer->Mapped());
GLuint buf = c.draw.vertexBuffer->buffer_;
_dbg_assert_(!c.draw.vertexBuffer->Mapped());
if (buf != curArrayBuffer) {
glBindBuffer(GL_ARRAY_BUFFER, buf);
curArrayBuffer = buf;
Expand All @@ -1254,7 +1253,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last
}
if (c.draw.indexBuffer) {
GLuint buf = c.draw.indexBuffer->buffer_;
_dbg_assert_(!(c.draw.indexBuffer && c.draw.indexBuffer->Mapped()));
_dbg_assert_(!c.draw.indexBuffer->Mapped());
if (buf != curElemArrayBuffer) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
curElemArrayBuffer = buf;
Expand Down
4 changes: 2 additions & 2 deletions Common/GPU/OpenGL/GLRenderManager.h
Expand Up @@ -752,7 +752,7 @@ class GLRenderManager {
}

void Draw(GLRInputLayout *inputLayout, GLRBuffer *vertexBuffer, uint32_t vertexOffset, GLenum mode, int first, int count) {
_dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER);
_dbg_assert_(vertexBuffer && curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER);
GLRRenderData &data = curRenderStep_->commands.push_uninitialized();
data.cmd = GLRRenderCommand::DRAW;
data.draw.inputLayout = inputLayout;
Expand All @@ -767,7 +767,7 @@ class GLRenderManager {

// Would really love to have a basevertex parameter, but impossible in unextended GLES, without glDrawElementsBaseVertex, unfortunately.
void DrawIndexed(GLRInputLayout *inputLayout, GLRBuffer *vertexBuffer, uint32_t vertexOffset, GLRBuffer *indexBuffer, uint32_t indexOffset, GLenum mode, int count, GLenum indexType, int instances = 1) {
_dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER);
_dbg_assert_(vertexBuffer && indexBuffer && curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER);
GLRRenderData &data = curRenderStep_->commands.push_uninitialized();
data.cmd = GLRRenderCommand::DRAW;
data.draw.inputLayout = inputLayout;
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/DrawEngineCommon.h
Expand Up @@ -130,7 +130,7 @@ class DrawEngineCommon {
virtual void ClearTrackedVertexArrays() {}

protected:
virtual bool UpdateUseHWTessellation(bool enabled) { return enabled; }
virtual bool UpdateUseHWTessellation(bool enabled) const { return enabled; }

int ComputeNumVertsToDecode() const;
void DecodeVerts(u8 *dest);
Expand Down
4 changes: 2 additions & 2 deletions GPU/Directx9/DrawEngineDX9.cpp
Expand Up @@ -161,7 +161,7 @@ static void VertexAttribSetup(D3DVERTEXELEMENT9 * VertexElement, u8 fmt, u8 offs
VertexElement->UsageIndex = usage_index;
}

IDirect3DVertexDeclaration9 *DrawEngineDX9::SetupDecFmtForDraw(VSShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt) {
IDirect3DVertexDeclaration9 *DrawEngineDX9::SetupDecFmtForDraw(const DecVtxFormat &decFmt, u32 pspFmt) {
IDirect3DVertexDeclaration9 *vertexDeclCached = vertexDeclMap_.Get(pspFmt);

if (vertexDeclCached) {
Expand Down Expand Up @@ -515,7 +515,7 @@ void DrawEngineDX9::DoFlush() {
ApplyDrawStateLate();

VSShader *vshader = shaderManager_->ApplyShader(true, useHWTessellation_, dec_, decOptions_.expandAllWeightsToFloat, decOptions_.applySkinInDecode, pipelineState_);
IDirect3DVertexDeclaration9 *pHardwareVertexDecl = SetupDecFmtForDraw(vshader, dec_->GetDecVtxFmt(), dec_->VertexType());
IDirect3DVertexDeclaration9 *pHardwareVertexDecl = SetupDecFmtForDraw(dec_->GetDecVtxFmt(), dec_->VertexType());

if (pHardwareVertexDecl) {
device_->SetVertexDeclaration(pHardwareVertexDecl);
Expand Down
4 changes: 2 additions & 2 deletions GPU/Directx9/DrawEngineDX9.h
Expand Up @@ -147,7 +147,7 @@ class DrawEngineDX9 : public DrawEngineCommon {

protected:
// Not currently supported.
bool UpdateUseHWTessellation(bool enable) override { return false; }
bool UpdateUseHWTessellation(bool enable) const override { return false; }
void DecimateTrackedVertexArrays();

private:
Expand All @@ -157,7 +157,7 @@ class DrawEngineDX9 : public DrawEngineCommon {
void ApplyDrawState(int prim);
void ApplyDrawStateLate();

IDirect3DVertexDeclaration9 *SetupDecFmtForDraw(VSShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt);
IDirect3DVertexDeclaration9 *SetupDecFmtForDraw(const DecVtxFormat &decFmt, u32 pspFmt);

void MarkUnreliable(VertexArrayInfoDX9 *vai);

Expand Down
6 changes: 3 additions & 3 deletions GPU/GLES/DrawEngineGLES.cpp
Expand Up @@ -204,7 +204,7 @@ static inline void VertexAttribSetup(int attrib, int fmt, int stride, int offset
}

// TODO: Use VBO and get rid of the vertexData pointers - with that, we will supply only offsets
GLRInputLayout *DrawEngineGLES::SetupDecFmtForDraw(LinkedShader *program, const DecVtxFormat &decFmt) {
GLRInputLayout *DrawEngineGLES::SetupDecFmtForDraw(const DecVtxFormat &decFmt) {
uint32_t key = decFmt.id;
GLRInputLayout *inputLayout = inputLayoutMap_.Get(key);
if (inputLayout) {
Expand Down Expand Up @@ -325,7 +325,7 @@ void DrawEngineGLES::DoFlush() {
ApplyDrawStateLate(false, 0);

LinkedShader *program = shaderManager_->ApplyFragmentShader(vsid, vshader, pipelineState_, framebufferManager_->UseBufferedRendering());
GLRInputLayout *inputLayout = SetupDecFmtForDraw(program, dec_->GetDecVtxFmt());
GLRInputLayout *inputLayout = SetupDecFmtForDraw(dec_->GetDecVtxFmt());
if (useElements) {
render_->DrawIndexed(inputLayout,
vertexBuffer, vertexBufferOffset,
Expand Down Expand Up @@ -502,7 +502,7 @@ bool DrawEngineGLES::SupportsHWTessellation() const {
return hasTexelFetch && gstate_c.UseAll(GPU_USE_VERTEX_TEXTURE_FETCH | GPU_USE_TEXTURE_FLOAT | GPU_USE_INSTANCE_RENDERING);
}

bool DrawEngineGLES::UpdateUseHWTessellation(bool enable) {
bool DrawEngineGLES::UpdateUseHWTessellation(bool enable) const {
return enable && SupportsHWTessellation();
}

Expand Down
4 changes: 2 additions & 2 deletions GPU/GLES/DrawEngineGLES.h
Expand Up @@ -108,7 +108,7 @@ class DrawEngineGLES : public DrawEngineCommon {
bool SupportsHWTessellation() const;

protected:
bool UpdateUseHWTessellation(bool enable) override;
bool UpdateUseHWTessellation(bool enable) const override;

private:
void Invalidate(InvalidationCallbackFlags flags);
Expand All @@ -120,7 +120,7 @@ class DrawEngineGLES : public DrawEngineCommon {
void ApplyDrawState(int prim);
void ApplyDrawStateLate(bool setStencil, int stencilValue);

GLRInputLayout *SetupDecFmtForDraw(LinkedShader *program, const DecVtxFormat &decFmt);
GLRInputLayout *SetupDecFmtForDraw(const DecVtxFormat &decFmt);

struct FrameData {
GLPushBuffer *pushVertex;
Expand Down
2 changes: 1 addition & 1 deletion GPU/Software/TransformUnit.h
Expand Up @@ -196,5 +196,5 @@ class SoftwareDrawEngine : public DrawEngineCommon {
#endif

protected:
bool UpdateUseHWTessellation(bool enable) override { return false; }
bool UpdateUseHWTessellation(bool enable) const override { return false; }
};

0 comments on commit 5ae9c9c

Please sign in to comment.