Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions core/nvrhi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,17 @@ export namespace nvrhi {
// render state. Its RefCountPtrs hold no reference, as in computePipelineDesc.
export function graphicsPipelineDesc(inputLayout: IInputLayout | null, vertexShader: IShader, pixelShader: IShader,
bindingLayout: IBindingLayout | null, state: RenderState): GraphicsPipelineDesc {
// (`bindingLayout ? 1 : 0` as the count fails to compile: TSLANG_ISSUES.md #14)
let layouts: index = 0;
if (bindingLayout) {
layouts = 1;
}

return [3, 0, [inputLayout], [vertexShader], [null], [null], [null], [pixelShader], state, [false, 0, 0, 0],
[[[bindingLayout], [null], [null], [null], [null], [null], [null], [null]], layouts], 0];
[[[bindingLayout], [null], [null], [null], [null], [null], [null], [null]], bindingLayout ? 1 : 0], 0];
}

// IDevice::createGraphicsPipeline for the framebuffer's formats; null on failure. Release() it.
export function createGraphicsPipeline(device: IDevice, desc: GraphicsPipelineDesc, framebuffer: IFramebuffer): IGraphicsPipeline | null {
let descValue = desc;
const handle = device.createGraphicsPipeline_2(Ref(descValue), framebuffer);
// (passed as the overload's `IFramebuffer | null`: an IFramebuffer fits no overload,
// TSLANG_ISSUES.md #19)
const framebufferArg: IFramebuffer | null = framebuffer;
const handle = device.createGraphicsPipeline(Ref(descValue), framebufferArg);
return handle.ptr_ ? <IGraphicsPipeline><Opaque>handle.ptr_ : null;
}

Expand All @@ -261,15 +258,6 @@ export namespace nvrhi {
const scissor: Rect = [<s32>Math.floor(viewport.minX), <s32>Math.ceil(viewport.maxX),
<s32>Math.floor(viewport.minY), <s32>Math.ceil(viewport.maxY)];
const noBuffer: VertexBufferBinding = [null, 0, 0];
// (counts from `x ? 1 : 0` fail to compile: TSLANG_ISSUES.md #14)
let bindingSets: index = 0;
if (bindingSet) {
bindingSets = 1;
}
let vertexBuffers: index = 0;
if (vertexBuffer) {
vertexBuffers = 1;
}
const vertexBinding: VertexBufferBinding = [vertexBuffer, 0, 0];

return [pipeline, framebuffer,
Expand All @@ -278,9 +266,9 @@ export namespace nvrhi {
[[scissor, noRect, noRect, noRect, noRect, noRect, noRect, noRect,
noRect, noRect, noRect, noRect, noRect, noRect, noRect, noRect], 1]],
[false, 0, 0, 0], [0, 0, 0, 0], 0, 0, 1,
[[bindingSet, null, null, null, null, null, null, null], bindingSets],
[[bindingSet, null, null, null, null, null, null, null], bindingSet ? 1 : 0],
[[vertexBinding, noBuffer, noBuffer, noBuffer, noBuffer, noBuffer, noBuffer, noBuffer,
noBuffer, noBuffer, noBuffer, noBuffer, noBuffer, noBuffer, noBuffer, noBuffer], vertexBuffers],
noBuffer, noBuffer, noBuffer, noBuffer, noBuffer, noBuffer, noBuffer, noBuffer], vertexBuffer ? 1 : 0],
[indexBuffer, <u8>indexFormat, 0], null, null];
}

Expand Down
8 changes: 3 additions & 5 deletions core/nvrhi_abi.linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ export namespace nvrhi {
}
}

// byte 0 is the size times two, byte k + 1 character k. (`shift *= 256` would multiply in
// 32 bits, losing the characters from the fourth on: TSLANG_ISSUES.md #15)
const BYTE: u64 = 256;
// byte 0 is the size times two, byte k + 1 character k
let word0: u64 = size * 2;
let word1: u64 = 0;
let word2: u64 = 0;
let shift: u64 = BYTE;
let shift: u64 = 256;
for (let i = 0; i < size; i++) {
const byte = i + 1;
if (byte == 8 || byte == 16) {
Expand All @@ -46,7 +44,7 @@ export namespace nvrhi {
} else {
word2 += char * shift;
}
shift *= BYTE;
shift *= 256;
}

return [[word0, word1, word2]];
Expand Down
5 changes: 1 addition & 4 deletions core/nvrhi_abi.win32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ export namespace nvrhi {
}
}

