@@ -191,6 +191,7 @@ class CPUTextureResource : public TextureResource
191
191
{}
192
192
~CPUTextureResource ()
193
193
{
194
+ free (m_data);
194
195
}
195
196
196
197
Result init (ITextureResource::SubresourceData const * initData)
@@ -341,7 +342,7 @@ class CPUTextureResource : public TextureResource
341
342
void * m_data = nullptr ;
342
343
};
343
344
344
- class CPUResourceView : public IResourceView , public RefObject
345
+ class CPUResourceView : public IResourceView , public ComObject
345
346
{
346
347
public:
347
348
enum class Kind
@@ -350,7 +351,7 @@ class CPUResourceView : public IResourceView, public RefObject
350
351
Texture,
351
352
};
352
353
353
- SLANG_REF_OBJECT_IUNKNOWN_ALL
354
+ SLANG_COM_OBJECT_IUNKNOWN_ALL
354
355
IResourceView* getInterface (const Guid& guid)
355
356
{
356
357
if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_IResourceView)
@@ -799,9 +800,9 @@ class CPUShaderObject : public ShaderObjectBase
799
800
800
801
auto & bindingRange = layout->m_bindingRanges [bindingRangeIndex];
801
802
auto subObjectIndex = bindingRange.baseIndex + offset.bindingArrayIndex ;
802
- CPUShaderObject* subObject = m_objects[subObjectIndex];
803
+ auto & subObject = m_objects[subObjectIndex];
803
804
804
- * outObject = ComPtr<IShaderObject>( subObject). detach ( );
805
+ returnComPtr ( outObject, subObject);
805
806
806
807
return SLANG_OK;
807
808
}
@@ -1043,6 +1044,12 @@ class CPUEntryPointShaderObject : public CPUShaderObject
1043
1044
1044
1045
class CPURootShaderObject : public CPUShaderObject
1045
1046
{
1047
+ public:
1048
+ // Override default reference counting behavior to disable lifetime management via ComPtr.
1049
+ // Root objects are managed by command buffer and does not need to be freed by the user.
1050
+ SLANG_NO_THROW uint32_t SLANG_MCALL addRef () override { return 1 ; }
1051
+ SLANG_NO_THROW uint32_t SLANG_MCALL release () override { return 1 ; }
1052
+
1046
1053
public:
1047
1054
SlangResult init (IDevice* device, CPUProgramLayout* programLayout);
1048
1055
@@ -1056,7 +1063,7 @@ class CPURootShaderObject : public CPUShaderObject
1056
1063
virtual SLANG_NO_THROW Result SLANG_MCALL
1057
1064
getEntryPoint (UInt index, IShaderObject** outEntryPoint) override
1058
1065
{
1059
- * outEntryPoint = ComPtr<IShaderObject>( m_entryPoints[index ]). detach ( );
1066
+ returnComPtr ( outEntryPoint, m_entryPoints[index ]);
1060
1067
return SLANG_OK;
1061
1068
}
1062
1069
virtual Result collectSpecializationArgs (ExtendedShaderObjectTypeList& args) override
@@ -1083,7 +1090,7 @@ class CPUShaderProgram : public ShaderProgramBase
1083
1090
class CPUPipelineState : public PipelineStateBase
1084
1091
{
1085
1092
public:
1086
- CPUShaderProgram* getProgram () { return static_cast <CPUShaderProgram*>(m_program.get ()); }
1093
+ CPUShaderProgram* getProgram () { return static_cast <CPUShaderProgram*>(m_program.Ptr ()); }
1087
1094
1088
1095
void init (const ComputePipelineStateDesc& inDesc)
1089
1096
{
@@ -1194,11 +1201,14 @@ class CPUDevice : public ImmediateComputeDeviceBase
1194
1201
const ITextureResource::SubresourceData* initData,
1195
1202
ITextureResource** outResource) override
1196
1203
{
1197
- RefPtr<CPUTextureResource> texture = new CPUTextureResource (desc);
1204
+ TextureResource::Desc srcDesc (desc);
1205
+ srcDesc.setDefaults (initialUsage);
1206
+
1207
+ RefPtr<CPUTextureResource> texture = new CPUTextureResource (srcDesc);
1198
1208
1199
1209
SLANG_RETURN_ON_FAIL (texture->init (initData));
1200
1210
1201
- * outResource = texture. detach ( );
1211
+ returnComPtr ( outResource, texture);
1202
1212
return SLANG_OK;
1203
1213
}
1204
1214
@@ -1214,7 +1224,7 @@ class CPUDevice : public ImmediateComputeDeviceBase
1214
1224
{
1215
1225
SLANG_RETURN_ON_FAIL (resource->setData (0 , desc.sizeInBytes , initData));
1216
1226
}
1217
- * outResource = resource. detach ( );
1227
+ returnComPtr ( outResource, resource);
1218
1228
return SLANG_OK;
1219
1229
}
1220
1230
@@ -1223,7 +1233,7 @@ class CPUDevice : public ImmediateComputeDeviceBase
1223
1233
{
1224
1234
auto texture = static_cast <CPUTextureResource*>(inTexture);
1225
1235
RefPtr<CPUTextureView> view = new CPUTextureView (desc, texture);
1226
- * outView = view. detach ( );
1236
+ returnComPtr ( outView, view);
1227
1237
return SLANG_OK;
1228
1238
}
1229
1239
@@ -1232,7 +1242,7 @@ class CPUDevice : public ImmediateComputeDeviceBase
1232
1242
{
1233
1243
auto buffer = static_cast <CPUBufferResource*>(inBuffer);
1234
1244
RefPtr<CPUBufferView> view = new CPUBufferView (desc, buffer);
1235
- * outView = view. detach ( );
1245
+ returnComPtr ( outView, view);
1236
1246
return SLANG_OK;
1237
1247
}
1238
1248
@@ -1241,7 +1251,7 @@ class CPUDevice : public ImmediateComputeDeviceBase
1241
1251
ShaderObjectLayoutBase** outLayout) override
1242
1252
{
1243
1253
RefPtr<CPUShaderObjectLayout> cpuLayout = new CPUShaderObjectLayout (this , typeLayout);
1244
- * outLayout = cpuLayout. detach ( );
1254
+ returnRefPtrMove ( outLayout, cpuLayout);
1245
1255
1246
1256
return SLANG_OK;
1247
1257
}
@@ -1254,19 +1264,19 @@ class CPUDevice : public ImmediateComputeDeviceBase
1254
1264
1255
1265
RefPtr<CPUShaderObject> result = new CPUShaderObject ();
1256
1266
SLANG_RETURN_ON_FAIL (result->init (this , cpuLayout));
1257
- * outObject = result. detach ( );
1267
+ returnComPtr ( outObject, result);
1258
1268
1259
1269
return SLANG_OK;
1260
1270
}
1261
1271
1262
- virtual Result createRootShaderObject (IShaderProgram* program, IShaderObject ** outObject) override
1272
+ virtual Result createRootShaderObject (IShaderProgram* program, ShaderObjectBase ** outObject) override
1263
1273
{
1264
1274
auto cpuProgram = static_cast <CPUShaderProgram*>(program);
1265
1275
auto cpuProgramLayout = cpuProgram->layout ;
1266
1276
1267
1277
RefPtr<CPURootShaderObject> result = new CPURootShaderObject ();
1268
1278
SLANG_RETURN_ON_FAIL (result->init (this , cpuProgramLayout));
1269
- * outObject = result. detach ( );
1279
+ returnRefPtrMove ( outObject, result);
1270
1280
return SLANG_OK;
1271
1281
}
1272
1282
@@ -1292,7 +1302,7 @@ class CPUDevice : public ImmediateComputeDeviceBase
1292
1302
cpuProgram->layout = cpuProgramLayout;
1293
1303
}
1294
1304
1295
- * outProgram = cpuProgram. detach ( );
1305
+ returnComPtr ( outProgram, cpuProgram);
1296
1306
return SLANG_OK;
1297
1307
}
1298
1308
@@ -1301,7 +1311,7 @@ class CPUDevice : public ImmediateComputeDeviceBase
1301
1311
{
1302
1312
RefPtr<CPUPipelineState> state = new CPUPipelineState ();
1303
1313
state->init (desc);
1304
- * outState = state. detach ( );
1314
+ returnComPtr ( outState, state);
1305
1315
return Result ();
1306
1316
}
1307
1317
@@ -1410,7 +1420,7 @@ SlangResult SLANG_MCALL createCPUDevice(const IDevice::Desc* desc, IDevice** out
1410
1420
{
1411
1421
RefPtr<CPUDevice> result = new CPUDevice ();
1412
1422
SLANG_RETURN_ON_FAIL (result->initialize (*desc));
1413
- * outDevice = result. detach ( );
1423
+ returnComPtr ( outDevice, result);
1414
1424
return SLANG_OK;
1415
1425
}
1416
1426
0 commit comments