36
36
#include " gfx/d3d11/render-d3d11.h"
37
37
#include " tools/graphics-app-framework/window.h"
38
38
#include " slang-com-ptr.h"
39
+ #include " source/core/slang-basic.h"
39
40
40
41
using namespace gfx ;
42
+ using namespace Slang ;
41
43
42
44
// For the purposes of a small example, we will define the vertex data for a
43
45
// single triangle directly in the source file. It should be easy to extend
@@ -72,7 +74,7 @@ struct HelloWorld
72
74
// Slang API. This function is representative of code that a user
73
75
// might write to integrate Slang into their renderer/engine.
74
76
//
75
- RefPtr <gfx::ShaderProgram > loadShaderProgram (gfx::IRenderer* renderer)
77
+ ComPtr <gfx::IShaderProgram > loadShaderProgram (gfx::IRenderer* renderer)
76
78
{
77
79
// First, we need to create a "session" for interacting with the Slang
78
80
// compiler. This scopes all of our application's interactions
@@ -183,13 +185,13 @@ RefPtr<gfx::ShaderProgram> loadShaderProgram(gfx::IRenderer* renderer)
183
185
// Reminder: this section does not involve the Slang API at all.
184
186
//
185
187
186
- gfx::ShaderProgram ::KernelDesc kernelDescs[] =
188
+ gfx::IShaderProgram ::KernelDesc kernelDescs[] =
187
189
{
188
190
{ gfx::StageType::Vertex, vertexCode, vertexCodeEnd },
189
191
{ gfx::StageType::Fragment, fragmentCode, fragmentCodeEnd },
190
192
};
191
193
192
- gfx::ShaderProgram ::Desc programDesc;
194
+ gfx::IShaderProgram ::Desc programDesc;
193
195
programDesc.pipelineType = gfx::PipelineType::Graphics;
194
196
programDesc.kernels = &kernelDescs[0 ];
195
197
programDesc.kernelCount = 2 ;
@@ -230,19 +232,19 @@ int gWindowHeight = 768;
230
232
gfx::ApplicationContext* gAppContext ;
231
233
gfx::Window* gWindow ;
232
234
Slang::ComPtr<gfx::IRenderer> gRenderer ;
233
- RefPtr <gfx::BufferResource > gConstantBuffer ;
235
+ ComPtr <gfx::IBufferResource > gConstantBuffer ;
234
236
235
- RefPtr <gfx::PipelineLayout > gPipelineLayout ;
236
- RefPtr <gfx::PipelineState> gPipelineState ;
237
- RefPtr <gfx::DescriptorSet> gDescriptorSet ;
237
+ ComPtr <gfx::IPipelineLayout > gPipelineLayout ;
238
+ ComPtr <gfx::IPipelineState> gPipelineState ;
239
+ ComPtr <gfx::IDescriptorSet> gDescriptorSet ;
238
240
239
- RefPtr <gfx::BufferResource > gVertexBuffer ;
241
+ ComPtr <gfx::IBufferResource > gVertexBuffer ;
240
242
241
243
// Now that we've covered the function that actually loads and
242
244
// compiles our Slang shade code, we can go through the rest
243
245
// of the application code without as much commentary.
244
246
//
245
- Result initialize ()
247
+ Slang:: Result initialize ()
246
248
{
247
249
// Create a window for our application to render into.
248
250
//
@@ -264,7 +266,7 @@ Result initialize()
264
266
rendererDesc.width = gWindowWidth ;
265
267
rendererDesc.height = gWindowHeight ;
266
268
{
267
- Result res = gRenderer ->initialize (rendererDesc, getPlatformWindowHandle (gWindow ));
269
+ gfx:: Result res = gRenderer ->initialize (rendererDesc, getPlatformWindowHandle (gWindow ));
268
270
if (SLANG_FAILED (res)) return res;
269
271
}
270
272
@@ -278,13 +280,13 @@ Result initialize()
278
280
//
279
281
int constantBufferSize = 16 * sizeof (float );
280
282
281
- BufferResource ::Desc constantBufferDesc;
283
+ IBufferResource ::Desc constantBufferDesc;
282
284
constantBufferDesc.init (constantBufferSize);
283
- constantBufferDesc.setDefaults (Resource ::Usage::ConstantBuffer);
284
- constantBufferDesc.cpuAccessFlags = Resource ::AccessFlag::Write;
285
+ constantBufferDesc.setDefaults (IResource ::Usage::ConstantBuffer);
286
+ constantBufferDesc.cpuAccessFlags = IResource ::AccessFlag::Write;
285
287
286
288
gConstantBuffer = gRenderer ->createBufferResource (
287
- Resource ::Usage::ConstantBuffer,
289
+ IResource ::Usage::ConstantBuffer,
288
290
constantBufferDesc);
289
291
if (!gConstantBuffer ) return SLANG_FAIL;
290
292
@@ -305,19 +307,19 @@ Result initialize()
305
307
// Next we allocate a vertex buffer for our pre-initialized
306
308
// vertex data.
307
309
//
308
- BufferResource ::Desc vertexBufferDesc;
310
+ IBufferResource ::Desc vertexBufferDesc;
309
311
vertexBufferDesc.init (kVertexCount * sizeof (Vertex));
310
- vertexBufferDesc.setDefaults (Resource ::Usage::VertexBuffer);
312
+ vertexBufferDesc.setDefaults (IResource ::Usage::VertexBuffer);
311
313
gVertexBuffer = gRenderer ->createBufferResource (
312
- Resource ::Usage::VertexBuffer,
314
+ IResource ::Usage::VertexBuffer,
313
315
vertexBufferDesc,
314
316
&kVertexData [0 ]);
315
317
if (!gVertexBuffer ) return SLANG_FAIL;
316
318
317
319
// Now we will use our `loadShaderProgram` function to load
318
320
// the code from `shaders.slang` into the graphics API.
319
321
//
320
- RefPtr<ShaderProgram > shaderProgram = loadShaderProgram (gRenderer );
322
+ ComPtr<IShaderProgram > shaderProgram = loadShaderProgram (gRenderer );
321
323
if (!shaderProgram) return SLANG_FAIL;
322
324
323
325
// Our example graphics API usess a "modern" D3D12/Vulkan style
@@ -326,11 +328,11 @@ Result initialize()
326
328
//
327
329
// First, we need to construct a descriptor set *layout*.
328
330
//
329
- DescriptorSetLayout ::SlotRangeDesc slotRanges[] =
331
+ IDescriptorSetLayout ::SlotRangeDesc slotRanges[] =
330
332
{
331
- DescriptorSetLayout ::SlotRangeDesc (DescriptorSlotType::UniformBuffer),
333
+ IDescriptorSetLayout ::SlotRangeDesc (DescriptorSlotType::UniformBuffer),
332
334
};
333
- DescriptorSetLayout ::Desc descriptorSetLayoutDesc;
335
+ IDescriptorSetLayout ::Desc descriptorSetLayoutDesc;
334
336
descriptorSetLayoutDesc.slotRangeCount = 1 ;
335
337
descriptorSetLayoutDesc.slotRanges = &slotRanges[0 ];
336
338
auto descriptorSetLayout = gRenderer ->createDescriptorSetLayout (descriptorSetLayoutDesc);
@@ -340,11 +342,11 @@ Result initialize()
340
342
// that we will render with only a single descriptor set bound.
341
343
//
342
344
343
- PipelineLayout ::DescriptorSetDesc descriptorSets[] =
345
+ IPipelineLayout ::DescriptorSetDesc descriptorSets[] =
344
346
{
345
- PipelineLayout ::DescriptorSetDesc ( descriptorSetLayout ),
347
+ IPipelineLayout ::DescriptorSetDesc ( descriptorSetLayout ),
346
348
};
347
- PipelineLayout ::Desc pipelineLayoutDesc;
349
+ IPipelineLayout ::Desc pipelineLayoutDesc;
348
350
pipelineLayoutDesc.renderTargetCount = 1 ;
349
351
pipelineLayoutDesc.descriptorSetCount = 1 ;
350
352
pipelineLayoutDesc.descriptorSets = &descriptorSets[0 ];
0 commit comments