// (`shift *= 256` would multiply in 32 bits, losing the characters from the fifth on:
// TSLANG_ISSUES.md #15)
const BYTE: u64 = 256;
let buffer0: u64 = 0;
let buffer1: u64 = 0;
let shift: u64 = 1;
Expand All @@ -43,7 +40,7 @@ export namespace nvrhi {
} else {
buffer1 += char * shift;
}
shift *= BYTE;
shift *= 256;
}

return [[[[buffer0, buffer1], size, 15]]];
Expand Down
8 changes: 4 additions & 4 deletions core/nvrhi_classes.linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,13 @@ export namespace nvrhi {
@cppnontrivial
@slot(42) createGraphicsPipeline(desc: Ref<GraphicsPipelineDesc>, fbinfo: Ref<FramebufferInfo>): RefCountPtr<Opaque>;
@cppnontrivial
@slot(43) createGraphicsPipeline_2(desc: Ref<GraphicsPipelineDesc>, fb: IFramebuffer | null): RefCountPtr<Opaque>;
@slot(43) createGraphicsPipeline(desc: Ref<GraphicsPipelineDesc>, fb: IFramebuffer | null): RefCountPtr<Opaque>;
@cppnontrivial
@slot(44) createComputePipeline(desc: Ref<ComputePipelineDesc>): RefCountPtr<Opaque>;
@cppnontrivial
@slot(45) createMeshletPipeline(desc: Ref<MeshletPipelineDesc>, fbinfo: Ref<FramebufferInfo>): RefCountPtr<Opaque>;
@cppnontrivial
@slot(46) createMeshletPipeline_2(desc: Ref<MeshletPipelineDesc>, fb: IFramebuffer | null): RefCountPtr<Opaque>;
@slot(46) createMeshletPipeline(desc: Ref<MeshletPipelineDesc>, fb: IFramebuffer | null): RefCountPtr<Opaque>;
@cppnontrivial
@slot(47) createRayTracingPipeline(desc: Ref<PipelineDesc>): RefCountPtr<Opaque>;
@cppnontrivial
Expand Down Expand Up @@ -331,8 +331,8 @@ export namespace nvrhi {
// skipped: clearDepthStencilTexture — parameter 'subresources': struct passed by value
// skipped: clearTextureUInt — parameter 'subresources': struct passed by value
@slot(13) copyTexture(dest: ITexture | null, destSlice: Ref<TextureSlice>, src: ITexture | null, srcSlice: Ref<TextureSlice>): void;
@slot(14) copyTexture_2(dest: IStagingTexture | null, destSlice: Ref<TextureSlice>, src: ITexture | null, srcSlice: Ref<TextureSlice>): void;
@slot(15) copyTexture_3(dest: ITexture | null, destSlice: Ref<TextureSlice>, src: IStagingTexture | null, srcSlice: Ref<TextureSlice>): void;
@slot(14) copyTexture(dest: IStagingTexture | null, destSlice: Ref<TextureSlice>, src: ITexture | null, srcSlice: Ref<TextureSlice>): void;
@slot(15) copyTexture(dest: ITexture | null, destSlice: Ref<TextureSlice>, src: IStagingTexture | null, srcSlice: Ref<TextureSlice>): void;
@slot(16) writeTexture(dest: ITexture | null, arraySlice: u32, mipLevel: u32, data: Opaque | null, rowPitch: index, depthPitch: index): void;
@slot(17) resolveTexture(dest: ITexture | null, dstSubresources: Ref<TextureSubresourceSet>, src: ITexture | null, srcSubresources: Ref<TextureSubresourceSet>): void;
@slot(18) writeBuffer(b: IBuffer | null, data: Opaque | null, dataSize: index, destOffsetBytes: u64): void;
Expand Down
8 changes: 4 additions & 4 deletions core/nvrhi_classes.win32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,13 @@ export namespace nvrhi {
@cppnontrivial
@slot(42) createGraphicsPipeline(desc: Ref<GraphicsPipelineDesc>, fbinfo: Ref<FramebufferInfo>): RefCountPtr<Opaque>;
@cppnontrivial
@slot(41) createGraphicsPipeline_2(desc: Ref<GraphicsPipelineDesc>, fb: IFramebuffer | null): RefCountPtr<Opaque>;
@slot(41) createGraphicsPipeline(desc: Ref<GraphicsPipelineDesc>, fb: IFramebuffer | null): RefCountPtr<Opaque>;
@cppnontrivial
@slot(43) createComputePipeline(desc: Ref<ComputePipelineDesc>): RefCountPtr<Opaque>;
@cppnontrivial
@slot(45) createMeshletPipeline(desc: Ref<MeshletPipelineDesc>, fbinfo: Ref<FramebufferInfo>): RefCountPtr<Opaque>;
@cppnontrivial
@slot(44) createMeshletPipeline_2(desc: Ref<MeshletPipelineDesc>, fb: IFramebuffer | null): RefCountPtr<Opaque>;
@slot(44) createMeshletPipeline(desc: Ref<MeshletPipelineDesc>, fb: IFramebuffer | null): RefCountPtr<Opaque>;
@cppnontrivial
@slot(46) createRayTracingPipeline(desc: Ref<PipelineDesc>): RefCountPtr<Opaque>;
@cppnontrivial
Expand Down Expand Up @@ -333,8 +333,8 @@ export namespace nvrhi {
// skipped: clearDepthStencilTexture — parameter 'subresources': struct passed by value
// skipped: clearTextureUInt — parameter 'subresources': struct passed by value
@slot(14) copyTexture(dest: ITexture | null, destSlice: Ref<TextureSlice>, src: ITexture | null, srcSlice: Ref<TextureSlice>): void;
@slot(13) copyTexture_2(dest: IStagingTexture | null, destSlice: Ref<TextureSlice>, src: ITexture | null, srcSlice: Ref<TextureSlice>): void;
@slot(12) copyTexture_3(dest: ITexture | null, destSlice: Ref<TextureSlice>, src: IStagingTexture | null, srcSlice: Ref<TextureSlice>): void;
@slot(13) copyTexture(dest: IStagingTexture | null, destSlice: Ref<TextureSlice>, src: ITexture | null, srcSlice: Ref<TextureSlice>): void;
@slot(12) copyTexture(dest: ITexture | null, destSlice: Ref<TextureSlice>, src: IStagingTexture | null, srcSlice: Ref<TextureSlice>): void;
@slot(15) writeTexture(dest: ITexture | null, arraySlice: u32, mipLevel: u32, data: Opaque | null, rowPitch: index, depthPitch: index): void;
@slot(16) resolveTexture(dest: ITexture | null, dstSubresources: Ref<TextureSubresourceSet>, src: ITexture | null, srcSubresources: Ref<TextureSubresourceSet>): void;
@slot(17) writeBuffer(b: IBuffer | null, data: Opaque | null, dataSize: index, destOffsetBytes: u64): void;
Expand Down
13 changes: 6 additions & 7 deletions examples/nvrhi_direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,10 @@ namespace NvrhiDirect {
check(false, "IDevice::createTexture");
return;
}
// (named so as not to hide nvrhi.textureDesc below: TSLANG_ISSUES.md #18)
const keptTextureDesc = Deref(texture.getDesc());
check(keptTextureDesc.width == TEXTURE_SIZE && keptTextureDesc.height == TEXTURE_SIZE
&& keptTextureDesc.format == <u8>Format.RGBA8_UNORM && keptTextureDesc.isRenderTarget
&& nvrhi.stdStringIs(keptTextureDesc.debugName, "Cleared texture"), "ITexture::getDesc");
const textureDesc = Deref(texture.getDesc());
check(textureDesc.width == TEXTURE_SIZE && textureDesc.height == TEXTURE_SIZE
&& textureDesc.format == <u8>Format.RGBA8_UNORM && textureDesc.isRenderTarget
&& nvrhi.stdStringIs(textureDesc.debugName, "Cleared texture"), "ITexture::getDesc");
check(nvrhi.getNativeObject(texture, isD3D12 ? nvrhi.OBJECT_TYPE_D3D12_RESOURCE : nvrhi.OBJECT_TYPE_VK_IMAGE) != null,
"the texture has its native resource");

Expand Down Expand Up @@ -224,9 +223,9 @@ namespace NvrhiDirect {
return;
}
const layoutDesc = Deref(bindingLayout.getDesc());
check(layoutDesc.visibility == nvrhi.SHADER_TYPE_COMPUTE && nvrhi.stdVectorSize<nvrhi.BindingLayoutItem>(layoutDesc.bindings) == 2,
check(layoutDesc.visibility == nvrhi.SHADER_TYPE_COMPUTE && nvrhi.stdVectorSize(layoutDesc.bindings) == 2,
"IBindingLayout::getDesc");
check(nvrhi.stdVectorSize<nvrhi.BindingSetItem>(Deref(bindingSet.getDesc()).bindings) == 2, "IBindingSet::getDesc");
check(nvrhi.stdVectorSize(Deref(bindingSet.getDesc()).bindings) == 2, "IBindingSet::getDesc");
check(<index><Opaque>bindingSet.getLayout() == <index><Opaque>bindingLayout, "IBindingSet::getLayout");
const pipeline = nvrhi.createComputePipeline(device, nvrhi.computePipelineDesc(shader, bindingLayout));
if (!pipeline) {
Expand Down