Back out the 32-bit index buffer support. Not actually needed for ImGui.

This commit is contained in:
Henrik Rydgård 2024-11-01 10:16:57 +01:00
parent 184a3ecf2a
commit 472103d460
11 changed files with 36 additions and 49 deletions

View File

@ -131,8 +131,8 @@ public:
void Draw(int vertexCount, int offset) override;
void DrawIndexed(int indexCount, int offset) override;
void DrawUP(const void *vdata, int vertexCount) override;
void DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt) override;
void DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt, Slice<ClippedDraw> draws) override;
void DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount) override;
void DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, Slice<ClippedDraw> draws) override;
void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) override;
@ -221,7 +221,6 @@ private:
bool dirtyIndexBuffer_ = false;
ID3D11Buffer *nextIndexBuffer_ = nullptr;
DXGI_FORMAT nextIndexBufferFormat_ = DXGI_FORMAT_R16_UINT;
UINT nextIndexBufferOffset_ = 0;
InvalidationCallback invalidationCallback_;
@ -1264,7 +1263,7 @@ void D3D11DrawContext::ApplyCurrentState() {
context_->IASetVertexBuffers(0, 1, &nextVertexBuffer_, &curPipeline_->input->stride, &nextVertexBufferOffset_);
}
if (dirtyIndexBuffer_) {
context_->IASetIndexBuffer(nextIndexBuffer_, nextIndexBufferFormat_, nextIndexBufferOffset_);
context_->IASetIndexBuffer(nextIndexBuffer_, DXGI_FORMAT_R16_UINT, nextIndexBufferOffset_);
dirtyIndexBuffer_ = false;
}
if (curPipeline_->dynamicUniforms) {
@ -1343,7 +1342,6 @@ void D3D11DrawContext::BindIndexBuffer(Buffer *indexBuffer, int offset) {
dirtyIndexBuffer_ = true;
nextIndexBuffer_ = buf ? buf->buf : 0;
nextIndexBufferOffset_ = buf ? offset : 0;
nextIndexBufferFormat_ = DXGI_FORMAT_R16_UINT;
}
void D3D11DrawContext::Draw(int vertexCount, int offset) {
@ -1365,31 +1363,27 @@ void D3D11DrawContext::DrawUP(const void *vdata, int vertexCount) {
Draw(vertexCount, offset);
}
void D3D11DrawContext::DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt) {
void D3D11DrawContext::DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount) {
int vbyteSize = vertexCount * curPipeline_->input->stride;
int ibyteSize = indexCount * (ifmt == IndexFormat::U32 ? 4 : 2);
int ibyteSize = indexCount * sizeof(u16);
UpdateBuffer(upBuffer_, (const uint8_t *)vdata, 0, vbyteSize, Draw::UPDATE_DISCARD);
BindVertexBuffer(upBuffer_, 0);
UpdateBuffer(upIBuffer_, (const uint8_t *)idata, 0, ibyteSize, Draw::UPDATE_DISCARD);
BindIndexBuffer(upIBuffer_, 0);
// Override the index buffer format.
nextIndexBufferFormat_ = ifmt == IndexFormat::U32 ? DXGI_FORMAT_R32_UINT : DXGI_FORMAT_R16_UINT;
DrawIndexed(indexCount, 0);
}
void D3D11DrawContext::DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt, Slice<ClippedDraw> draws) {
void D3D11DrawContext::DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, Slice<ClippedDraw> draws) {
int vbyteSize = vertexCount * curPipeline_->input->stride;
int ibyteSize = indexCount * (ifmt == IndexFormat::U32 ? 4 : 2);
int ibyteSize = indexCount * sizeof(u16);
UpdateBuffer(upBuffer_, (const uint8_t *)vdata, 0, vbyteSize, Draw::UPDATE_DISCARD);
BindVertexBuffer(upBuffer_, 0);
UpdateBuffer(upIBuffer_, (const uint8_t *)idata, 0, ibyteSize, Draw::UPDATE_DISCARD);
BindIndexBuffer(upIBuffer_, 0);
// Override the index buffer format.
nextIndexBufferFormat_ = ifmt == IndexFormat::U32 ? DXGI_FORMAT_R32_UINT : DXGI_FORMAT_R16_UINT;
ApplyCurrentState();

View File

@ -573,7 +573,7 @@ public:
void Draw(int vertexCount, int offset) override;
void DrawIndexed(int vertexCount, int offset) override;
void DrawUP(const void *vdata, int vertexCount) override;
void DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt) override;
void DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount) override;
void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) override;
uint64_t GetNativeObject(NativeObject obj, void *srcObject) override {
@ -1176,13 +1176,13 @@ void D3D9Context::DrawUP(const void *vdata, int vertexCount) {
device_->DrawPrimitiveUP(curPipeline_->prim, D3DPrimCount(curPipeline_->prim, vertexCount), vdata, curPipeline_->inputLayout->GetStride());
}
void D3D9Context::DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt) {
void D3D9Context::DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount) {
curPipeline_->inputLayout->Apply(device_);
curPipeline_->Apply(device_, stencilRef_, stencilWriteMask_, stencilCompareMask_);
ApplyDynamicState();
device_->DrawIndexedPrimitiveUP(curPipeline_->prim, 0, vertexCount, D3DPrimCount(curPipeline_->prim, indexCount),
idata, ifmt == IndexFormat::U32 ? D3DFMT_INDEX32 : D3DFMT_INDEX16,
idata, D3DFMT_INDEX16,
vdata, curPipeline_->inputLayout->GetStride());
}

