modernize rx::die utility

This commit is contained in:
DH 2025-10-04 14:23:42 +03:00
parent 5904079a87
commit 825c92b135
11 changed files with 124 additions and 121 deletions

View file

@ -111,7 +111,7 @@ static bool isPrimRequiresConversion(gnm::PrimitiveType primType) {
return true;
default:
rx::die("unknown primitive type: %u", (unsigned)primType);
rx::die("unknown primitive type: {}", (unsigned)primType);
}
}
@ -142,7 +142,7 @@ static ConverterFn *getPrimConverterFn(gnm::PrimitiveType primType,
return quadStripPrimConverter;
default:
rx::die("getPrimConverterFn: unexpected primType %u",
rx::die("getPrimConverterFn: unexpected primType {}",
static_cast<unsigned>(primType));
}
}
@ -465,7 +465,7 @@ Cache::ShaderResources::eval(ir::InstructionId instId,
result = readPointer<std::array<std::uint32_t, 16>>(address);
break;
default:
rx::die("unexpected pointer load size %u", loadSize);
rx::die("unexpected pointer load size {}", loadSize);
}
return result;
@ -522,7 +522,7 @@ static VkShaderStageFlagBits shaderStageToVk(gcn::Stage stage) {
// case gcn::Stage::DsEs:
default:
rx::die("unsupported shader stage %u", int(stage));
rx::die("unsupported shader stage {}", int(stage));
}
}
@ -532,7 +532,7 @@ static void fillStageBindings(VkDescriptorSetLayoutBinding *bindings,
auto createDescriptorBinding = [&](VkDescriptorType type, uint32_t count,
int dim = 0) {
auto binding = Cache::getDescriptorBinding(type, dim);
rx::dieIf(binding < 0, "unexpected descriptor type %#x\n", int(type));
rx::dieIf(binding < 0, "unexpected descriptor type {:#x}\n", int(type));
bindings[binding] = VkDescriptorSetLayoutBinding{
.binding = static_cast<std::uint32_t>(binding),
.descriptorType = type,
@ -1983,20 +1983,17 @@ Cache::Image Cache::Tag::getImage(const ImageKey &key, Access access) {
key.nfmt == gnm::kNumericFormatUNorm) {
format = VK_FORMAT_D16_UNORM;
} else {
rx::die("unexpected depth format %u, %u", static_cast<int>(key.dfmt),
static_cast<int>(key.nfmt));
rx::die("unexpected depth format {}, {}", key.dfmt, key.nfmt);
}
} else if (key.kind == ImageKind::Stencil) {
if (key.dfmt == gnm::kDataFormat8 &&
key.nfmt == gnm::kNumericFormatUInt) {
format = VK_FORMAT_S8_UINT;
} else {
rx::die("unexpected stencil format %u, %u",
static_cast<int>(key.dfmt), static_cast<int>(key.nfmt));
rx::die("unexpected stencil format {}, {}", key.dfmt, key.nfmt);
}
} else {
rx::die("image kind %u %u, %u", static_cast<int>(key.kind),
static_cast<int>(key.dfmt), static_cast<int>(key.nfmt));
rx::die("image kind {} {}, {}", key.kind, key.dfmt, key.nfmt);
}
usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
@ -2425,8 +2422,8 @@ Cache::Shader Cache::GraphicsTag::getShader(
break;
default:
rx::die("unexpected resource slot in graphics shader %u, stage %u",
int(slot.type), int(stage));
rx::die("unexpected resource slot in graphics shader {}, stage {}",
slot.type, stage);
}
++index;
@ -2578,7 +2575,7 @@ Cache::ComputeTag::getShader(const Registers::ComputeConfig &pgm) {
break;
default:
rx::die("unexpected resource slot in compute shader %u", int(slot.type));
rx::die("unexpected resource slot in compute shader {}", slot.type);
}
++index;

View file

@ -680,7 +680,7 @@ void Device::onCommandBuffer(std::uint32_t pid, int cmdHeader,
size / sizeof(std::uint32_t)),
1);
} else {
rx::die("unimplemented command buffer %x", cmdHeader);
rx::die("unimplemented command buffer {:x}", cmdHeader);
}
}
@ -814,7 +814,7 @@ bool Device::flip(std::uint32_t pid, int bufferIndex, std::uint64_t arg,
break;
default:
rx::die("unimplemented color buffer format %x", bufferAttr.pixelFormat);
rx::die("unimplemented color buffer format {:x}", bufferAttr.pixelFormat);
}
// std::printf("displaying buffer %lx\n", buffer.address);
@ -1029,10 +1029,10 @@ void Device::mapMemory(std::uint32_t pid, std::uint64_t address,
perror("::mmap");
rx::mem::printStats();
rx::die("failed to map process %u memory, address %p-%p, type %x, offset "
"%lx, prot %x",
(int)pid, memory.getPointer(address),
memory.getPointer(address + size), memoryType, offset, prot);
rx::die("failed to map process {} memory, address {}-{}, type {:x}, offset "
"{:x}, prot {:x}",
pid, memory.getPointer(address), memory.getPointer(address + size),
memoryType, offset, prot);
}
// std::println(stderr, "map memory of process {}, address {}-{}, prot {:x}",

