Skip to content

Commit 557f056

Browse files
authored
format code (#7621)
Co-authored-by: slangbot <[email protected]>
1 parent 8361fc7 commit 557f056

File tree

60 files changed

+571
-505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+571
-505
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ function(example dir)
6060
platform
6161
$<$<BOOL:${SLANG_ENABLE_CUDA}>:CUDA::cuda_driver>
6262
${main_wrapper_libraries}
63-
INCLUDE_DIRECTORIES_PUBLIC
64-
${slang_SOURCE_DIR}
63+
INCLUDE_DIRECTORIES_PUBLIC ${slang_SOURCE_DIR}
6564
EXTRA_COMPILE_DEFINITIONS_PRIVATE
6665
SLANG_EXAMPLE_NAME=${dir}
6766
$<$<BOOL:${SLANG_ENABLE_XLIB}>:SLANG_ENABLE_XLIB>

examples/autodiff-texture/main.cpp

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "core/slang-basic.h"
22
#include "examples/example-base/example-base.h"
3-
#include "slang-rhi/shader-cursor.h"
43
#include "platform/vector-math.h"
54
#include "platform/window.h"
65
#include "slang-com-ptr.h"
76
#include "slang-rhi.h"
7+
#include "slang-rhi/shader-cursor.h"
88
#include "slang.h"
99

1010
using namespace rhi;
@@ -96,10 +96,7 @@ struct AutoDiffTexture : public WindowedAppBase
9696
return SLANG_OK;
9797
}
9898