View File

@ -443,8 +443,8 @@ public:
void Draw(int vertexCount, int offset) override;
void DrawIndexed(int vertexCount, int offset) override;
void DrawUP(const void *vdata, int vertexCount) override;
void DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt) override;
void DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt, Slice<ClippedDraw> draws) override;
void DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount) override;
void DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, Slice<ClippedDraw> draws) override;
void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) override;
@ -1420,11 +1420,11 @@ void OpenGLContext::DrawUP(const void *vdata, int vertexCount) {
renderManager_.Draw(curPipeline_->inputLayout->inputLayout_, buf, offset, curPipeline_->prim, 0, vertexCount);
}
void OpenGLContext::DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt) {
void OpenGLContext::DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount) {
_assert_(curPipeline_->inputLayout != nullptr);
int stride = curPipeline_->inputLayout->stride;
uint32_t vdataSize = stride * vertexCount;
uint32_t idataSize = indexCount * (ifmt == IndexFormat::U32 ? 4 : 2);
uint32_t idataSize = indexCount * sizeof(u16);
FrameData &frameData = frameData_[renderManager_.GetCurFrame()];
@ -1439,14 +1439,14 @@ void OpenGLContext::DrawIndexedUP(const void *vdata, int vertexCount, const void
memcpy(dest, idata, idataSize);
ApplySamplers();
renderManager_.DrawIndexed(curPipeline_->inputLayout->inputLayout_, vbuf, voffset, ibuf, ioffset, curPipeline_->prim, 0, ifmt == IndexFormat::U32 ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, vertexCount);
renderManager_.DrawIndexed(curPipeline_->inputLayout->inputLayout_, vbuf, voffset, ibuf, ioffset, curPipeline_->prim, 0, GL_UNSIGNED_SHORT, vertexCount);
}
void OpenGLContext::DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt, Slice<ClippedDraw> draws) {
void OpenGLContext::DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, Slice<ClippedDraw> draws) {
_assert_(curPipeline_->inputLayout != nullptr);
int stride = curPipeline_->inputLayout->stride;
uint32_t vdataSize = stride * vertexCount;
int indexSize = (ifmt == IndexFormat::U32 ? 4 : 2);
int indexSize = sizeof(u16);
uint32_t idataSize = indexCount * indexSize;
FrameData &frameData = frameData_[renderManager_.GetCurFrame()];
@ -1469,7 +1469,7 @@ void OpenGLContext::DrawIndexedClippedBatchUP(const void *vdata, int vertexCount
scissor.w = draw.clipw;
scissor.h = draw.cliph;
renderManager_.SetScissor(scissor);
renderManager_.DrawIndexed(curPipeline_->inputLayout->inputLayout_, vbuf, voffset, ibuf, ioffset + draw.indexOffset * indexSize, curPipeline_->prim, 0, ifmt == IndexFormat::U32 ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, draw.indexCount);
renderManager_.DrawIndexed(curPipeline_->inputLayout->inputLayout_, vbuf, voffset, ibuf, ioffset + draw.indexOffset * indexSize, curPipeline_->prim, 0, GL_UNSIGNED_SHORT, draw.indexCount);
}
}

