Skip to content

Commit 250afe4

Browse files
committed
const
1 parent 925fe5f commit 250afe4

5 files changed

Lines changed: 32 additions & 30 deletions

File tree

include/API/FormatConversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ validateTextureDescMatchesCPUBuffer(const TextureCreateDesc &Desc,
137137
"TextureCreateDesc mip levels %u does not match CPUBuffer mip "
138138
"levels %d.",
139139
Desc.MipLevels, Buf.OutputProps.MipLevels);
140-
uint32_t TexelSize = getFormatSize(Desc.Format);
140+
const uint32_t TexelSize = getFormatSize(Desc.Format);
141141
if (Buf.Stride > 0 && static_cast<uint32_t>(Buf.Stride) != TexelSize)
142142
return llvm::createStringError(
143143
std::errc::invalid_argument,
144144
"CPUBuffer stride %d does not match texture format element size %u.",
145145
Buf.Stride, TexelSize);
146-
uint64_t ExpectedSize =
146+
const uint64_t ExpectedSize =
147147
static_cast<uint64_t>(Desc.Width) * Desc.Height * TexelSize;
148148
if (static_cast<uint64_t>(Buf.size()) != ExpectedSize)
149149
return llvm::createStringError(

include/API/Texture.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ enum TextureUsage : uint32_t {
3333
LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ DepthStencil)
3434
};
3535