99-
Result loadComputeProgram(
100-
IDevice* device,
101-
const char* fileName,
102-
IShaderProgram** outProgram)
99+
Result loadComputeProgram(IDevice* device, const char* fileName, IShaderProgram** outProgram)
103100
{
104101
ComPtr<slang::ISession> slangSession;
105102
slangSession = device->getSlangSession();
@@ -178,19 +175,16 @@ struct AutoDiffTexture : public WindowedAppBase
178175

179176
bool resetLearntTexture = false;
180177

181-
ComPtr<ITexture> createRenderTargetTexture(
182-
Format format,
183-
int w,
184-
int h,
185-
int levels)
178+
ComPtr<ITexture> createRenderTargetTexture(Format format, int w, int h, int levels)
186179
{
187180
TextureDesc textureDesc = {};
188181
textureDesc.format = format;
189182
textureDesc.size.width = w;
190183
textureDesc.size.height = h;
191184
textureDesc.size.depth = 1;
192185
textureDesc.mipCount = levels;
193-
textureDesc.usage = TextureUsage::ShaderResource | TextureUsage::UnorderedAccess | TextureUsage::RenderTarget;
186+
textureDesc.usage = TextureUsage::ShaderResource | TextureUsage::UnorderedAccess |
187+
TextureUsage::RenderTarget;
194188
textureDesc.defaultState = ResourceState::RenderTarget;
195189
return gDevice->createTexture(textureDesc);
196190
}
@@ -225,9 +219,7 @@ struct AutoDiffTexture : public WindowedAppBase
225219
TextureViewDesc srvDesc = {};
226220
return gDevice->createTextureView(tex, srvDesc);
227221
}
228-
ComPtr<IRenderPipeline> createRenderPipeline(
229-
IInputLayout* inputLayout,
230-
IShaderProgram* program)
222+
ComPtr<IRenderPipeline> createRenderPipeline(IInputLayout* inputLayout, IShaderProgram* program)
231223
{
232224
ColorTargetDesc colorTarget;
233225
colorTarget.format = Format::RGBA8Unorm;
@@ -254,8 +246,8 @@ struct AutoDiffTexture : public WindowedAppBase
254246
TextureViewDesc desc = {};
255247
SubresourceRange textureViewRange = {};
256248
textureViewRange.mipCount = 1;
257-
textureViewRange.mip = level; // Fixed: should be level, not 0
258-
textureViewRange.layerCount = 1; // Fixed: should be 1, not level
249+
textureViewRange.mip = level; // Fixed: should be level, not 0
250+
textureViewRange.layerCount = 1; // Fixed: should be 1, not level
259251
textureViewRange.layer = 0;
260252
desc.subresourceRange = textureViewRange;
261253
return gDevice->createTextureView(texture, desc);
@@ -357,21 +349,21 @@ struct AutoDiffTexture : public WindowedAppBase
357349
// Load texture from file - this would need to be adapted to use slang-rhi texture loading
358350
Slang::String imagePath = resourceBase.resolveResource("checkerboard.jpg");
359351
gTexView = createTextureFromFile(imagePath.getBuffer(), textureWidth, textureHeight);
360-
textureWidth = 512; // Placeholder values
352+
textureWidth = 512; // Placeholder values
361353
textureHeight = 512;
362354
initMipOffsets(textureWidth, textureHeight);
363355

364356
BufferDesc bufferDesc = {};
365357
bufferDesc.size = mipMapOffset.getLast() * sizeof(uint32_t);
366358
bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess;
367-
359+
368360
gAccumulateBuffer = gDevice->createBuffer(bufferDesc);
369361
if (!gAccumulateBuffer)
370362
{
371363
printf("ERROR: Failed to create accumulate buffer!\n");
372364
return SLANG_FAIL;
373365
}
374-
366+
375367
gReconstructBuffer = gDevice->createBuffer(bufferDesc);
376368
if (!gReconstructBuffer)
377369
{
@@ -381,21 +373,14 @@ struct AutoDiffTexture : public WindowedAppBase
381373

382374
int mipCount = 1 + Math::Log2Ceil(Math::Max(textureWidth, textureHeight));
383375
SubresourceData initialData = {};
384-
initialData.data =
385-
gLearningTexture = createRenderTargetTexture(
386-
Format::RGBA32Float,
387-
textureWidth,
388-
textureHeight,
389-
mipCount);
376+
initialData.data = gLearningTexture =
377+
createRenderTargetTexture(Format::RGBA32Float, textureWidth, textureHeight, mipCount);
390378
gLearningTextureSRV = createSRV(gLearningTexture);
391379
for (int i = 0; i < mipCount; i++)
392380
gLearningTextureUAVs.add(createUAV(gLearningTexture, i));
393381

394-
gDiffTexture = createRenderTargetTexture(
395-
Format::RGBA32Float,
396-
textureWidth,
397-
textureHeight,
398-
mipCount);
382+
gDiffTexture =
383+
createRenderTargetTexture(Format::RGBA32Float, textureWidth, textureHeight, mipCount);
399384
gDiffTextureSRV = createSRV(gDiffTexture);
400385
for (int i = 0; i < mipCount; i++)
401386
gDiffTextureUAVs.add(createUAV(gDiffTexture, i));
@@ -409,8 +394,7 @@ struct AutoDiffTexture : public WindowedAppBase
409394
gRefImage = createRenderTargetTexture(Format::RGBA8Unorm, windowWidth, windowHeight, 1);
410395
gRefImageSRV = createSRV(gRefImage);
411396

412-
gIterImage =
413-
createRenderTargetTexture(Format::RGBA8Unorm, windowWidth, windowHeight, 1);
397+
gIterImage = createRenderTargetTexture(Format::RGBA8Unorm, windowWidth, windowHeight, 1);
414398
gIterImageSRV = createSRV(gIterImage);
415399

416400
// Initialize textures
@@ -419,7 +403,7 @@ struct AutoDiffTexture : public WindowedAppBase
419403
// Clear learning and diff textures
420404
commandEncoder->clearTextureFloat(gLearningTexture, kEntireTexture, clearValue);
421405
commandEncoder->clearTextureFloat(gDiffTexture, kEntireTexture, clearValue);
422-
406+
423407
gQueue->submit(commandEncoder->finish());
424408
}
425409

@@ -464,9 +448,7 @@ struct AutoDiffTexture : public WindowedAppBase
464448
}
465449

466450
template<typename SetupPipelineFunc>
467-
void renderImage(
468-
ITexture* renderTarget,
469-
const SetupPipelineFunc& setupPipeline)
451+
void renderImage(ITexture* renderTarget, const SetupPipelineFunc& setupPipeline)
470452
{
471453
auto commandEncoder = gQueue->createCommandEncoder();
472454

@@ -517,7 +499,8 @@ struct AutoDiffTexture : public WindowedAppBase
517499
gRefImage,
518500
[&](IRenderPassEncoder* encoder)
519501
{
520-
auto rootObject = encoder->bindPipeline(static_cast<IRenderPipeline*>(gRefPipeline.get()));
502+
auto rootObject =
503+
encoder->bindPipeline(static_cast<IRenderPipeline*>(gRefPipeline.get()));
521504
ShaderCursor rootCursor(rootObject);
522505
rootCursor["Uniforms"]["modelViewProjection"].setData(
523506
&transformMatrix,
@@ -528,7 +511,8 @@ struct AutoDiffTexture : public WindowedAppBase
528511
mipMapOffset.getBuffer(),
529512
sizeof(uint32_t) * mipMapOffset.getCount());
530513
rootCursor["Uniforms"]["texRef"].setBinding(gTexView);
531-
rootCursor["Uniforms"]["bwdTexture"]["accumulateBuffer"].setBinding(gAccumulateBuffer);
514+
rootCursor["Uniforms"]["bwdTexture"]["accumulateBuffer"].setBinding(
515+
gAccumulateBuffer);
532516
});
533517
}
534518

