Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
IonAgorria committed Oct 7, 2024
1 parent 03b7393 commit 43caa48
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 44 deletions.
6 changes: 0 additions & 6 deletions Source/Render/D3D/D3DRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,6 @@ const uint32_t D3D_LOCK_FLAGS_STATIC = D3DLOCK_NOSYSLOCK | D3DLOCK_NO_DIRTY_UPDA
const uint32_t D3D_LOCK_FLAGS_DYNAMIC = D3D_LOCK_FLAGS_STATIC | D3DLOCK_DISCARD;

void cD3DRender::UpdateD3DVertexBuffer(VertexBuffer* vb, size_t len) {
xassert(!vb->burned);
vb->burned = true;
xassert(len <= vb->data_len);
if (!vb->d3d) {
MTG();
Expand Down Expand Up @@ -1284,8 +1282,6 @@ void cD3DRender::UpdateD3DVertexBuffer(VertexBuffer* vb, size_t len) {
}

void cD3DRender::UpdateD3DIndexBuffer(IndexBuffer* ib, size_t len) {
xassert(!ib->burned);
ib->burned = true;
xassert(len <= ib->data_len);
if (!ib->d3d) {
MTG();
Expand Down Expand Up @@ -1444,8 +1440,6 @@ void cD3DRender::SubmitBuffers(ePrimitiveType primitive, VertexBuffer* vb, size_
xassert(0);
RDCALL(gb_RenderDevice3D->lpD3DDevice->DrawPrimitive(d3dType, offset, vertices));
}
if (vb->dynamic) vb->burned = false;
if (ib->dynamic) ib->burned = false;
}

void cD3DRender::SetGlobalFog(const sColor4f &color,const Vect2f &v)
Expand Down
1 change: 0 additions & 1 deletion Source/Render/inc/MemoryResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class MemoryResource {
size_t data_len = 0;
bool dirty = true;
bool locked = false;
bool burned = false;

explicit MemoryResource(size_t _data_len) {
AllocData(_data_len);
Expand Down
19 changes: 6 additions & 13 deletions Source/Render/sokol/SokolRenderState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,14 @@ void cSokolRender::PrepareSokolBuffer(SokolBuffer*& buffer_ptr, MemoryResource*
}
xassert(buffer_ptr == nullptr);
xassert(resource->data);
xassert(!resource->burned);
desc.data = {resource->data, len};
resource->burned = true;
resource->dirty = false;

buffer = new SokolResourceBuffer(
SokolResourceKeyNone,
sg_make_buffer(&desc)
);
buffer->burned = true;
}
xassert(buffer != nullptr);

Expand Down Expand Up @@ -673,18 +672,12 @@ void cSokolRender::SetActiveDrawBuffer(DrawBuffer* db) {
activeCommand.base_elements = 0;
activeCommand.vertices = 0;
activeCommand.indices = 0;
//Those that are dynamic should have their buffer released and unburned since we wil recreate later
if (db->vb.dynamic && db->vb.burned) {
db->vb.burned = false;
if (db->vb.sg) {
db->vb.sg->release_buffer();
}
//Those that are dynamic should have their buffer released since we wil recreate later
if (db->vb.dynamic && db->vb.sg) {
db->vb.sg->release_buffer();
}
if (db->ib.dynamic && db->ib.burned) {
db->ib.burned = false;
if (db->ib.sg) {
db->ib.sg->release_buffer();
}
if (db->ib.dynamic && db->ib.sg) {
db->ib.sg->release_buffer();
}
}

Expand Down
3 changes: 0 additions & 3 deletions Source/Render/sokol/SokolRenderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ void* cSokolRender::LockTexture(cTexture* Texture, int& Pitch) {
}
SokolTexture2D* tex = frm->sg;
xassert(!tex->locked);
xassert(!tex->burned);
xassert(tex->data);
Pitch = static_cast<int>(Texture->GetWidth() * sokol_pixelformat_bytesize(tex->pixel_format));
if (!tex->data) {
Expand All @@ -159,7 +158,6 @@ void* cSokolRender::LockTextureRect(cTexture* Texture, int& Pitch, Vect2i pos, V
}
SokolTexture2D* tex = frm->sg;
xassert(!tex->locked);
xassert(!tex->burned);
xassert(tex->data);
size_t fmt_size = sokol_pixelformat_bytesize(tex->pixel_format);
Pitch = static_cast<int>(Texture->GetWidth() * fmt_size);
Expand All @@ -185,7 +183,6 @@ void cSokolRender::UnlockTexture(cTexture* Texture) {
}
SokolTexture2D* tex = frm->sg;
xassert(tex->locked);
xassert(!tex->burned);
xassert(tex->data);
if (!tex->data) {
return;
Expand Down
31 changes: 17 additions & 14 deletions Source/Render/sokol/SokolResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ void SokolBuffer::release_buffer() {
}

void SokolBuffer::update(MemoryResource* resource, size_t len) const {
xassert(!resource->burned);
xassert(!resource->locked);
if (!resource->dirty) return;
xassert(resource->data);
Expand All @@ -73,13 +72,15 @@ void SokolBuffer::update(MemoryResource* resource, size_t len) const {
xassert(len <= resource->data_len);
if (len == 0) return;
if (len > resource->data_len) len = resource->data_len;

resource->burned = true;
resource->dirty = false;
if (!buffer) {
xassert(0);
return;
}
xassert(!buffer->burned);
buffer->burned = true;

resource->dirty = false;

xassert(buffer->res.id != SG_INVALID_ID);
sg_range range = {resource->data, len};
sg_update_buffer(buffer->res, &range);
Expand All @@ -106,12 +107,12 @@ void SokolTexture2D::FreeImages() {
return;
}
//Cleanup subimages
for (int ci = 0; ci < SG_CUBEFACE_NUM; ++ci) {
for (int ci = 0; ci < SG_CUBEFACE_NUM; ++ci) {
for (int i = 0; i < SG_MAX_MIPMAPS; ++i) {
sg_range& range = desc->data.subimage[ci][i];
if (!range.ptr) {
if (!range.ptr) {
break;
}
}
const uint8_t* buf = reinterpret_cast<const uint8_t*>(range.ptr);
delete[] buf;
range.ptr = nullptr;
Expand All @@ -122,16 +123,18 @@ void SokolTexture2D::FreeImages() {
void SokolTexture2D::update() {
xassert(!locked);
if (!dirty) return;
dirty = false;
if (!data) return;

if (!image) {
xassert(0);
return;
}
if (data) {
xassert(image->res.id != SG_INVALID_ID);
sg_image_data imageData = {};
imageData.subimage[0][0] = {data, data_len};
sg_update_image(image->res, &imageData);
}
xassert(!image->burned);
image->burned = true;
dirty = false;

xassert(image->res.id != SG_INVALID_ID);
sg_image_data imageData = {};
imageData.subimage[0][0] = {data, data_len};
sg_update_image(image->res, &imageData);
}
1 change: 1 addition & 0 deletions Source/Render/sokol/SokolResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SokolResource {
}
}
public:
bool burned = false;
SokolResourceKey key = SokolResourceKeyNone;
T res;

Expand Down
7 changes: 0 additions & 7 deletions Source/Render/src/RenderDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ void MemoryResource::FreeData() {
free(data);
data = nullptr;
}
burned = false;
data_len = 0;
}

Expand Down Expand Up @@ -168,7 +167,6 @@ void cInterfaceRenderDevice::CreateVertexBuffer(VertexBuffer& vb, uint32_t Numbe

vb.dirty = true;
vb.locked = false;
vb.burned = false;

vb.AllocData(vb.NumberVertex * vb.VertexSize);
}
Expand All @@ -189,7 +187,6 @@ void cInterfaceRenderDevice::CreateIndexBuffer(IndexBuffer& ib, uint32_t NumberI

ib.dirty = true;
ib.locked = false;
ib.burned = false;

ib.AllocData(ib.NumberIndices * sizeof(indices_t));
}
Expand All @@ -210,7 +207,6 @@ void* cInterfaceRenderDevice::LockVertexBuffer(VertexBuffer &vb) {
xassert(0);
return nullptr;
}
xassert(!vb.burned);
xassert(!vb.locked);
vb.dirty = true;
vb.locked = true;
Expand All @@ -230,7 +226,6 @@ void cInterfaceRenderDevice::UnlockVertexBuffer(VertexBuffer &vb) {
#ifdef PERIMETER_RENDER_TRACKER_LOCKS
RenderSubmitEvent(RenderEvent::UNLOCK_VERTEXBUF, "", &vb);
#endif
xassert(!vb.burned);
xassert(vb.locked);
vb.locked = false;
}
Expand All @@ -244,7 +239,6 @@ indices_t* cInterfaceRenderDevice::LockIndexBuffer(IndexBuffer &ib) {
xassert(0);
return nullptr;
}
xassert(!ib.burned);
xassert(!ib.locked);
ib.dirty = true;
ib.locked = true;
Expand All @@ -264,7 +258,6 @@ void cInterfaceRenderDevice::UnlockIndexBuffer(IndexBuffer &ib) {
#ifdef PERIMETER_RENDER_TRACKER_LOCKS
RenderSubmitEvent(RenderEvent::UNLOCK_INDEXBUF, "", &ib);
#endif
xassert(!ib.burned);
xassert(ib.locked);
ib.locked = false;
}
Expand Down

0 comments on commit 43caa48

Please sign in to comment.