View File

@ -1165,7 +1165,7 @@ void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer c
VkDescriptorSet set = (*descSets)[c.drawIndexed.descSetIndex].set;
_dbg_assert_(set != VK_NULL_HANDLE);
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &set, c.drawIndexed.numUboOffsets, c.drawIndexed.uboOffsets);
vkCmdBindIndexBuffer(cmd, c.drawIndexed.ibuffer, c.drawIndexed.ioffset, c.drawIndexed.itype);
vkCmdBindIndexBuffer(cmd, c.drawIndexed.ibuffer, c.drawIndexed.ioffset, VK_INDEX_TYPE_UINT16);
VkDeviceSize voffset = c.drawIndexed.voffset;
vkCmdBindVertexBuffers(cmd, 0, 1, &c.drawIndexed.vbuffer, &voffset);
vkCmdDrawIndexed(cmd, c.drawIndexed.count, c.drawIndexed.instances, 0, 0, 0);

View File

@ -80,7 +80,6 @@ struct VkRenderData {
uint32_t voffset;
uint32_t ioffset;
uint32_t count;
VkIndexType itype; // TODO: pack this into one of the others, it's really a single bit
} drawIndexed;
struct {
uint32_t clearColor;

View File

@ -471,7 +471,7 @@ public:
curRenderStep_->render.numDraws++;
}
void DrawIndexed(int descSetIndex, int numUboOffsets, const uint32_t *uboOffsets, VkBuffer vbuffer, int voffset, VkBuffer ibuffer, int ioffset, int count, int numInstances, VkIndexType itype) {
void DrawIndexed(int descSetIndex, int numUboOffsets, const uint32_t *uboOffsets, VkBuffer vbuffer, int voffset, VkBuffer ibuffer, int ioffset, int count, int numInstances) {
_dbg_assert_(curRenderStep_ && curRenderStep_->stepType == VKRStepType::RENDER && curStepHasViewport_ && curStepHasScissor_);
VkRenderData &data = curRenderStep_->commands.push_uninitialized();
data.cmd = VKRRenderCommand::DRAW_INDEXED;
@ -483,7 +483,6 @@ public:
data.drawIndexed.ibuffer = ibuffer;
data.drawIndexed.ioffset = ioffset;
data.drawIndexed.numUboOffsets = numUboOffsets;
data.drawIndexed.itype = itype;
_dbg_assert_(numUboOffsets <= ARRAY_SIZE(data.drawIndexed.uboOffsets));
for (int i = 0; i < numUboOffsets; i++)
data.drawIndexed.uboOffsets[i] = uboOffsets[i];

View File

@ -491,9 +491,9 @@ public:
void Draw(int vertexCount, int offset) override;
void DrawIndexed(int vertexCount, int offset) override;
void DrawUP(const void *vdata, int vertexCount) override;
void DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt) override;
void DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount) override;
// Specialized for quick IMGUI drawing.
void DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt, Slice<ClippedDraw>) override;
void DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, Slice<ClippedDraw>) override;
void BindCurrentPipeline();
void ApplyDynamicState();
@ -1501,7 +1501,7 @@ void VKContext::DrawIndexed(int vertexCount, int offset) {
int descSetIndex;
PackedDescriptor *descriptors = renderManager_.PushDescriptorSet(4, &descSetIndex);
BindDescriptors(vulkanUBObuf, descriptors);
renderManager_.DrawIndexed(descSetIndex, 1, &ubo_offset, vulkanVbuf, (int)vbBindOffset + curVBufferOffset_, vulkanIbuf, (int)ibBindOffset + offset * sizeof(uint32_t), vertexCount, 1, VK_INDEX_TYPE_UINT16);
renderManager_.DrawIndexed(descSetIndex, 1, &ubo_offset, vulkanVbuf, (int)vbBindOffset + curVBufferOffset_, vulkanIbuf, (int)ibBindOffset + offset * sizeof(uint32_t), vertexCount, 1);
}
void VKContext::DrawUP(const void *vdata, int vertexCount) {
@ -1527,7 +1527,7 @@ void VKContext::DrawUP(const void *vdata, int vertexCount) {
renderManager_.Draw(descSetIndex, 1, &ubo_offset, vulkanVbuf, (int)vbBindOffset, vertexCount);
}
void VKContext::DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt) {
void VKContext::DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount) {
_dbg_assert_(vertexCount >= 0);
_dbg_assert_(indexCount >= 0);
if (vertexCount <= 0 || indexCount <= 0) {
@ -1541,7 +1541,7 @@ void VKContext::DrawIndexedUP(const void *vdata, int vertexCount, const void *id
_assert_(vdataPtr != nullptr);
memcpy(vdataPtr, vdata, vdataSize);
size_t idataSize = indexCount * (ifmt == IndexFormat::U32 ? 4 : 2);
size_t idataSize = indexCount * sizeof(u16);
uint32_t ibBindOffset;
uint8_t *idataPtr = push_->Allocate(idataSize, 4, &vulkanIbuf, &ibBindOffset);
_assert_(idataPtr != nullptr);
@ -1554,10 +1554,10 @@ void VKContext::DrawIndexedUP(const void *vdata, int vertexCount, const void *id
int descSetIndex;
PackedDescriptor *descriptors = renderManager_.PushDescriptorSet(4, &descSetIndex);
BindDescriptors(vulkanUBObuf, descriptors);
renderManager_.DrawIndexed(descSetIndex, 1, &ubo_offset, vulkanVbuf, (int)vbBindOffset, vulkanIbuf, (int)ibBindOffset, indexCount, 1, ifmt == IndexFormat::U32 ? VK_INDEX_TYPE_UINT32 : VK_INDEX_TYPE_UINT16);
renderManager_.DrawIndexed(descSetIndex, 1, &ubo_offset, vulkanVbuf, (int)vbBindOffset, vulkanIbuf, (int)ibBindOffset, indexCount, 1);
}
void VKContext::DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt, Slice<ClippedDraw> draws) {
void VKContext::DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, Slice<ClippedDraw> draws) {
_dbg_assert_(vertexCount >= 0);
_dbg_assert_(indexCount >= 0);
if (vertexCount <= 0 || indexCount <= 0 || draws.is_empty()) {
@ -1571,7 +1571,7 @@ void VKContext::DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, co
_assert_(vdataPtr != nullptr);
memcpy(vdataPtr, vdata, vdataSize);
int indexSize = (ifmt == IndexFormat::U32 ? 4 : 2);
constexpr int indexSize = sizeof(u16);
size_t idataSize = indexCount * indexSize;
uint32_t ibBindOffset;
@ -1590,7 +1590,7 @@ void VKContext::DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, co
BindDescriptors(vulkanUBObuf, descriptors);
renderManager_.SetScissor(draw.clipx, draw.clipy, draw.clipw, draw.cliph);
renderManager_.DrawIndexed(descSetIndex, 1, &ubo_offset, vulkanVbuf, (int)vbBindOffset, vulkanIbuf,
(int)ibBindOffset + draw.indexOffset * indexSize, draw.indexCount, 1, ifmt == IndexFormat::U32 ? VK_INDEX_TYPE_UINT32 : VK_INDEX_TYPE_UINT16);
(int)ibBindOffset + draw.indexOffset * indexSize, draw.indexCount, 1);
}
}

View File

@ -180,11 +180,6 @@ enum class Facing {
CW,
};
enum class IndexFormat {
U16,
U32,
};
enum BorderColor {
DONT_CARE,
TRANSPARENT_BLACK,
@ -842,8 +837,8 @@ public:
virtual void Draw(int vertexCount, int offset) = 0;
virtual void DrawIndexed(int vertexCount, int offset) = 0; // Always 16-bit indices.
virtual void DrawUP(const void *vdata, int vertexCount) = 0;
virtual void DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt) = 0; // Supports 32-bit indices, for IMGUI use.
virtual void DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, IndexFormat ifmt, Slice<ClippedDraw> draws) {}
virtual void DrawIndexedUP(const void *vdata, int vertexCount, const void *idata, int indexCount) = 0; // Supports 32-bit indices, for IMGUI use.
virtual void DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, const void *idata, int indexCount, Slice<ClippedDraw> draws) {}
// Frame management (for the purposes of sync and resource management, necessary with modern APIs). Default implementations here.
virtual void BeginFrame(DebugFlags debugFlags) = 0;