@@ -544,7 +528,7 @@ struct AutoDiffTexture : public WindowedAppBase
544528
auto commandEncoder = gQueue->createCommandEncoder();
545529
commandEncoder->clearBuffer(gAccumulateBuffer, 0, gAccumulateBuffer->getDesc().size);
546530
commandEncoder->clearBuffer(gReconstructBuffer, 0, gReconstructBuffer->getDesc().size);
547-
531+
548532
if (resetLearntTexture)
549533
{
550534
commandEncoder->clearTextureFloat(gLearningTexture, kEntireTexture, clearValue);
@@ -570,7 +554,8 @@ struct AutoDiffTexture : public WindowedAppBase
570554
mipMapOffset.getBuffer(),
571555
sizeof(uint32_t) * mipMapOffset.getCount());
572556
rootCursor["Uniforms"]["texRef"].setBinding(gRefImageSRV);
573-
rootCursor["Uniforms"]["bwdTexture"]["accumulateBuffer"].setBinding(gAccumulateBuffer);
557+
rootCursor["Uniforms"]["bwdTexture"]["accumulateBuffer"].setBinding(
558+
gAccumulateBuffer);
574559
rootCursor["Uniforms"]["bwdTexture"]["minLOD"].setData(5.0);
575560
});
576561

@@ -671,7 +656,7 @@ struct AutoDiffTexture : public WindowedAppBase
671656
renderPass.colorAttachmentCount = 1;
672657

673658
auto renderEncoder = commandEncoder->beginRenderPass(renderPass);
674-
659+
675660
drawTexturedQuad(renderEncoder, 0, 0, textureWidth, textureHeight, gLearningTextureSRV);
676661

677662
int refImageWidth = windowWidth - textureWidth - 10;
@@ -718,7 +703,8 @@ struct AutoDiffTexture : public WindowedAppBase
718703
renderState.vertexBufferCount = 1;
719704
renderEncoder->setRenderState(renderState);
720705

721-
auto root = renderEncoder->bindPipeline(static_cast<IRenderPipeline*>(gDrawQuadPipeline.get()));
706+
auto root =
707+
renderEncoder->bindPipeline(static_cast<IRenderPipeline*>(gDrawQuadPipeline.get()));
722708
ShaderCursor rootCursor(root);
723709
rootCursor["Uniforms"]["x"].setData(x);
724710
rootCursor["Uniforms"]["y"].setData(y);
@@ -728,7 +714,7 @@ struct AutoDiffTexture : public WindowedAppBase
728714
rootCursor["Uniforms"]["viewHeight"].setData(windowHeight);
729715
rootCursor["Uniforms"]["texture"].setBinding(srv);
730716
rootCursor["Uniforms"]["sampler"].setBinding(gSampler);
731-
717+
732718
DrawArguments drawArgs = {};
733719
drawArgs.vertexCount = 4;
734720
renderEncoder->draw(drawArgs);

