Navigation Menu

Skip to content

Commit

Permalink
Drive-by texture slot management cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Aug 24, 2022
1 parent 58de891 commit eb2f12e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
11 changes: 7 additions & 4 deletions Common/GPU/OpenGL/GLQueueRunner.cpp
Expand Up @@ -758,9 +758,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last
}

GLRProgram *curProgram = nullptr;
int activeSlot = 0;
if (first)
glActiveTexture(GL_TEXTURE0 + activeSlot);
int activeSlot = -1;

// State filtering tracking.
int attrMask = 0;
Expand Down Expand Up @@ -1202,8 +1200,13 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last
}
case GLRRenderCommand::TEXTURE_SUBIMAGE:
{
GLRTexture *tex = c.texture_subimage.texture;
GLint slot = c.texture_subimage.slot;
if (slot != activeSlot) {
glActiveTexture(GL_TEXTURE0 + slot);
activeSlot = slot;
}
// TODO: Need bind?
GLRTexture *tex = c.texture_subimage.texture;
if (!c.texture_subimage.data)
Crash();
_assert_(tex->target == GL_TEXTURE_2D);
Expand Down
11 changes: 6 additions & 5 deletions Common/GPU/OpenGL/GLQueueRunner.h
Expand Up @@ -148,11 +148,12 @@ struct GLRRenderData {
struct {
GLRTexture *texture;
Draw::DataFormat format;
int level;
int x;
int y;
int width;
int height;
uint8_t slot;
uint8_t level;
uint16_t width;
uint16_t height;
uint16_t x;
uint16_t y;
GLRAllocType allocType;
uint8_t *data; // owned, delete[]-d
} texture_subimage;
Expand Down
3 changes: 2 additions & 1 deletion Common/GPU/OpenGL/GLRenderManager.h
Expand Up @@ -555,7 +555,7 @@ class GLRenderManager {
initSteps_.push_back(step);
}

void TextureSubImage(GLRTexture *texture, int level, int x, int y, int width, int height, Draw::DataFormat format, uint8_t *data, GLRAllocType allocType = GLRAllocType::NEW) {
void TextureSubImage(int slot, GLRTexture *texture, int level, int x, int y, int width, int height, Draw::DataFormat format, uint8_t *data, GLRAllocType allocType = GLRAllocType::NEW) {
_dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER);
GLRRenderData _data{ GLRRenderCommand::TEXTURE_SUBIMAGE };
_data.texture_subimage.texture = texture;
Expand All @@ -567,6 +567,7 @@ class GLRenderManager {
_data.texture_subimage.width = width;
_data.texture_subimage.height = height;
_data.texture_subimage.allocType = allocType;
_data.texture_subimage.slot = slot;
curRenderStep_->commands.push_back(_data);
}

Expand Down
10 changes: 5 additions & 5 deletions GPU/GLES/DrawEngineGLES.cpp
Expand Up @@ -504,13 +504,13 @@ void TessellationDataTransferGLES::SendDataToShader(const SimpleVertex *const *p
}
renderManager_->BindTexture(TEX_SLOT_SPLINE_POINTS, data_tex[0]);
// Position
renderManager_->TextureSubImage(data_tex[0], 0, 0, 0, size_u, size_v, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)pos, GLRAllocType::NEW);
renderManager_->TextureSubImage(TEX_SLOT_SPLINE_POINTS, data_tex[0], 0, 0, 0, size_u, size_v, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)pos, GLRAllocType::NEW);
// Texcoord
if (hasTexCoord)
renderManager_->TextureSubImage(data_tex[0], 0, size_u, 0, size_u, size_v, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)tex, GLRAllocType::NEW);
renderManager_->TextureSubImage(TEX_SLOT_SPLINE_POINTS, data_tex[0], 0, size_u, 0, size_u, size_v, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)tex, GLRAllocType::NEW);
// Color
if (hasColor)
renderManager_->TextureSubImage(data_tex[0], 0, size_u * 2, 0, size_u, size_v, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)col, GLRAllocType::NEW);
renderManager_->TextureSubImage(TEX_SLOT_SPLINE_POINTS, data_tex[0], 0, size_u * 2, 0, size_u, size_v, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)col, GLRAllocType::NEW);

// Weight U
if (prevSizeWU < weights.size_u) {
Expand All @@ -521,7 +521,7 @@ void TessellationDataTransferGLES::SendDataToShader(const SimpleVertex *const *p
renderManager_->FinalizeTexture(data_tex[1], 0, false);
}
renderManager_->BindTexture(TEX_SLOT_SPLINE_WEIGHTS_U, data_tex[1]);
renderManager_->TextureSubImage(data_tex[1], 0, 0, 0, weights.size_u * 2, 1, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)weights.u, GLRAllocType::NONE);
renderManager_->TextureSubImage(TEX_SLOT_SPLINE_WEIGHTS_U, data_tex[1], 0, 0, 0, weights.size_u * 2, 1, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)weights.u, GLRAllocType::NONE);

// Weight V
if (prevSizeWV < weights.size_v) {
Expand All @@ -532,7 +532,7 @@ void TessellationDataTransferGLES::SendDataToShader(const SimpleVertex *const *p
renderManager_->FinalizeTexture(data_tex[2], 0, false);
}
renderManager_->BindTexture(TEX_SLOT_SPLINE_WEIGHTS_V, data_tex[2]);
renderManager_->TextureSubImage(data_tex[2], 0, 0, 0, weights.size_v * 2, 1, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)weights.v, GLRAllocType::NONE);
renderManager_->TextureSubImage(TEX_SLOT_SPLINE_WEIGHTS_V, data_tex[2], 0, 0, 0, weights.size_v * 2, 1, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)weights.v, GLRAllocType::NONE);
}

void TessellationDataTransferGLES::EndFrame() {
Expand Down

0 comments on commit eb2f12e

Please sign in to comment.