-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Glsl.meta.slang raytracing #3560 #10
Glsl.meta.slang raytracing #3560 #10
Conversation
all functions part of ray_query, shader_invocation_reorder and ray_tracing_motion_blur are implemented for GLSL.meta. If HLSL lacks an implementation equal GLSL/SPIR-V was implemented without an HLSL equivalent in HLSL.meta (anticipation of HLSL equivalent function eventually); completed built in variables have only been stubbed thus far; NOT completed the following commit sets up formatting & tests for all ray_query functions (compute shader); completed the commit also sets up structure for compile testing glsl raytracing shaders; NOT completed
…L_EXT_ray_query, GLSL_NV_shader_invocation_reorder & GLSL_NV_ray_tracing_motion_blur Implement all functions & built-in variables (with tests) for the GLSL_EXT_ray_query, GLSL_NV_shader_invocation_reorder & GLSL_NV_ray_tracing_motion_blur glsl extension based on specification (https://github.com/KhronosGroup/GLSL/blob/main/extensions/nv/). implementation details of worth{ All functions with alternatives in GLSL->HLSL have been implemented in GLSL, HLSL & SPRI-V (hlsl implementation has a few errors); otherwise only GLSL & SPIR-V was implemented. * modified slang compiler to add support for query'ing and fetching raytracing payloads/attributes based on bound layout(location) and input a 'constexpr int'. This allows'dynamic typing' for these operations to late evaluate all location tied raytracing objects. An attribute to functions were also added to force setting a generic's type based on a payload object (this is also required to allow 'generic typed' raytracing object functions); all of the hacky generic forcing will be removed in next commit in regards to removing hlsl code GL_EXT_ray_tracing was NOT implemented and part of scope of this commit, they will be for the next commit This commit will be overrided with removing HLSL functions and logic. commit is happening just to keep code history } testing details of worth{ Raytracing shader (non compute, compute can test properly) tests only test compiling and opcodes due to testing system limitations }
…L_EXT_ray_tracing, GLSL_EXT_ray_query, GLSL_NV_shader_invocation_reorder & GLSL_NV_ray_tracing_motion_blur glsl extension based on specification (https://github.com/KhronosGroup/GLSL/blob/main/extensions/). implementation details of worth{ spirv required direct referencing of raytracing objects, as a result, __rayPayloadFromLocation, __rayAttributeFromLocation, and __rayCallableFromLocation, all take in a integer literal and use this to add a placeholder to fillin with an actual layout(location) bound object. layout(location) bound raytracing objects are never optimized out, this was intentionally added to the code. GL_EXT_ray_tracing was implemented as noted in the commit description. all HLSL support has been removed. } testing details of worth{ Raytracing shader tests only test compiling and opcodes due to testing system limitations (raygen, intersection, miss, anyhit cover all raytracing functions/builtins/syntax); Compute raytracing works with actual value testing }
change dictionary usage to be more correct syntax-wise compact and organize parser code to be more like other parser code (this structure is important since there will be many attributes along with layout() syntax later on) code style adjustments to match slang use of braces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me overall.
@@ -74,14 +76,14 @@ void rayGenerationMain() | |||
someValues); | |||
|
|||
uint r = calcValue(hit); | |||
// SPIRV: OpReorderThreadWithHitObjectNV |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this test removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I broke the tests during development; I forgot to add them back since I broke them at the start; I am adding them 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this file removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are not tests and go against the .gitignore; they don't do anything
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> | ||
bool equals(matrix<T, N, M> lhs, matrix<T, N, M> rhs) | ||
{ | ||
for (int i = 0; i < N; i++) | ||
{ | ||
for (int j = 0; j < M; j++) | ||
{ | ||
if ( | ||
lhs[i][j] | ||
!= | ||
rhs[i][j] | ||
) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we have a equality testing function already for Matrix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do not, other testing code also has an "equals" function for this purpose
source/slang/slang-ir.cpp
Outdated
else if (kIROp_SPIRVAsmOperandRayCallableFromLocation == op) | ||
{ | ||
varLayoutPointsTo = this->getRayCallableVariableFromLocation(intLitValue); | ||
} | ||
else | ||
{ | ||
// should be impossible to hit | ||
assert(false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be better with
else
{
SLANG_ASSERT(kIROp_SPIRVAsmOperandRayCallableFromLocation == op);
varLayoutPointsTo = this->getRayCallableVariableFromLocation(intLitValue);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some comments.
source/slang/hlsl.meta.slang
Outdated
//__target_intrinsic(glsl, RayDesc) | ||
//__target_intrinsic(spirv, RayDesc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you either uncomment these or remove?
source/slang/hlsl.meta.slang
Outdated
case _GL_EXT_ray_tracing: | ||
case glsl: __intrinsic_asm "reportIntersectionEXT"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change actually needed?
It seems like _GL_EXT_ray_tracing will cover all the GLSL target, doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glsl->_GL_EXT_ray_tracing does/did not seem to work, this is needed
I think its a superset->subset type of problem (_GL_EXT_ray_tracing -> glsl is fine, other way is not)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean you don't need to have "case _GL_EXT_ray_tracing" when you have "case glsl"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some code & tests enable/use the _GL_EXT_ray_tracing (hlsl->glsl) capability, I use glsl capability instead (but the code is identical since both are glsl)
source/slang/hlsl.meta.slang
Outdated
case glsl: | ||
case glsl: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks to be a mistake.
There should be only one "glsl" case.
source/slang/hlsl.meta.slang
Outdated
spirv_asm { | ||
result:$$float = OpHitObjectGetCurrentTimeNV &this | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this have "return"?
return spirv_asm { ... };
source/slang/slang-emit-spirv.cpp
Outdated
goto rayExtensionAddition; | ||
case kIROp_VulkanHitObjectAttributesDecoration: | ||
// needed since GLSL will not set optypes accordingly, but will keep the decoration | ||
ensureExtensionDeclaration(UnownedStringSlice("SPV_NV_shader_invocation_reorder")); | ||
requireSPIRVCapability(SpvCapabilityShaderInvocationReorderNV); | ||
goto rayExtensionAddition; | ||
case kIROp_VulkanRayPayloadDecoration: | ||
case kIROp_VulkanRayPayloadInDecoration: | ||
// needed since GLSL will not set optypes accordingly, but will keep the decoration | ||
ensureExtensionDeclaration(UnownedStringSlice("SPV_KHR_ray_query")); | ||
requireSPIRVCapability(SpvCapabilityRayQueryKHR); | ||
goto rayExtensionAddition; | ||
rayExtensionAddition:; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use GOTO within switch statement.
In this case, you can set a temporary variable to be true and handle the action later.
bool isRayExtension = false;
...
case kIROp_VulkanCallablePayloadInDecoration:
...
isRayExtension = true;
break;
...
if (isRayExtension)
{
emitOpDecorateLocation(...);
}
In general, "goto" should be limited to error handling; not for code reuse.
source/slang/slang-ir.cpp
Outdated
IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandRayPayloadFromLocation(IRInst* inst) | ||
{ | ||
SLANG_ASSERT(as<IRSPIRVAsm>(m_insertLoc.getParent())); | ||
const auto i = createInst<IRSPIRVAsmOperand>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that you shouldn't have const here because your return type doesn't have const and "i" will be returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const is used since other functions which do the same thing also set a const ptr for return; likely const is used since in the function we are signaling that the ptr's value won't change value between instantiation and returning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"const" is not a "signal"-ing keyword, and it cannot automatically become non-const.
Something doesn't look right on this code to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some checking, in godbolt -- it should not compile in MSVC (without a flag), nor does it likely emit different ASM... I will check to see if there is a reason the other functions use a const~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, just a cause of warnings; I suppose I will remove all of the const'ness from these type of functions and if there is a question of why that will be a different discussion
source/slang/slang-ir.h
Outdated
@@ -2239,6 +2240,8 @@ struct IRAnalysis | |||
IRDominatorTree* getDominatorTree(); | |||
}; | |||
|
|||
struct DiagnosticSink; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may need to move this line up to the top where other classes are declared; around line 28~38.
source/slang/slang-parser.cpp
Outdated
@@ -7013,6 +7013,27 @@ namespace Slang | |||
{ | |||
return SPIRVAsmOperand{ SPIRVAsmOperand::NonSemanticDebugPrintfExtSet, parser->ReadToken() }; | |||
} | |||
else if (AdvanceIf(parser, "__rayPayloadFromLocation")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should keep the coding style same as how the previous code was written.
Please add a new line character between ")" and "{".
I see that this mistake occurs on multiple lines in this PR.
source/slang/slang-parser.cpp
Outdated
@@ -7771,6 +7793,20 @@ namespace Slang | |||
parser->ReadToken(TokenType::Comma); | |||
} | |||
|
|||
#define CASE(key, type) if (AdvanceIf(parser, #key)) { auto modifier = parser->astBuilder->create<type>(); \ | |||
modifier->location = getIntegerLiteralValue(listBuilder.find<GLSLLayoutModifier>()->valToken); listBuilder.add(modifier); } else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "modifier->location" only for debugging purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modifier->location is for creating a modifier and tying a glsl layout(location) location value to it
Looks good to me |
fix various code-style warnings fix vkray regression: remove assumption that layout-val will be attached to a vk object decoration (causes crashes in some specific senarios) add missing ext's to hlsl.meta removed __specialized_for_target(glsl) for specific function due to causing a regression and not doing anything functional
9f4ec6e
to
b8c3f4c
Compare
fixed lots of coding style issues added early intrinsic pass to handle spirv get_from_location and for the future 'glsl magic syntax'->'target with well defined syntax'
(once capabilities auto-add ext's, these problems will be no more!)
added missing cap's to raytracing & adjusted syntax+naming to be conformant with Slang
…/ArielG-NV/slang into glsl.meta.slang_raytracing_#3560
…syntax + glsl syntax for raytracing objects as well, which is quite cool) changed comment about early raytracing object addition to ir (more about positioning of code emitted)
change code emit'ing to ensure it emits properly at top of scope refactored a bit of the descriptions to be more accurate for why we need things done the way they are
…adds to entry point)
…/ArielG-NV/slang into glsl.meta.slang_raytracing_#3560
…ess conflicts changed spirv replacement to be proper and not a hacky 'working' implementation (since the code is being finalized now and I don't need a 'just working' implementation for testing)
… no ref --> no HLSL export tag
This PR is only for a code review purpose.