examples/example-base/example-base.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ Slang::Result WindowedAppBase::initializeBase(
2424
deviceDesc.enableValidation = true;
2525
#endif
2626
gDevice = getRHI()->createDevice(deviceDesc);
27-
if (!gDevice) {
27+
if (!gDevice)
28+
{
2829
return SLANG_FAIL;
2930
}
3031

@@ -163,7 +164,8 @@ ComPtr<ITextureView> WindowedAppBase::createTextureFromFile(
163164

164165
void WindowedAppBase::createOfflineTextures()
165166
{
166-
for (uint32_t i = 0; i < kSwapchainImageCount; i++) {
167+
for (uint32_t i = 0; i < kSwapchainImageCount; i++)
168+
{
167169
TextureDesc textureDesc = {};
168170
textureDesc.size.width = this->windowWidth;
169171
textureDesc.size.height = this->windowHeight;

examples/example-base/example-base.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ struct WindowedAppBase : public TestBase
5858
virtual void windowSizeChanged();
5959

6060
protected:
61-
// virtual void renderFrame(int framebufferIndex) = 0;
61+
// virtual void renderFrame(int framebufferIndex) = 0;
6262
virtual void renderFrame(rhi::ITexture* texture) = 0;
63+
6364
public:
6465
platform::Window* getWindow() { return gWindow.Ptr(); }
6566
virtual void finalize() { gQueue->waitOnHost(); }

examples/gpu-printing/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ using Slang::ComPtr;
1010
#include "gpu-printing.h"
1111
#include "platform/window.h"
1212
#include "slang-rhi.h"
13+
1314
#include <slang-rhi/shader-cursor.h>
1415

1516
using namespace rhi;
@@ -109,7 +110,8 @@ struct ExampleProgram : public TestBase
109110
BufferDesc printBufferDesc = {};
110111
printBufferDesc.size = printBufferSize;
111112
printBufferDesc.elementSize = sizeof(uint32_t);
112-
printBufferDesc.usage = BufferUsage::UnorderedAccess | BufferUsage::CopySource | BufferUsage::CopyDestination;
113+
printBufferDesc.usage =
114+
BufferUsage::UnorderedAccess | BufferUsage::CopySource | BufferUsage::CopyDestination;
113115
printBufferDesc.memoryType = MemoryType::DeviceLocal;
114116
auto printBuffer = gDevice->createBuffer(printBufferDesc);
115117

@@ -119,9 +121,9 @@ struct ExampleProgram : public TestBase
119121
auto rootShaderObject = computeEncoder->bindPipeline(gPipelineState);
120122
auto cursor = ShaderCursor(rootShaderObject);
121123
cursor["gPrintBuffer"].setBinding(printBuffer);
122-
124+
123125
computeEncoder->dispatchCompute(1, 1, 1);
124-
126+
125127
computeEncoder->end();
126128
queue->submit(commandEncoder->finish());
127129

examples/model-viewer/main.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
// and parameter binding.
2626
//
2727
#include "examples/example-base/example-base.h"
28-
#include <slang-rhi/shader-cursor.h>
2928
#include "platform/gui.h"
3029
#include "platform/model.h"
3130
#include "platform/vector-math.h"
3231
#include "platform/window.h"
3332
#include "slang-rhi.h"
3433

3534
#include <map>
35+
#include <slang-rhi/shader-cursor.h>
3636
#include <sstream>
3737

3838
using namespace rhi;
@@ -390,7 +390,10 @@ struct LightEnvLayout : public RefObject
390390
std::map<slang::TypeReflection*, SlangInt> mapLightTypeToArrayIndex;
391391
slang::TypeReflection* shaderType = nullptr;
392392

393-
void addLightType(RendererContext* context, slang::TypeReflection* lightType, SlangInt maximumCount)
393+
void addLightType(
394+
RendererContext* context,
395+
slang::TypeReflection* lightType,
396+
SlangInt maximumCount)
394397
{
395398
SlangInt arrayIndex = (SlangInt)lightArrayLayouts.size();
396399
LightArrayLayout layout;
@@ -898,9 +901,11 @@ struct ModelViewer : WindowedAppBase
898901
auto renderEncoder = drawCommandEncoder->beginRenderPass(renderPass);
899902

900903
RenderState renderState = {};
901-
renderState.viewports[0] = Viewport::fromSize((float)clientRect.width, (float)clientRect.height);
904+
renderState.viewports[0] =
905+
Viewport::fromSize((float)clientRect.width, (float)clientRect.height);
902906
renderState.viewportCount = 1;
903-
renderState.scissorRects[0] = ScissorRect::fromSize((float)clientRect.width, (float)clientRect.height);
907+
renderState.scissorRects[0] =
908+
ScissorRect::fromSize((float)clientRect.width, (float)clientRect.height);
904909
renderState.scissorRectCount = 1;
905910

906911
// We are only rendering one view, so we can fill in a per-view
@@ -949,11 +954,12 @@ struct ModelViewer : WindowedAppBase
949954
for (auto& mesh : model->meshes)
950955
{
951956
// Set the pipeline and binding state for drawing each mesh.
952-
auto rootObject = renderEncoder->bindPipeline(static_cast<IRenderPipeline*>(gPipelineState.get()));
953-
957+
auto rootObject = renderEncoder->bindPipeline(
958+
static_cast<IRenderPipeline*>(gPipelineState.get()));
959+
954960
// Apply render state
955961
renderEncoder->setRenderState(renderState);
956-
962+
957963
ShaderCursor rootCursor(rootObject);
958964
rootCursor["gViewParams"].setObject(viewShaderObject);
959965
rootCursor["gModelParams"].setObject(modelShaderObject);
@@ -975,7 +981,8 @@ struct ModelViewer : WindowedAppBase
975981
// All the shader parameters and pipeline states have been set up,
976982
// we can now issue a draw call for the mesh.
977983
DrawArguments drawArgs = {};
978-
// `drawArgs.vertexCount` is actually `indexCount` for the `DrawIndexed` Graphics API
984+
// `drawArgs.vertexCount` is actually `indexCount` for the `DrawIndexed` Graphics
985+
// API
979986
drawArgs.vertexCount = mesh->indexCount;
980987
drawArgs.startIndexLocation = mesh->firstIndex;
981988
renderEncoder->drawIndexed(drawArgs);

0 commit comments

Comments
 (0)