Index buffer upload.

This commit is contained in:
Ben Vanik 2013-10-20 00:47:32 -07:00
parent 5a80c7b9c1
commit 92899739bd
2 changed files with 26 additions and 19 deletions

View File

@ -179,7 +179,7 @@ void D3D11GraphicsDriver::DrawIndexBuffer(
} }
// Issue draw. // Issue draw.
uint32_t start_index = 0; //rf.values[XE_GPU_REG_VGT_INDX_OFFSET].u32; uint32_t start_index = rf.values[XE_GPU_REG_VGT_INDX_OFFSET].u32;
uint32_t base_vertex = 0; uint32_t base_vertex = 0;
context_->DrawIndexed(index_count, start_index, base_vertex); context_->DrawIndexed(index_count, start_index, base_vertex);
} }
@ -466,39 +466,45 @@ int D3D11GraphicsDriver::PrepareIndexBuffer(
uint32_t index_base, uint32_t index_size, uint32_t endianness) { uint32_t index_base, uint32_t index_size, uint32_t endianness) {
RegisterFile& rf = register_file_; RegisterFile& rf = register_file_;
uint32_t address = (index_base << 2) + address_translation_; uint32_t address = index_base + address_translation_;
//uint32_t size_dwords = fetch->size;
// All that's done so far:
XEASSERT(endianness == 0x2);
/*
ID3D11Buffer* buffer = 0; ID3D11Buffer* buffer = 0;
D3D11_BUFFER_DESC buffer_desc; D3D11_BUFFER_DESC buffer_desc;
xe_zero_struct(&buffer_desc, sizeof(buffer_desc)); xe_zero_struct(&buffer_desc, sizeof(buffer_desc));
buffer_desc.ByteWidth = size_dwords * 4; buffer_desc.ByteWidth = index_size;
buffer_desc.Usage = D3D11_USAGE_DYNAMIC; buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
buffer_desc.BindFlags = D3D11_BIND_INDEX_BUFFER; buffer_desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
device_->CreateBuffer(&buffer_desc, NULL, &buffer); device_->CreateBuffer(&buffer_desc, NULL, &buffer);
D3D11_MAPPED_SUBRESOURCE res; D3D11_MAPPED_SUBRESOURCE res;
context_->Map(buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &res); context_->Map(buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &res);
uint32_t* src = (uint32_t*)xe_memory_addr(memory_, address); if (index_32bit) {
uint32_t* dest = (uint32_t*)res.pData; uint32_t* src = (uint32_t*)xe_memory_addr(memory_, address);
for (uint32_t n = 0; n < size_dwords; n++) { uint32_t* dest = (uint32_t*)res.pData;
union { for (uint32_t n = 0; n < index_count; n++) {
uint32_t i; uint32_t d = { XESWAP32(src[n]) };
float f; XELOGGPU("i%.4d %0.8X", n, d);
} d = {XESWAP32(src[n])}; dest[n] = d;
XELOGGPU("v%.3d %0.8X %g", n, d.i, d.f); }
} else {
dest[n] = XESWAP32(src[n]); uint16_t* src = (uint16_t*)xe_memory_addr(memory_, address);
uint16_t* dest = (uint16_t*)res.pData;
for (uint32_t n = 0; n < index_count; n++) {
uint16_t d = XESWAP16(src[n]);
XELOGGPU("i%.4d, %.4X", n, d);
dest[n] = d;
}
} }
context_->Unmap(buffer, 0); context_->Unmap(buffer, 0);
DXGI_FORMAT format; DXGI_FORMAT format;
format = DXGI_FORMAT_R16_UINT; format = index_32bit ? DXGI_FORMAT_R32_UINT : DXGI_FORMAT_R16_UINT;
format = DXGI_FORMAT_R32_UINT;
context_->IASetIndexBuffer(buffer, format, 0); context_->IASetIndexBuffer(buffer, format, 0);
buffer->Release();*/ buffer->Release();
return 1; return 0;
} }

View File

@ -508,6 +508,7 @@ uint32_t RingBufferWorker::ExecutePacket(PacketArgs& args) {
uint32_t endianness = index_size >> 29; uint32_t endianness = index_size >> 29;
index_size &= 0x00FFFFFF; index_size &= 0x00FFFFFF;
bool index_32bit = (d1 >> 11) & 0x1; bool index_32bit = (d1 >> 11) & 0x1;
index_size *= index_32bit ? 4 : 2;
driver_->DrawIndexBuffer( driver_->DrawIndexBuffer(
(XE_GPU_PRIMITIVE_TYPE)prim_type, (XE_GPU_PRIMITIVE_TYPE)prim_type,
index_32bit, index_count, index_base, index_size, endianness); index_32bit, index_count, index_base, index_size, endianness);