• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Jason Smith
      While working on a project using D3D12 I was getting an exception being thrown while trying to get a D3D12_CPU_DESCRIPTOR_HANDLE. The project is using plain C so it uses the COBJMACROS. The following application replicates the problem happening in the project.
      #define COBJMACROS #pragma warning(push, 3) #include <Windows.h> #include <d3d12.h> #include <dxgi1_4.h> #pragma warning(pop) IDXGIFactory4 *factory; ID3D12Device *device; ID3D12DescriptorHeap *rtv_heap; int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE pinst, PWSTR cline, int cshow) { (hinst), (pinst), (cline), (cshow); HRESULT hr = CreateDXGIFactory1(&IID_IDXGIFactory4, (void **)&factory); hr = D3D12CreateDevice(0, D3D_FEATURE_LEVEL_11_0, &IID_ID3D12Device, &device); D3D12_DESCRIPTOR_HEAP_DESC desc; desc.NumDescriptors = 1; desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV; desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; desc.NodeMask = 0; hr = ID3D12Device_CreateDescriptorHeap(device, &desc, &IID_ID3D12DescriptorHeap, (void **)&rtv_heap); D3D12_CPU_DESCRIPTOR_HANDLE rtv = ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(rtv_heap); (rtv); } The call to ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart throws an exception. Stepping into the disassembly for ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart show that the error occurs on the instruction
      mov  qword ptr [rdx],rax
      which seems odd since rdx doesn't appear to be used. Any help would be greatly appreciated. Thank you.
       
    • By lubbe75
      As far as I understand there is no real random or noise function in HLSL. 
      I have a big water polygon, and I'd like to fake water wave normals in my pixel shader. I know it's not efficient and the standard way is really to use a pre-calculated noise texture, but anyway...
      Does anyone have any quick and dirty HLSL shader code that fakes water normals, and that doesn't look too repetitious? 
    • By turanszkij
      Hi,
      I finally managed to get the DX11 emulating Vulkan device working but everything is flipped vertically now because Vulkan has a different clipping space. What are the best practices out there to keep these implementation consistent? I tried using a vertically flipped viewport, and while it works on Nvidia 1050, the Vulkan debug layer is throwing error messages that this is not supported in the spec so it might not work on others. There is also the possibility to flip the clip scpace position Y coordinate before writing out with vertex shader, but that requires changing and recompiling every shader. I could also bake it into the camera projection matrices, though I want to avoid that because then I need to track down for the whole engine where I upload matrices... Any chance of an easy extension or something? If not, I will probably go with changing the vertex shaders.
    • By NikiTo
      Some people say "discard" has not a positive effect on optimization. Other people say it will at least spare the fetches of textures.
       
      if (color.A < 0.1f) { //discard; clip(-1); } // tons of reads of textures following here // and loops too
      Some people say that "discard" will only mask out the output of the pixel shader, while still evaluates all the statements after the "discard" instruction.

      MSN>
      discard: Do not output the result of the current pixel.
      clip: Discards the current pixel..
      <MSN

      As usual it is unclear, but it suggests that "clip" could discard the whole pixel(maybe stopping execution too)

      I think, that at least, because of termal and energy consuming reasons, GPU should not evaluate the statements after "discard", but some people on internet say that GPU computes the statements anyways. What I am more worried about, are the texture fetches after discard/clip.

      (what if after discard, I have an expensive branch decision that makes the approved cheap branch neighbor pixels stall for nothing? this is crazy)
    • By NikiTo
      I have a problem. My shaders are huge, in the meaning that they have lot of code inside. Many of my pixels should be completely discarded. I could use in the very beginning of the shader a comparison and discard, But as far as I understand, discard statement does not save workload at all, as it has to stale until the long huge neighbor shaders complete.
      Initially I wanted to use stencil to discard pixels before the execution flow enters the shader. Even before the GPU distributes/allocates resources for this shader, avoiding stale of pixel shaders execution flow, because initially I assumed that Depth/Stencil discards pixels before the pixel shader, but I see now that it happens inside the very last Output Merger state. It seems extremely inefficient to render that way a little mirror in a scene with big viewport. Why they've put the stencil test in the output merger anyway? Handling of Stencil is so limited compared to other resources. Does people use Stencil functionality at all for games, or they prefer discard/clip?

      Will GPU stale the pixel if I issue a discard in the very beginning of the pixel shader, or GPU will already start using the freed up resources to render another pixel?!?!



       
  • Advertisement
  • Advertisement
Sign in to follow this  

DX12 Directx 12 hull shader error

This topic is 715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an application that uses DX12 with feature level 12.0. Recently hull shaders hlsl code compilation is crashing (at function D3DCompileFromFile) when I access multiple constant buffers from hull shader. Is there a limitation on how many constant buffers hull shader can access? I did not find anything mentioned here https://msdn.microsoft.com/en-us/library/windows/desktop/mt186615(v=vs.85).aspx.

 

If I use more than one constant buffer, it throws following error -

 

Exception thrown at 0x00007FFE9550D6C8 in AppWin.exe: Microsoft C++ exception: long at memory location 0x0000003A498F6C0C.
Exception thrown at 0x00007FFE9550D6C8 in AppWin.exe: Microsoft C++ exception: long at memory location 0x0000003A498F6D40.
error X8000: D3D11 Internal Compiler Error: Invalid Bytecode: Reference out of bounds, [0], on cb0[size==14] (if size is listed as 0, it means default size is used, which is 4096.  Opcode #42, operand #2 (counts are 1-based).
error X8000: D3D11 Internal Compiler Error: Invalid Bytecode: Can't continue validation - aborting.

 

The error message says "D3D11 Internal Compiler Error...", even though I am using DX12.

 

I get error when I use -

HS_CONSTANT_DATA_OUTPUT mainConstantsHS_High(InputPatch<VS_OUTPUT, 3> inputPatch, uint patchID : SV_PrimitiveID)
{
	HS_CONSTANT_DATA_OUTPUT output = (HS_CONSTANT_DATA_OUTPUT)0;
	output.edges[0] = buffer0Data + buffer1Data;
	output.edges[1] = buffer0Data;
	output.edges[2] = buffer0Data;
	output.inside = buffer0Data;
	return output;
}

But no error when I use just one buffer -

HS_CONSTANT_DATA_OUTPUT mainConstantsHS_High(InputPatch<VS_OUTPUT, 3> inputPatch, uint patchID : SV_PrimitiveID)
{
	HS_CONSTANT_DATA_OUTPUT output = (HS_CONSTANT_DATA_OUTPUT)0;
	output.edges[0] = buffer0Data;
	output.edges[1] = buffer0Data;
	output.edges[2] = buffer0Data;
	output.inside = buffer0Data;
	return output;
}

I have GTX 970 video card with Windows 10 14925 and VS 2015 update 2.

Thanks

Share this post


Link to post
Share on other sites
Advertisement

Can you provide a minimally compilable shader that includes the definitions for your constant buffers and HS_CONSTANT_DATA_OUTPUT? Have you tried compiling the shader offline using fxc?

 

Also, I don't think Windows 10 14925 is a thing (yet).

Share this post


Link to post
Share on other sites

Thanks Adam for replying my post. I had never tried FXC command line before. I tried to too. Same error.

 

Here is the stripped down version of the code.

//make all the matrices row major
#pragma pack_matrix( row_major )

//structure for light
struct Light
{
	float4x4 viewProjMatrix; //view projection matrix of the light
	float3 position;	//position of light
	float nearPlane;	//near plane of light
	float3 direction;	//direction of light
	float farPlane;		//far plane of light
	float3 color;		//color of light
	float ambientAmount;	//amount of ambient light
	float lightInfluenceRadius;	//light influence radius
	float lightInfluenceMaxCutoff;	//max influence radius of light (it can be lightInfluenceRadius) If smaller creates spotlight
	float cosAngleInnerCone;	//cos range(inner cone)
	float cosAngleOuterCone;	//cos angle end (outer cone)
};

typedef float4 floatPlane;

//Constant buffer per frame
cbuffer ConstantBufferPerFrame : register(b0, space1)
{
	Light mainLight;	//light parameter
	float3 eyePosition;	//camera position
	float dt;	//delta time since last frame
	float3 eyeLookAt;	//camera lookat point
	float elapsedTime;	//total elapsed
	float3 eyeUp;	//camera up direction
	float depthDelta;	//for computing shadow
	float3 eyeSide;	//camera side
	bool enableShadow;	//is shadow enabled
	float4x4 viewMatrix;	//camera view matrix
	float4x4 projMatrix;	//camera projection matrix
	float4x4 viewProjMatrix;	//camera view and projection matrix combined	
	float4x4 viewMatrixInverse;	//inverse of camera view matrix
	float4x4 projMatrixInverse;	//inverse of camera projection matrix
	float4x4 viewProjMatrixInverse;	//inverse of camera view and projection matrix combined
	floatPlane clipPlane0;	//for clipping for reflection
	float3 fogColor;	//color of fog
	float fogDensity;	//fog density
	float3 gravity;		//gravity direction
	float waterLevel;	//water level
	float3 windDirection;	//direction of the wind
	float wetnessFactor;	//how wet is the scene [0-1]
	float coldnessFactor;	//how cold is the scene [0-1]
	float nearPlane;	//near plane of camera
	float farPlane;		//far plane of camera
	float maxTessellationDistanceAdjustment; //maximum tessellation distance
};

//Constant buffer per object
cbuffer ConstantBufferPerObject : register(b0)
{
	float4x4 worldMatrix;
	float4x4 worldMatrixInverseTranspose;
	float4 dataDiffuseAlpha;	//diffuse and alpha
	float4 dataNormalHeight;	//normal and height data
	float4 dataSpecularLevel;	//specular color and specular level (controls intensity)
	float4 dataIlluminationGlossiness;	//illumination color and glossiness (controls size of specular spot)
	float3 scatterColor;	//color that is scattered by sub-surface scattering, 0 will disable it
	float maxScatterDepthWorldSpace;	//maximum depth light can penetrate
	float R0; //computation based on nvidia's article
	float etaRatio; //Ratio of indices of refraction indexOfRefractionFirst/indexOfRefractionSecond
	float maxTessellationFactor;	//geometry tessellation
	float maxTessellationBumpHeight;	//maximum tessellation bump height
};

// Per-vertex data used as input to the vertex shader.
struct VS_INPUT
{
	float3 position : POSITION;
};

struct VS_OUTPUT
{
	float3 worldPosition : WORLDPOS;
};

struct HS_CONSTANT_DATA_OUTPUT
{
	float edges[3]	: SV_TessFactor;
	float inside : SV_InsideTessFactor;
};

struct HS_CONTROL_POINT_OUTPUT
{
	float3 worldPosition : WORLDPOS;
};

struct DS_OUTPUT
{
	float3 worldPosition : WORLDPOS;
};

// Per-pixel color data passed through the pixel shader.
struct GS_OUTPUT
{
	float4 screenPositionSV : SV_POSITION;
};

struct PS_OUTPUT
{
	float4 color0 : SV_Target0;
};
//////////////////////////////////////////////////////////////////////

// Simple shader to do vertex processing on the GPU.
VS_OUTPUT mainVS_High(VS_INPUT input)
{
	VS_OUTPUT output = (VS_OUTPUT)0;

	float4 position = float4(input.position.xyz, 1.0);
	position = mul(worldMatrix, position);
	output.worldPosition = (position.xyz / position.w);
	
	return output;
}

// Hull shader constant data
HS_CONSTANT_DATA_OUTPUT mainConstantsHS_High(InputPatch<VS_OUTPUT, 3> inputPatch, uint patchID : SV_PrimitiveID)
{
	HS_CONSTANT_DATA_OUTPUT output = (HS_CONSTANT_DATA_OUTPUT)0;

	////// Assign tessellation levels
	//output.edges[0] = maxTessellationFactor;
	//output.edges[1] = maxTessellationFactor;
	//output.edges[2] = maxTessellationFactor;
	//output.inside = maxTessellationFactor;

	//// Assign tessellation levels
	output.edges[0] = maxTessellationFactor + maxTessellationDistanceAdjustment;
	output.edges[1] = maxTessellationFactor + maxTessellationDistanceAdjustment;
	output.edges[2] = maxTessellationFactor + maxTessellationDistanceAdjustment;
	output.inside = maxTessellationFactor + maxTessellationDistanceAdjustment;

	return output;
}

//hull shader control pooint
[domain("tri")]
[partitioning("fractional_odd")]
[outputtopology("triangle_cw")]	//goes 1,2,3 and so on. Triangles are supplied in CCW order already so no need to change
[outputcontrolpoints(3)]
[patchconstantfunc("mainConstantsHS_High")]
[maxtessfactor(64.0)]
HS_CONTROL_POINT_OUTPUT mainHS_High(InputPatch<VS_OUTPUT, 3> inputPatch, uint uCPID : SV_OutputControlPointID)
{
	HS_CONTROL_POINT_OUTPUT    output = (HS_CONTROL_POINT_OUTPUT)0;

	// Copy inputs to outputs
	output.worldPosition = inputPatch[uCPID].worldPosition.xyz;

	return output;
}

//domain shader
[domain("tri")]
DS_OUTPUT mainDS_High(HS_CONSTANT_DATA_OUTPUT input, float3 barycentricCoordinates : SV_DomainLocation, const OutputPatch<HS_CONTROL_POINT_OUTPUT, 3> triPatch)
{
	DS_OUTPUT output = (DS_OUTPUT)0;

	//Interpolate world space position with barycentric coordinates
	float3 worldPosition =
		barycentricCoordinates.x * triPatch[0].worldPosition + 
		barycentricCoordinates.y * triPatch[1].worldPosition +
		barycentricCoordinates.z * triPatch[2].worldPosition;
	output.worldPosition = worldPosition;

	return output;
}


// Geometry shader
[maxvertexcount(3)]
void mainGS_High(triangle DS_OUTPUT input[3], inout TriangleStream<GS_OUTPUT> triStream)
{
	GS_OUTPUT output = (GS_OUTPUT)0;

	//perform view projection transformation
	for (int i = 0; i<3; i++)
	{

		float4 screenPosition = mul(viewProjMatrix, float4(input[i].worldPosition, 1.0));
		output.screenPositionSV = screenPosition;
		triStream.Append(output);
	}
	triStream.RestartStrip();
}


// Per-pixel color data passed through the pixel shader. A pass-through function for the (interpolated) color data.
PS_OUTPUT mainPS_High(GS_OUTPUT input)
{
	//set to zero
	PS_OUTPUT output = (PS_OUTPUT)0;
	output.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);

	return output;
}

I used FXC command line - "C:\Program Files (x86)\Windows Kits\10\bin\x64\fxc.exe" /Od /Zi ErrorTest.fx /Fo tmpHH.o /T hs_5_1 /E mainHS_High

 

I get the same error as before. But if I switch to the commented out code in the hull shader, it works fine;

 

I am using insider build of Windows. It should not matter but I just posted it there just in case.

 

Thanks

Share this post


Link to post
Share on other sites

I'll send it through to the compiler team to take a look at.

The crash is actually already fixed in the latest internal builds of the compiler, so you'll be able to pick up this fix in the next version of the Windows SDK.
 

In the meantime, aside from placing one of your constant buffers in 'space1', you don't appear to be doing anything requiring Shader Model 5.1. The shader compiles fine if you use Shader Model 5.0 (hs_5_0). If you move your constant buffer from space1 into slot 'b1' of space0 and use hs_5_0, that'll unblock you in the meantime.

Thanks,

 

Adam

Edited by Adam Miles

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement