Skip to content

Commit cc6184e

Browse files
committed
Work in-progress: simple compute test passed. (d3d renderer)
1 parent 0c8efd1 commit cc6184e

File tree

10 files changed

+541
-106
lines changed

10 files changed

+541
-106
lines changed

source/slang/type-defs.h

-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ SYNTAX_CLASS(GroupSharedType, Type)
318318
RAW(
319319
virtual ~GroupSharedType()
320320
{
321-
int f = 0;
322321
}
323322

324323
virtual Slang::String ToString() override;

tests/compute/simple.slang

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//TEST(smoke,compute):COMPARE_COMPUTE:
2-
2+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
33
// This is a basic test for Slang compute shader.
44

55
RWStructuredBuffer<float> outputBuffer;
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
0.0
2-
1.0
3-
2.0
4-
3.0
1+
0
2+
3F800000
3+
40000000
4+
40400000

tools/render-test/main.cpp

+5-30
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ uintptr_t gConstantBufferSize, gComputeResultBufferSize;
5454
Buffer* gConstantBuffer;
5555
InputLayout* gInputLayout;
5656
Buffer* gVertexBuffer;
57-
Buffer* gComputeResultBuffer;
5857
ShaderProgram* gShaderProgram;
5958
BindingState* gBindingState;
6059
ShaderInputLayout gShaderInputLayout;
@@ -125,16 +124,6 @@ Error initializeShaders(
125124

126125
return Error::None;
127126
}
128-
129-
void outputComputeResult(Renderer* renderer, const char * fileName)
130-
{
131-
float* data = (float*)renderer->map(gComputeResultBuffer, MapFlavor::HostRead);
132-
FILE* f = fopen(fileName, "wt");
133-
for (auto i = 0u; i < gComputeResultBufferSize / sizeof(UInt); i++)
134-
fprintf(f, "%.9g\n", data[i]);
135-
fclose(f);
136-
}
137-
138127
//
139128
// At initialization time, we are going to load and compile our Slang shader
140129
// code, and then create the D3D11 API objects we need for rendering.
@@ -162,20 +151,7 @@ Error initializeInner(
162151
gConstantBuffer = renderer->createBuffer(constantBufferDesc);
163152
if(!gConstantBuffer)
164153
return Error::Unexpected;
165-
166-
gComputeResultBufferSize = 512 * sizeof(float);
167-
BufferDesc computeResultBufferDesc;
168-
computeResultBufferDesc.size = gComputeResultBufferSize;
169-
computeResultBufferDesc.flavor = BufferFlavor::Storage;
170-
gComputeResultBuffer = renderer->createBuffer(computeResultBufferDesc);
171-
if (!gComputeResultBufferSize)
172-
return Error::Unexpected;
173-
// initialize buffer to 0
174-
char * ptr = (char*)renderer->map(gComputeResultBuffer, MapFlavor::HostWrite);
175-
for (auto i = 0u; i < gComputeResultBufferSize; i++)
176-
ptr[i] = 0;
177-
renderer->unmap(gComputeResultBuffer);
178-
154+
179155
// Input Assembler (IA)
180156

181157
InputElementDesc inputElements[] = {
@@ -236,7 +212,6 @@ void renderFrameInner(
236212
void runCompute(Renderer * renderer)
237213
{
238214
renderer->setShaderProgram(gShaderProgram);
239-
renderer->setStorageBuffer(0, gComputeResultBuffer);
240215
renderer->setBindingState(gBindingState);
241216
renderer->dispatchCompute(1, 1, 1);
242217
}
@@ -434,10 +409,10 @@ int main(
434409
// If we are in a mode where output is requested, we need to snapshot the back buffer here
435410
if (gOptions.outputPath)
436411
{
437-
if (gOptions.shaderType == ShaderProgramType::Compute)
438-
outputComputeResult(renderer, gOptions.outputPath);
439-
else
440-
renderer->captureScreenShot(gOptions.outputPath);
412+
if (gOptions.shaderType == ShaderProgramType::Compute)
413+
renderer->serializeOutput(gBindingState, gOptions.outputPath);
414+
else
415+
renderer->captureScreenShot(gOptions.outputPath);
441416
return 0;
442417
}
443418

0 commit comments

Comments
 (0)