Skip to content

Implement the printf HLSL Function #99140

Open
@farzonl

Description

@farzonl
  • Implement printf clang builtin,
    Link printf clang builtin with hlsl_intrinsics.h
    Add sema checks for printf to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
    Add codegen for printf to EmitHLSLBuiltinExpr in CGBuiltin.cpp
    Add codegen tests to clang/test/CodeGenHLSL/builtins/printf.hlsl
    Add sema tests to clang/test/SemaHLSL/BuiltIns/printf-errors.hlsl
    Create the int_spv_printf intrinsic in IntrinsicsSPIRV.td
    In SPIRVInstructionSelector.cpp create the printf lowering and map it to int_spv_printf in SPIRVInstructionSelector::selectIntrinsic.
    Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/printf.ll

DirectX

There is no support for printf when targeting DirectX.

SPIR-V

See "Using Debug Printf in HLSL Shaders" in https://vulkan.lunarg.com/doc/sdk/1.3.283.0/windows/debug_printf.html

Test Case(s)

Example 1

//dxc printf_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export void fn(string p1) {
    return printf(p1);
}

HLSL:

Submits a custom shader message to the information queue.

Syntax

void printf(
   string format,
    argument ...
);

Parameters

format

The format string.

argument ...

Optional arguments.

Return value

This function does not return a value.

Remarks

This operation does nothing on devices that do not support it.

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 4 (DirectX HLSL) or later. yes

 

See also

Intrinsic Functions

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    HLSLHLSL Language Supportbackend:SPIR-Vbot:HLSLmetaissueIssue to collect references to a group of similar or related issues.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Development

    No branches or pull requests

      Participants

      @farzonl

      Issue actions

        Implement the `printf` HLSL Function · Issue #99140 · llvm/llvm-project