36-
3736
inline std::string getTextureUsageName(TextureUsage Usage) {
3837
std::string Result;
3938
if ((Usage & Sampled) != 0)
@@ -84,9 +83,9 @@ inline llvm::Error validateTextureCreateDesc(const TextureCreateDesc &Desc) {
8483
"Format '%s' is not compatible with texture creation.",
8584
getFormatName(Desc.Format).data());
8685

87-
bool IsDepth = isDepthFormat(Desc.Format);
88-
bool IsRT = (Desc.Usage & TextureUsage::RenderTarget) != 0;
89-
bool IsDS = (Desc.Usage & TextureUsage::DepthStencil) != 0;
86+
const bool IsDepth = isDepthFormat(Desc.Format);
87+
const bool IsRT = (Desc.Usage & TextureUsage::RenderTarget) != 0;
88+
const bool IsDS = (Desc.Usage & TextureUsage::DepthStencil) != 0;
9089

9190
// DepthStencil + RenderTarget is not supported.
9291
if (IsDS && IsRT)

lib/API/DX/Device.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,13 @@ class DXDevice : public offloadtest::Device {
476476

477477
auto Tex = std::make_shared<DXTexture>(DeviceTexture, Name, Desc);
478478

479-
bool IsRT = (Desc.Usage & TextureUsage::RenderTarget) != 0;
480-
bool IsDS = (Desc.Usage & TextureUsage::DepthStencil) != 0;
479+
const bool IsRT = (Desc.Usage & TextureUsage::RenderTarget) != 0;
480+
const bool IsDS = (Desc.Usage & TextureUsage::DepthStencil) != 0;
481481
if (IsRT || IsDS) {
482482
D3D12_DESCRIPTOR_HEAP_DESC HeapDesc = {};
483483
HeapDesc.NumDescriptors = 1;
484-
HeapDesc.Type =
485-
IsRT ? D3D12_DESCRIPTOR_HEAP_TYPE_RTV : D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
484+
HeapDesc.Type = IsRT ? D3D12_DESCRIPTOR_HEAP_TYPE_RTV
485+
: D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
486486
HeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
487487
if (auto Err = HR::toError(Device->CreateDescriptorHeap(
488488
&HeapDesc, IID_PPV_ARGS(&Tex->ViewHeap)),
@@ -1673,7 +1673,8 @@ class DXDevice : public offloadtest::Device {
16731673
CD3DX12_SUBRESOURCE_FOOTPRINT(
16741674
getDXFormat(B.Format, B.Channels), B.OutputProps.Width,
16751675
B.OutputProps.Height, 1, B.OutputProps.Width * B.getElementSize())};
1676-
const CD3DX12_TEXTURE_COPY_LOCATION DstLoc(IS.RTReadback->Buffer.Get(), Footprint);
1676+
const CD3DX12_TEXTURE_COPY_LOCATION DstLoc(IS.RTReadback->Buffer.Get(),
1677+
Footprint);
16771678
const CD3DX12_TEXTURE_COPY_LOCATION SrcLoc(IS.RT->Resource.Get(), 0);
16781679

16791680
IS.CmdList->CopyTextureRegion(&DstLoc, 0, 0, 0, &SrcLoc, nullptr);
@@ -1779,7 +1780,8 @@ class DXDevice : public offloadtest::Device {
17791780
llvm::outs() << "Compute command list created.\n";
17801781

17811782
} else {
1782-
// Create render target, depth/stencil, readback and vertex buffer and PSO.
1783+
// Create render target, depth/stencil, readback and vertex buffer and
1784+
// PSO.
17831785
if (auto Err = createRenderTarget(P, State))
17841786
return Err;
17851787
llvm::outs() << "Render target created.\n";

lib/API/MTL/MTLDevice.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class MTLDevice : public offloadtest::Device {
371371
if (TableSize > 0) {
372372
IS.ArgBuffer =
373373
Device->newBuffer(TableSize, MTL::ResourceStorageModeManaged);
374-
uint32_t HeapIndex = 0;
374+
const uint32_t HeapIndex = 0;
375375
for (auto &D : P.Sets) {
376376
for (auto &R : D.Resources) {
377377
if (auto Err = createDescriptor(R, IS, HeapIndex++))
@@ -513,25 +513,26 @@ class MTLDevice : public offloadtest::Device {
513513
auto *CADesc = MTL::RenderPassColorAttachmentDescriptor::alloc()->init();
514514
CADesc->setTexture(IS.FrameBufferTexture->Tex);
515515
CADesc->setLoadAction(MTL::LoadActionClear);
516-
const auto *ColorCV =
517-
std::get_if<ClearColor>(&*IS.FrameBufferTexture->Desc.OptimizedClearValue);
516+
const auto *ColorCV = std::get_if<ClearColor>(
517+
&*IS.FrameBufferTexture->Desc.OptimizedClearValue);
518518
if (!ColorCV)
519519
return llvm::createStringError(
520520
std::errc::invalid_argument,
521521
"Render target clear value must be a ClearColor.");
522522

523-
CADesc->setClearColor(MTL::ClearColor(ColorCV->R, ColorCV->G, ColorCV->B, ColorCV->A));
523+
CADesc->setClearColor(
524+
MTL::ClearColor(ColorCV->R, ColorCV->G, ColorCV->B, ColorCV->A));
524525
CADesc->setStoreAction(MTL::StoreActionStore);
525526
Desc->colorAttachments()->setObject(CADesc, 0);
526527

527528
// Depth/stencil attachment.
528-
const auto *DepthCV =
529-
std::get_if<ClearDepthStencil>(&*IS.DepthStencil->Desc.OptimizedClearValue);
529+
const auto *DepthCV = std::get_if<ClearDepthStencil>(
530+
&*IS.DepthStencil->Desc.OptimizedClearValue);
530531
if (!DepthCV)
531532
return llvm::createStringError(
532533
std::errc::invalid_argument,
533534
"Depth/stencil clear value must be a ClearDepthStencil.");
534-
535+
535536
auto *DADesc = Desc->depthAttachment();
536537
DADesc->setTexture(IS.DepthStencil->Tex);
537538
DADesc->setLoadAction(MTL::LoadActionClear);
@@ -598,8 +599,8 @@ class MTLDevice : public offloadtest::Device {
598599
}
599600

600601
llvm::Error copyBack(Pipeline &P, InvocationState &IS) {
601-
uint32_t TextureIndex = 0;
602-
uint32_t BufferIndex = 0;
602+
const uint32_t TextureIndex = 0;
603+
const uint32_t BufferIndex = 0;
603604
for (auto &D : P.Sets) {
604605
for (auto &R : D.Resources) {
605606
assert(R.BufferPtr->ArraySize == 1 &&

lib/API/VK/Device.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,8 @@ class VulkanDevice : public offloadtest::Device {
769769
auto Tex = std::make_shared<VulkanTexture>(Device, Image, DeviceMemory,
770770
Name, Desc);
771771

772-
bool IsRT = (Desc.Usage & TextureUsage::RenderTarget) != 0;
773-
bool IsDS = (Desc.Usage & TextureUsage::DepthStencil) != 0;
772+
const bool IsRT = (Desc.Usage & TextureUsage::RenderTarget) != 0;
773+
const bool IsDS = (Desc.Usage & TextureUsage::DepthStencil) != 0;
774774
if (IsRT || IsDS) {
775775
VkImageViewCreateInfo ViewCi = {};
776776
ViewCi.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
@@ -1544,7 +1544,7 @@ class VulkanDevice : public offloadtest::Device {
15441544
return llvm::Error::success();
15451545
}
15461546

1547-
llvm::Error createRenderPass(Pipeline &P, InvocationState &IS) {
1547+
llvm::Error createRenderPass(InvocationState &IS) {
15481548
std::array<VkAttachmentDescription, 2> Attachments = {};
15491549

15501550
Attachments[0].format = getVulkanFormat(IS.RenderTarget->Desc.Format);
@@ -1626,7 +1626,7 @@ class VulkanDevice : public offloadtest::Device {
16261626
return llvm::Error::success();
16271627
}
16281628

1629-
llvm::Error createFrameBuffer(Pipeline &P, InvocationState &IS) {
1629+
llvm::Error createFrameBuffer(InvocationState &IS) {
16301630
std::array<VkImageView, 2> Views = {IS.RenderTarget->View,
16311631
IS.DepthStencil->View};
16321632

@@ -2009,9 +2009,9 @@ class VulkanDevice : public offloadtest::Device {
20092009
VkImageLayout OldLayout,
20102010
VkAccessFlags SrcAccessMask,
20112011
VkPipelineStageFlags SrcStageMask) {
2012-
VkImageAspectFlags AspectMask = isDepthFormat(Tex.Desc.Format)
2013-
? VK_IMAGE_ASPECT_DEPTH_BIT
2014-
: VK_IMAGE_ASPECT_COLOR_BIT;
2012+
const VkImageAspectFlags AspectMask = isDepthFormat(Tex.Desc.Format)
2013+
? VK_IMAGE_ASPECT_DEPTH_BIT
2014+
: VK_IMAGE_ASPECT_COLOR_BIT;
20152015

20162016
// Transition texture to transfer source.
20172017
VkImageSubresourceRange SubRange = {};
@@ -2425,10 +2425,10 @@ class VulkanDevice : public offloadtest::Device {
24252425
if (auto Err = createResources(P, State))
24262426
return Err;
24272427
if (P.isGraphics()) {
2428-
if (auto Err = createRenderPass(P, State))
2428+
if (auto Err = createRenderPass(State))
24292429
return Err;
24302430
llvm::outs() << "Render pass created.\n";
2431-
if (auto Err = createFrameBuffer(P, State))
2431+
if (auto Err = createFrameBuffer(State))
24322432
return Err;
24332433
llvm::outs() << "Frame buffer created.\n";
24342434
}

0 commit comments

Comments
 (0)