View file

@ -39,9 +39,8 @@ void DeviceCtl::submitGfxCommand(int gfxPipe, int vmId,
if ((op != gnm::IT_INDIRECT_BUFFER && op != gnm::IT_INDIRECT_BUFFER_CNST &&
op != gnm::IT_CONTEXT_CONTROL) ||
type != 3 || command.size() != len) {
rx::println(stderr, "unexpected gfx command for main ring: {}, {}, {}",
gnm::Pm4Opcode(op), type, len);
rx::die("");
rx::die("unexpected gfx command for main ring: {}, {}, {}",
gnm::Pm4Opcode(op), type, len);
}
std::vector<std::uint32_t> patchedCommand{command.data(),
@ -153,7 +152,7 @@ void DeviceCtl::registerBuffer(std::uint32_t pid, Buffer buffer) {
auto &process = mDevice->processInfo[pid];
if (buffer.attrId >= 10 || buffer.index >= 10) {
rx::die("out of buffers %u, %u", buffer.attrId, buffer.index);
rx::die("out of buffers {}, {}", buffer.attrId, buffer.index);
}
process.buffers[buffer.index] = buffer;
@ -164,7 +163,7 @@ void DeviceCtl::registerBufferAttribute(std::uint32_t pid,
// FIXME: submit command
auto &process = mDevice->processInfo[pid];
if (attr.attrId >= 10) {
rx::die("out of buffer attributes %u", attr.attrId);
rx::die("out of buffer attributes {}", attr.attrId);
}
process.bufferAttributes[attr.attrId] = attr;
@ -178,7 +177,7 @@ void DeviceCtl::mapComputeQueue(int vmId, std::uint32_t meId,
orbis::uint64_t doorbell,
orbis::uint64_t ringSize) {
if (meId != 1 && meId != 2) {
rx::die("unexpected ME %d", meId);
rx::die("unexpected ME {}", meId);
}
if (meId == 2) {
@ -186,7 +185,7 @@ void DeviceCtl::mapComputeQueue(int vmId, std::uint32_t meId,
}
if (queueId >= ComputePipe::kQueueCount) {
rx::die("unexpected queueId %d", queueId);
rx::die("unexpected queueId {}", queueId);
}
auto &pipe = mDevice->computePipes[pipeId];
@ -215,11 +214,11 @@ void DeviceCtl::submitComputeQueue(std::uint32_t meId, std::uint32_t pipeId,
std::uint32_t queueId,
std::uint64_t offset) {
if (meId != 1 && meId != 2) {
rx::die("unexpected ME %d", meId);
rx::die("unexpected ME {}", meId);
}
if (queueId >= ComputePipe::kQueueCount) {
rx::die("unexpected queueId %d", queueId);
rx::die("unexpected queueId {}", queueId);
}
if (meId == 2) {

View file

@ -173,7 +173,7 @@ bool ComputePipe::processRing(Ring &ring) {
continue;
}
rx::die("unexpected pm4 packet type %u", type);
rx::die("unexpected pm4 packet type {}", type);
}
if (origRptr != ring.rptr && ring.rptrReportLocation != nullptr) {
@ -188,13 +188,13 @@ bool ComputePipe::processRing(Ring &ring) {
void ComputePipe::setIndirectRing(int queueId, int indirectLevel, Ring ring) {
if (indirectLevel != 1) {
rx::die("unexpected compute indirect ring indirect level %d",
rx::die("unexpected compute indirect ring indirect level {}",
ring.indirectLevel);
}
ring.indirectLevel = indirectLevel;
rx::println(stderr, "mapQueue: {}, {}, {}", (void *)ring.base,
(void *)ring.wptr, ring.size);
(void *)ring.wptr, ring.size);
queues[1 - ring.indirectLevel][queueId] = ring;
}
@ -202,7 +202,7 @@ void ComputePipe::setIndirectRing(int queueId, int indirectLevel, Ring ring) {
void ComputePipe::mapQueue(int queueId, Ring ring,
std::unique_lock<orbis::shared_mutex> &lock) {
if (ring.indirectLevel < 0 || ring.indirectLevel > 1) {
rx::die("unexpected compute ring indirect level %d", ring.indirectLevel);
rx::die("unexpected compute ring indirect level {}", ring.indirectLevel);
}
if (ring.indirectLevel == 0) {
@ -257,7 +257,7 @@ bool ComputePipe::setShReg(Ring &ring) {
rx::dieIf(
(offset + len) * sizeof(std::uint32_t) > sizeof(Registers::ComputeConfig),
"out of compute regs, offset: %x, count %u, %s\n", offset, len,
"out of compute regs, offset: {:x}, count {}, {}\n", offset, len,
gnm::mmio::registerName(Registers::ShaderConfig::kMmioOffset + offset));
for (std::size_t i = 0; i < len; ++i) {
@ -341,7 +341,7 @@ bool ComputePipe::releaseMem(Ring &ring) {
break;
default:
rx::die("unimplemented event release mem data %#x", dataSel);
rx::die("unimplemented event release mem data {:#x}", dataSel);
}
if (intSel) {
@ -411,7 +411,7 @@ bool ComputePipe::writeData(Ring &ring) {
}
default:
rx::die("unimplemented write data, dst sel = %#x", dstSel);
rx::die("unimplemented write data, dst sel = {:#x}", dstSel);
}
if (wrOneAddress) {
@ -519,7 +519,7 @@ bool ComputePipe::dmaData(Ring &ring) {
break;
default:
rx::die("IT_DMA_DATA: unexpected dstSel %u", dstSel);
rx::die("IT_DMA_DATA: unexpected dstSel {}", dstSel);
}
void *src = nullptr;
@ -551,11 +551,11 @@ bool ComputePipe::dmaData(Ring &ring) {
break;
default:
rx::die("IT_DMA_DATA: unexpected srcSel %u", srcSel);
rx::die("IT_DMA_DATA: unexpected srcSel {}", srcSel);
}
rx::dieIf(size > srcSize && saic == 0,
"IT_DMA_DATA: out of source size srcSel %u, dstSel %u, size %u",
"IT_DMA_DATA: out of source size srcSel {}, dstSel {}, size {}",
srcSel, dstSel, size);
if (saic != 0) {
@ -581,7 +581,7 @@ bool ComputePipe::dmaData(Ring &ring) {
bool ComputePipe::unknownPacket(Ring &ring) {
auto op = rx::getBits(ring.rptr[0], 15, 8);
rx::die("unimplemented compute pm4 packet: %s, indirect level %u\n",
rx::die("unimplemented compute pm4 packet: {}, indirect level {}\n",
gnm::pm4OpcodeToString(op), ring.indirectLevel);
return true;
@ -597,8 +597,8 @@ std::uint32_t *ComputePipe::getMmRegister(Ring &ring, std::uint32_t dwAddress) {
return ring.doorbell + (dwAddress - Registers::ComputeConfig::kMmioOffset);
}
rx::die("unexpected memory mapped compute register address %x, %s", dwAddress,
gnm::mmio::registerName(dwAddress));
rx::die("unexpected memory mapped compute register address {:x}, {}",
dwAddress, gnm::mmio::registerName(dwAddress));
}
GraphicsPipe::GraphicsPipe(int index) : scheduler(createGfxScheduler(index)) {
@ -723,7 +723,7 @@ void GraphicsPipe::setCeQueue(Ring ring) {
}
void GraphicsPipe::setDeQueue(Ring ring, int indirectLevel) {
rx::dieIf(indirectLevel > 2, "out of indirect gfx rings, %u", indirectLevel);
rx::dieIf(indirectLevel > 2, "out of indirect gfx rings, {}", indirectLevel);
ring.indirectLevel = indirectLevel;
deQueues[2 - indirectLevel] = ring;
}
@ -757,7 +757,7 @@ std::uint32_t *GraphicsPipe::getMmRegister(std::uint32_t dwAddress) {
(dwAddress - Registers::Context::kMmioOffset);
}
rx::die("unexpected memory mapped register address %x, %s", dwAddress,
rx::die("unexpected memory mapped register address {:x}, {}", dwAddress,
gnm::mmio::registerName(dwAddress));
}
@ -864,9 +864,10 @@ void GraphicsPipe::processRing(Ring &ring) {
continue;
}
rx::die("unexpected pm4 packet type %u, ring %u, header %u, rptr %p, wptr "
"%p, base %p",
type, ring.indirectLevel, header, ring.rptr, ring.wptr, ring.base);
rx::die("unexpected pm4 packet type {}, ring {}, header {}, rptr {}, wptr "
"{}, base {}",
type, ring.indirectLevel, header, (void *)ring.rptr,
(void *)ring.wptr, ring.base);
}
}
@ -910,7 +911,7 @@ bool GraphicsPipe::setBase(Ring &ring) {
}
default:
rx::die("pm4: unknown SET_BASE index %u", baseIndex);
rx::die("pm4: unknown SET_BASE index {}", baseIndex);
}
return true;
@ -1184,7 +1185,7 @@ bool GraphicsPipe::writeData(Ring &ring) {
}
default:
rx::die("unimplemented write data, dst sel = %#x", dstSel);
rx::die("unimplemented write data, dst sel = {:#x}", dstSel);
}
if (wrOneAddress) {
@ -1319,7 +1320,7 @@ bool GraphicsPipe::eventWrite(Ring &ring) {
auto addressLo = ring.rptr[2] & ~7;
auto addressHi = ring.rptr[3] & ((1 << 16) - 1);
auto address = addressLo | (static_cast<std::uint64_t>(addressHi) << 32);
rx::die("unimplemented event write, event index %#x, address %lx",
rx::die("unimplemented event write, event index {:#x}, address {:x}",
eventIndex, address);
return true;
}
@ -1369,7 +1370,7 @@ bool GraphicsPipe::eventWriteEop(Ring &ring) {
break;
default:
rx::die("unimplemented event write eop data %#x", dataSel);
rx::die("unimplemented event write eop data {:x}", dataSel);
}
}
@ -1461,7 +1462,7 @@ bool GraphicsPipe::eventWriteEos(Ring &ring) {
break;
default:
rx::die("unexpected event write eos command: %#x", cmd);
rx::die("unexpected event write eos command: {:#x}", cmd);
}
return true;
}
@ -1539,7 +1540,7 @@ bool GraphicsPipe::dmaData(Ring &ring) {
break;
default:
rx::die("IT_DMA_DATA: unexpected dstSel %u", dstSel);
rx::die("IT_DMA_DATA: unexpected dstSel {}", dstSel);
}
void *src = nullptr;
@ -1571,11 +1572,11 @@ bool GraphicsPipe::dmaData(Ring &ring) {
break;
default:
rx::die("IT_DMA_DATA: unexpected srcSel %u", srcSel);
rx::die("IT_DMA_DATA: unexpected srcSel {}", srcSel);
}
rx::dieIf(size > srcSize && saic == 0,
"IT_DMA_DATA: out of source size srcSel %u, dstSel %u, size %u",
"IT_DMA_DATA: out of source size srcSel {}, dstSel {}, size {}",
srcSel, dstSel, size);
if (saic != 0) {
@ -1759,7 +1760,7 @@ bool GraphicsPipe::setShReg(Ring &ring) {
auto data = ring.rptr + 2;
rx::dieIf((offset + len) * sizeof(std::uint32_t) > sizeof(sh),
"out of SH regs, offset: %x, count %u, %s\n", offset, len,
"out of SH regs, offset: {:x}, count {}, {}\n", offset, len,
gnm::mmio::registerName(decltype(sh)::kMmioOffset + offset));
std::memcpy(reinterpret_cast<std::uint32_t *>(&sh) + offset,
@ -1802,7 +1803,7 @@ bool GraphicsPipe::setUConfigReg(Ring &ring) {
// }
rx::dieIf((offset + len) * sizeof(std::uint32_t) > sizeof(context),
"out of UConfig regs, offset: %u, count %u, %s\n", offset, len,
"out of UConfig regs, offset: {:x}, count {}, {}\n", offset, len,
gnm::mmio::registerName(decltype(uConfig)::kMmioOffset + offset));
std::memcpy(reinterpret_cast<std::uint32_t *>(&uConfig) + offset,
@ -1845,7 +1846,7 @@ bool GraphicsPipe::setContextReg(Ring &ring) {
// }
rx::dieIf((offset + len) * sizeof(std::uint32_t) > sizeof(context),
"out of Context regs, offset: %u, count %u, %s\n", offset, len,
"out of Context regs, offset: {:x}, count {}, {}\n", offset, len,
gnm::mmio::registerName(decltype(context)::kMmioOffset + offset));
std::memcpy(reinterpret_cast<std::uint32_t *>(&context) + offset,
@ -1930,7 +1931,7 @@ bool GraphicsPipe::dumpConstRam(Ring &ring) {
bool GraphicsPipe::unknownPacket(Ring &ring) {
auto op = rx::getBits(ring.rptr[0], 15, 8);
rx::die("unimplemented gfx pm4 packet: %s, queue %u\n",
rx::die("unimplemented gfx pm4 packet: {}, queue {}",
gnm::pm4OpcodeToString(op), ring.indirectLevel);
}
@ -1966,7 +1967,7 @@ bool GraphicsPipe::loadContextRegIndex(Ring &ring) {
// direct address
} else {
// offset
rx::die("%s: unimplemented index 1", __FUNCTION__);
rx::die("{}: unimplemented index 1", __FUNCTION__);
}
// std::println(
@ -2028,7 +2029,7 @@ bool GraphicsPipe::loadShRegIndex(Ring &ring) {
// direct address
} else {
// offset
rx::die("%s: unimplemented index 1", __FUNCTION__);
rx::die("{}: unimplemented index 1", __FUNCTION__);
}
if (dataFormat == 0) {
@ -2086,7 +2087,7 @@ bool GraphicsPipe::loadUConfigRegIndex(Ring &ring) {
// direct address
} else {
// offset
rx::die("%s: unimplemented index 1", __FUNCTION__);
rx::die("{}: unimplemented index 1", __FUNCTION__);
}
if (dataFormat == 0) {
@ -2141,7 +2142,7 @@ bool GraphicsPipe::setUConfigRegIndex(Ring &ring) {
auto data = ring.rptr + 2;
rx::dieIf((offset + len) * sizeof(std::uint32_t) > sizeof(context),
"out of UConfig regs, offset: %u, count %u, %s\n", offset, len,
"out of UConfig regs, offset: {:x}, count {}, {}\n", offset, len,
gnm::mmio::registerName(decltype(uConfig)::kMmioOffset + offset));
// for (std::size_t i = 0; i < len; ++i) {
@ -2205,11 +2206,12 @@ void CommandPipe::processRing(Ring &ring) {
continue;
}
rx::die("cmd pipe: unexpected pm4 packet type %u, ring %u, header %u, rptr "
"%p, wptr "
"%p, base %p, end %p",
type, ring.indirectLevel, header, ring.rptr, ring.wptr, ring.base,
ring.base + ring.size);
rx::die("cmd pipe: unexpected pm4 packet type {}, ring {}, header {}, rptr "
"{}, wptr "
"{}, base {}, end {}",
type, ring.indirectLevel, header, (void *)ring.rptr,
(void *)ring.wptr, (void *)ring.base,
(void *)(ring.base + ring.size));
}
}
@ -2278,6 +2280,6 @@ void CommandPipe::flip(Ring &ring) {
void CommandPipe::unknownPacket(Ring &ring) {
auto op = rx::getBits(ring.rptr[0], 15, 8);
rx::die("unexpected command pm4 packet: %s, queue %u\n",
rx::die("unexpected command pm4 packet: {}, queue {}\n",
gnm::pm4OpcodeToString(op), ring.indirectLevel);
}

View file

@ -146,8 +146,7 @@ static VkPrimitiveTopology toVkPrimitiveType(gnm::PrimitiveType type) {
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
default:
rx::die("toVkPrimitiveType: unexpected primitive type %u",
static_cast<unsigned>(type));
rx::die("toVkPrimitiveType: unexpected primitive type {}", type);
}
}
@ -162,7 +161,7 @@ void amdgpu::draw(GraphicsPipe &pipe, int vmId, std::uint32_t firstVertex,
if (pipe.context.cbColorControl.mode != gnm::CbMode::Normal &&
pipe.context.cbColorControl.mode != gnm::CbMode::EliminateFastClear) {
rx::println("unimplemented context.cbColorControl.mode = {}",
static_cast<gnm::CbMode>(pipe.context.cbColorControl.mode));
static_cast<gnm::CbMode>(pipe.context.cbColorControl.mode));
return;
}

View file

@ -560,7 +560,7 @@ ir::Value gcn::Context::readReg(ir::Location loc, Builder &builder,
return builder.createSpvBitcast(loc, getTypeFloat16(), result);
}
rx::die("unexpected value width %u", valWidth);
rx::die("unexpected value width {}", valWidth);
}
if ((valWidth % regWidth) != 0) {

View file

@ -27,7 +27,7 @@ inline VkImageType toVkImageType(gnm::TextureType type) {
return VK_IMAGE_TYPE_2D;
}
rx::die("toVkImageType: unexpected texture type %u",
rx::die("toVkImageType: unexpected texture type {}",
static_cast<unsigned>(type));
}
@ -51,7 +51,7 @@ inline VkImageViewType toVkImageViewType(gnm::TextureType type) {
return VK_IMAGE_VIEW_TYPE_2D_ARRAY;
}
rx::die("toVkImageViewType: unexpected texture type %u",
rx::die("toVkImageViewType: unexpected texture type {}",
static_cast<unsigned>(type));
}
@ -71,11 +71,11 @@ inline VkComponentSwizzle toVkComponentSwizzle(Swizzle swizzle) {
return VK_COMPONENT_SWIZZLE_A;
}
rx::die("toVkComponentSwizzle: unexpected swizzle %u\n",
rx::die("toVkComponentSwizzle: unexpected swizzle {}",
static_cast<unsigned>(swizzle));
}
static VkBlendFactor toVkBlendFactor(BlendMultiplier mul) {
inline VkBlendFactor toVkBlendFactor(BlendMultiplier mul) {
switch (mul) {
case BlendMultiplier::Zero:
return VK_BLEND_FACTOR_ZERO;
@ -117,10 +117,10 @@ static VkBlendFactor toVkBlendFactor(BlendMultiplier mul) {
return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA;
}
rx::die("VkBlendFactor: unexpected value %u\n", static_cast<unsigned>(mul));
rx::die("VkBlendFactor: unexpected value {}", static_cast<unsigned>(mul));
}
static VkBlendOp toVkBlendOp(BlendFunc func) {
inline VkBlendOp toVkBlendOp(BlendFunc func) {
switch (func) {
case BlendFunc::Add:
return VK_BLEND_OP_ADD;
@ -134,11 +134,11 @@ static VkBlendOp toVkBlendOp(BlendFunc func) {
return VK_BLEND_OP_REVERSE_SUBTRACT;
}
rx::die("blendFuncToVkBlendOp: unexpected value %u\n",
rx::die("blendFuncToVkBlendOp: unexpected value {}",
static_cast<unsigned>(func));
}
static VkFrontFace toVkFrontFace(Face face) {
inline VkFrontFace toVkFrontFace(Face face) {
switch (face) {
case Face::CW:
return VK_FRONT_FACE_CLOCKWISE;
@ -146,10 +146,10 @@ static VkFrontFace toVkFrontFace(Face face) {
return VK_FRONT_FACE_COUNTER_CLOCKWISE;
}
rx::die("toVkFrontFace: unexpected value %u\n", static_cast<unsigned>(face));
rx::die("toVkFrontFace: unexpected value {}", static_cast<unsigned>(face));
}
static VkIndexType toVkIndexType(IndexType indexType) {
inline VkIndexType toVkIndexType(IndexType indexType) {
switch (indexType) {
case IndexType::Int16:
return VK_INDEX_TYPE_UINT16;
@ -157,15 +157,15 @@ static VkIndexType toVkIndexType(IndexType indexType) {
return VK_INDEX_TYPE_UINT32;
}
rx::die("toVkIndexType: unexpected value %u\n",
rx::die("toVkIndexType: unexpected value {}",
static_cast<unsigned>(indexType));
}
static VkCompareOp toVkCompareOp(CompareFunc compareFn) {
inline VkCompareOp toVkCompareOp(CompareFunc compareFn) {
return static_cast<VkCompareOp>(compareFn);
}
static VkBorderColor toVkBorderColor(BorderColor color) {
inline VkBorderColor toVkBorderColor(BorderColor color) {
switch (color) {
case gnm::BorderColor::OpaqueBlack:
return VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
@ -180,11 +180,11 @@ static VkBorderColor toVkBorderColor(BorderColor color) {
return VK_BORDER_COLOR_FLOAT_CUSTOM_EXT;
}
rx::die("toVkBorderColor: unexpected value %u\n",
rx::die("toVkBorderColor: unexpected value {}\n",
static_cast<unsigned>(color));
}
static VkSamplerAddressMode toVkSamplerAddressMode(ClampMode clampMode) {
inline VkSamplerAddressMode toVkSamplerAddressMode(ClampMode clampMode) {
switch (clampMode) {
case ClampMode::Wrap:
return VK_SAMPLER_ADDRESS_MODE_REPEAT;
@ -208,11 +208,11 @@ static VkSamplerAddressMode toVkSamplerAddressMode(ClampMode clampMode) {
"toVkSamplerAddressMode: unimplemented ClampMode::MirrorOnceBorder");
}
rx::die("toVkSamplerAddressMode: unexpected value %u\n",
rx::die("toVkSamplerAddressMode: unexpected value {}",
static_cast<unsigned>(clampMode));
}
static VkFilter toVkFilter(Filter filter) {
inline VkFilter toVkFilter(Filter filter) {
switch (filter) {
case Filter::Point:
return VK_FILTER_NEAREST;
@ -224,10 +224,10 @@ static VkFilter toVkFilter(Filter filter) {
return VK_FILTER_LINEAR;
}
rx::die("toVkFilter: unexpected value %u\n", static_cast<unsigned>(filter));
rx::die("toVkFilter: unexpected value {}", static_cast<unsigned>(filter));
}
static VkSamplerMipmapMode toVkSamplerMipmapMode(MipFilter filter) {
inline VkSamplerMipmapMode toVkSamplerMipmapMode(MipFilter filter) {
switch (filter) {
case MipFilter::None:
return VK_SAMPLER_MIPMAP_MODE_NEAREST;
@ -237,7 +237,7 @@ static VkSamplerMipmapMode toVkSamplerMipmapMode(MipFilter filter) {
return VK_SAMPLER_MIPMAP_MODE_LINEAR;
}
rx::die("toVkSamplerMipmapMode: unexpected value %u\n",
rx::die("toVkSamplerMipmapMode: unexpected value {}",
static_cast<unsigned>(filter));
}
} // namespace gnm

View file

@ -645,5 +645,5 @@ VkFormat gnm::toVkFormat(DataFormat dfmt, NumericFormat nfmt) {
return it->second;
}
rx::die("unimplemented surface format. %x.%x\n", (int)dfmt, (int)nfmt);
rx::die("unimplemented surface format. {}.{}", dfmt, nfmt);
}

View file

@ -777,7 +777,7 @@ vk::Context::findPhysicalMemoryTypeIndex(std::uint32_t typeBits,
typeBits &= ~(1 << typeIndex);
}
rx::die("Failed to find memory type with properties %x", properties);
rx::die("Failed to find memory type with properties {:x}", properties);
}
vk::MemoryResource &vk::getHostVisibleMemory() { return g_hostVisibleMemory; }
@ -786,14 +786,14 @@ vk::MemoryResource &vk::getDeviceLocalMemory() { return g_deviceLocalMemory; }
static auto importDeviceVkProc(VkDevice device, const char *name) {
auto result = vkGetDeviceProcAddr(device, name);
rx::dieIf(result == nullptr,
"vkGetDeviceProcAddr: failed to get address of '%s'", name);
"vkGetDeviceProcAddr: failed to get address of '{}'", name);
return result;
}
static auto importInstanceVkProc(VkInstance instance, const char *name) {
auto result = vkGetInstanceProcAddr(instance, name);
rx::dieIf(result == nullptr,
"vkGetInstanceProcAddr: failed to get address of '%s'", name);
"vkGetInstanceProcAddr: failed to get address of '{}'", name);
return result;
}

View file

@ -1,7 +1,26 @@
#pragma once
#include "format.hpp"
namespace rx {
[[noreturn, gnu::format(printf, 1, 2)]] void die(const char *message, ...);
[[gnu::format(printf, 2, 3)]] void dieIf(bool condition, const char *message,
...);
namespace detail {
[[noreturn]] void dieImpl(std::string_view fmt, format_args args,
std::source_location location);
}
template <typename... Args>
[[noreturn]] void die(rx::format_string_with_location<Args...> fmt,
const Args &...args) {
detail::dieImpl(fmt.get(), make_format_args(const_cast<Args &>(args)...),
fmt.location);
}
template <typename... Args>
void dieIf(bool condition, rx::format_string_with_location<Args...> fmt,
const Args &...args) {
if (condition) {
detail::dieImpl(fmt.get(), make_format_args(const_cast<Args &>(args)...),
fmt.location);
}
}
} // namespace rx

View file

@ -1,31 +1,18 @@
#include "die.hpp"
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <rx/print.hpp>
void rx::die(const char *message, ...) {
va_list args;
va_start(args, message);
std::vfprintf(stderr, message, args);
std::fprintf(stderr, "\n");
va_end(args);
void rx::detail::dieImpl(std::string_view fmt, format_args args,
std::source_location location) {
rx::print(stderr, "\n");
rx::print(stderr, "{}:{}:{}: ", location.file_name(), location.line(),
location.column());
rx::vprint_nonunicode(stderr, fmt, args);
rx::print(stderr, "\n");
std::fflush(stdout);
std::fflush(stderr);
std::abort();
}
void rx::dieIf(bool condition, const char *message, ...) {
if (condition) {
va_list args;
va_start(args, message);
std::vfprintf(stderr, message, args);
std::fprintf(stderr, "\n");
va_end(args);
std::fflush(stdout);
std::fflush(stderr);
std::abort();
}
}