View File

@ -374,7 +374,7 @@ void DrawEngineVulkan::DoFlush() {
if (!ibuf) {
ibOffset = (uint32_t)pushIndex_->Push(decIndex_, sizeof(uint16_t) * vertexCount, 4, &ibuf);
}
renderManager->DrawIndexed(descSetIndex, ARRAY_SIZE(dynamicUBOOffsets), dynamicUBOOffsets, vbuf, vbOffset, ibuf, ibOffset, vertexCount, 1, VK_INDEX_TYPE_UINT16);
renderManager->DrawIndexed(descSetIndex, ARRAY_SIZE(dynamicUBOOffsets), dynamicUBOOffsets, vbuf, vbOffset, ibuf, ibOffset, vertexCount, 1);
} else {
renderManager->Draw(descSetIndex, ARRAY_SIZE(dynamicUBOOffsets), dynamicUBOOffsets, vbuf, vbOffset, vertexCount);
}
@ -539,7 +539,7 @@ void DrawEngineVulkan::DoFlush() {
VkBuffer vbuf, ibuf;
vbOffset = (uint32_t)pushVertex_->Push(result.drawBuffer, numDecodedVerts_ * sizeof(TransformedVertex), 4, &vbuf);
ibOffset = (uint32_t)pushIndex_->Push(inds, sizeof(short) * result.drawNumTrans, 4, &ibuf);
renderManager->DrawIndexed(descSetIndex, ARRAY_SIZE(dynamicUBOOffsets), dynamicUBOOffsets, vbuf, vbOffset, ibuf, ibOffset, result.drawNumTrans, 1, VK_INDEX_TYPE_UINT16);
renderManager->DrawIndexed(descSetIndex, ARRAY_SIZE(dynamicUBOOffsets), dynamicUBOOffsets, vbuf, vbOffset, ibuf, ibOffset, result.drawNumTrans, 1);
} else if (result.action == SW_CLEAR) {
// Note: we won't get here if the clear is alpha but not color, or color but not alpha.
bool clearColor = gstate.isClearModeColorMask();

View File

@ -27,7 +27,7 @@
//#define IMGUI_API __declspec( dllimport )
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names.
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87+ disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This is automatically done by IMGUI_DISABLE_OBSOLETE_FUNCTIONS.
//---- Disable all of Dear ImGui or don't implement standard windows/tools.

View File

@ -76,7 +76,7 @@ void ImGui_ImplThin3d_RenderDrawData(ImDrawData* draw_data, Draw::DrawContext *d
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
const Draw::IndexFormat idxFormat = sizeof(ImDrawIdx) == 2 ? Draw::IndexFormat::U16 : Draw::IndexFormat::U32;
_assert_(sizeof(ImDrawIdx) == 2);
std::vector<Draw::ClippedDraw> draws;
// Render command lists
@ -116,7 +116,7 @@ void ImGui_ImplThin3d_RenderDrawData(ImDrawData* draw_data, Draw::DrawContext *d
draws.push_back(draw);
}
}
draw->DrawIndexedClippedBatchUP(cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.size(), cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.size(), idxFormat, draws);
draw->DrawIndexedClippedBatchUP(cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.size(), cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.size(), draws);
}
draw->SetScissorRect(0, 0, fb_width, fb_height);