Skip to content

Add initial support for extension intrinsics and defines - #5

Merged
David Peixotto (dmpots) merged 4 commits into
masterfrom
dmpots_ext
Jan 18, 2017
Merged

David Peixotto (dmpots) merged 4 commits into
masterfrom
dmpots_ext

Conversation

@dmpots

Copy link
Copy Markdown
Contributor

-Add support for recognizing hlsl extensions as new intrinsic functions.
-Add support for requesting lowering of extensions.
-Add support for preserving semantic defines.
-Add support for validating semantic defines.

This commit adds support for hlsl extensions in the form of additional
intrisic functions and semantic defines.

We now allow a dxcompiler instance to register that it can handle
additional intrinsic functions beyond the standard hlsl intrinsics. These
new intrinsics are called extensions. For each extension, the compiler
supplies a lowering strategy that is used by the dxcompiler to translate
from the source level intrinsic to a high-level dxil intrinsic.

We initially support the two lowering strategies: replicate and pack.
The replicate strategy will scalarize the vector elements in the call
and replicate the function call once for each element in the vector.
The pack strategy changes the vector arguments into literal struct
arguments.

We also now include support for "semantic defines". A semantic define is
a source level define whose value is preserved in the final dxil as
metatdata. The source level define can come as either a #define in
the hlsl source or a /D define from the command line.

We provide a hook to validate that a semantic define has a legal value
(for example to ensure that the value is an integer). Validation failures
can produce warnings and errors that will be emitted through the standard
clang diagnostic mechanism.

This code was originally written by marcelolr and modified by dmpots to
support packed lowering of intriniscs and validation of semantic defines.

-Add support for recognizing hlsl extensions as new intrinsic functions.
-Add support for requesting lowering of extensions.
-Add support for preserving semantic defines.
-Add support for validating semantic defines.

This commit adds support for hlsl extensions in the form of additional
intrisic functions and semantic defines.

We now allow a dxcompiler instance to register that it can handle
additional intrinsic functions beyond the standard hlsl intrinsics. These
new intrinsics are called extensions.  For each extension, the compiler
supplies a lowering strategy that is used by the dxcompiler to translate
from the source level intrinsic to a high-level dxil intrinsic.

We initially support the two lowering strategies: replicate and pack.
The replicate strategy will scalarize the vector elements in the call
and replicate the function call once for each element in the vector.
The pack strategy changes the vector arguments into literal struct
arguments.

We also now include support for "semantic defines". A semantic define is
a source level define whose value is preserved in the final dxil as
metatdata. The source level define can come as either a #define in
the hlsl source or a /D define from the command line.

We provide a hook to validate that a semantic define has a legal value
(for example to ensure that the value is an integer). Validation failures
can produce warnings and errors that will be emitted through the standard
clang diagnostic mechanism.

This code was originally written by marcelolr and modified by dmpots to
support packed lowering of intriniscs and validation of semantic defines.
@msftclas

Hi David Peixotto (@dmpots), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (David Peixotto). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

// Set the validator used to validate semantic defines.
// Only one validator stored and used to run validation.
HRESULT STDMETHODCALLTYPE SetSemanticDefineValidator(_In_ IDxcSemanticDefineValidator* pValidator) {
try {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block doesn't really need a try block, as all we do is an assignment. It can just error if pValidator is nullptr, otherwise assign.

}

HRESULT STDMETHODCALLTYPE SetSemanticDefineMetaDataName(LPCSTR name) {
m_semanticDefineMetaDataName = name;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one on the other hand does need a try block, because the std::string will throw with bad_alloc.

HRESULT result = m_semanticDefineValidator->GetSemanticDefineWarningsAndErrors(name.c_str(), value.c_str(), &pWarning, &pError);

if (FAILED(result)) {
// Hmmm... what to do?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably failing with a generic error message? Maybe format the HRESULT?

dxcsupport
hlsl
option
Analysis

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these additions are needed.

return S_OK;
}
};
void CheckOperationFailed(IDxcOperationResult *pResult) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static? or maybe share them out via a header in helpers. But I'd start with static. Same with the next function.

#include "dxc/dxcapi.internal.h"
#include "dxc/HLSL/HLOperationLowerExtension.h"

// LLVM include for custom lowering

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No custom lowering from outside dxcompiler.

    * add/remove try blocks
    * format message on failure to run validator
    * clean up link/include options for tests
    * make internal test functions static

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the lib references in the test cmake file, I think this is good to go.

hlsl
option
Analysis
Core

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other newly introduced dependencies aren't necessary either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I will fix that. Sorry I missed it earlier!

Forgot to remove them in an earlier patch.
@dmpots
David Peixotto (dmpots) merged commit 9451f2c into master Jan 18, 2017
@dmpots
David Peixotto (dmpots) deleted the dmpots_ext branch January 18, 2017 01:51
Xiang Li (python3kgae) added a commit that referenced this pull request Jan 20, 2017
Strip function parameter for entry and patch constant function

* Update error message for ValidationTest::MultiDimArray

* Merge remote-tracking branch 'origin/master'

# Conflicts:
#	lib/HLSL/DxilValidation.cpp
#	tools/clang/unittests/HLSL/ValidationTest.cpp

* Update error message for ValidationTest::MultiDimArray

Update error message for ValidationTest::MultiDimArray

* Fix merge error. (#3)

* Delete local file (#4)

* Fix merge error.

* Delete local file

* Strip function parameter for entry and patch constant function. (#5)
yurido1 pushed a commit to yurido1/DirectXShaderCompiler that referenced this pull request Feb 8, 2017
…icrosoft#5)

* Fix ValidateDxilBitcode PSV generation for Root Signature validation.
- also fix validation for empty patch constant signature.
* Test container and root signature validation.
* Fix DXASSERT when PC in/out patch sig mismatch HS.
Steven Perron (s-perron) added a commit that referenced this pull request Feb 24, 2026
…for `vk::SampledTexture2D` type. (#8098)

Part of #7979

Implement remaining sample methods methods for `vk::SampledTexture2D`:
```hlsl
float Object.SampleCmp(float Location, float CompareValue, [, int Offset], [, float Clamp] [, out uint Status]);
float Object.SampleCmpLevelZero(float Location, float CompareValue, [, int Offset], [, out uint Status]);
float Object.SampleCmpLevel(float Location, float CompareValue, float LOD, [, int Offset], [, out uint Status]);
float Object.SampleGrad(float Location, float DDX, float DDY, [, int Offset], [, float Clamp] [, out uint Status]);
float Object.SampleCompGrad(float Location, float CompareValue, float DDX, float DDY, [, int Offset], [, float Clamp] [, out uint Status]);
float Object.SampleCompBias(float Location, float CompareValue, float Bias, [, int Offset], [, float Clamp] [, out uint Status]);
PARAM_TYPE Object.SampleBias(float Location, float Bias, [, int Offset], [, float Clamp], [, out uint Status]);
PARAM_TYPE Object.SampleLevel(float Location, float LOD, [, int Offset], [, out uint Status]);
```

---------

Co-authored-by: Damyan Pepper <damyanp@microsoft.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Ashley Coleman <ascoleman@microsoft.com>
Co-authored-by: kpyzhov <konstantin.pyzhov@gmail.com>
Co-authored-by: Konstantin <konstantin.pyzhov@amd.com>
Co-authored-by: Steven Perron <stevenperron@google.com>
Co-authored-by: Alex Sepkowski <alexsepkowski@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants