how can i get the pixel shader asm code "Ld"?I'm writing HLSL - directx

When I'm reading the asm code ,I dont know how to get the instruction "ld" just below.
Which function should I use in HLSL to get it?
Or had it be replaced with the update of versions?
The following is asm code:
ld r0.xyzw r0.xyzw t19.xyzw
I tried to use texture2D in HLSL but when compiled it was "sample " not "ld".

ld is a Shader Model 4.0 or later instruction. Which shader profile & HLSL compiler are you using?
The Load member of a texture object is typically how you do this in modern HLSL.
Texture2D<float4> g_Input : register( t0 );
float4 pixel = g_Input.Load(...);

Related

Metal Shader vertex attributes - cannot convert attribute from MTLAttributeFormatUInt to float1

I have a shader that looks like this:
struct VertexIn {
float a_customIdx [[attribute(0)]];
...
};
vertex vec4 vertex_func(VertexIn v_in [[stage_in]], ...) {...}
In my buffer I'm actually passing in a uint32_t for a_customIdx, so in my MTLVertexAttributeDescriptor I specify its type to be MTLAttributeFormatUInt. When I create the RenderPipelineState I get the error:
cannot convert attribute from MTLAttributeFormatUInt to float1
I get the same error if I use MTLAttributeFormatInt, but can successfully convert a MTLAttributeFormatUShort.
Why is this not a valid operation? According to the documentation for format, "Casting any MTLVertexFormat to a float or half is valid".
I know there are multiple ways I can get around this problem, but I'm curious about why this is invalid - perhaps there's something about alignments and byte sizes I'm missing here.

validateFunctionArguments:3379: failed assertion `Fragment Function , The pixel format (MTLPixelFormatRGBA16Unorm) of the texture

validateFunctionArguments:3379: failed assertion `Fragment Function(ca_uber_fragment_lp0_cp1_fo0): The pixel format (MTLPixelFormatRGBA16Unorm) of the texture (name:) bound at index 0 is incompatible with the data type (MTLDataTypeHalf) of the texture parameter (img_tex_0A [[texture(0)]]). MTLPixelFormatRGBA16Unorm is compatible with the data type(s) (
float
).'
When I run my project on iPhone 8, I got this crash error, someone adviced me to set "edit scheme - Options - Metal API Validation" disabled, and It really can solve it, But I do not know why ? so I'm looking forward to you give me some suggestions, Thanks.
Try to set colorPixelFormat = .bgra8Unorm for your MTLView and MTLRenderPipelineState
In the metal function, you have one of two options - try changing the texture type from float to half or from half to float.
texture2d<float, access::read> myTexture [[texture(0)]]
texture2d<half, access::read> myTexture [[texture(0)]]

Metal: unknown type name float4

I'm trying to include a header file in a metal shader.
For a prototype like this,
float4 someFunction(float4 v);
I get this error message,
Unknown type name 'float4'; did you mean 'float'?
It seems it doesn't understand it's a header for a shader program... Although other errors suggest it does. For instance, if I don't specify the address space here,
static float someK = 2.0;
I get this error,
Global variables must have a constant address space qualifier
which can be fixed if I add
constant static float someK = 2.0;
If I use references, I also get these type of errors,
Reference type must include device, threadgroup, constant, or thread address space qualifier
So it does look as if the compiler knows it's a shader. Why it doesn't know about float4? :(
Make sure you have the first two lines in your shader like in this example:
#include <metal_stdlib>
using namespace metal;
float4 someFunction(float4 v);
kernel void compute(texture2d<float, access::write> output [[texture(0)]],
uint2 gid [[thread_position_in_grid]])
{
float4 color = float4(0, 0.5, 0.5, 1);
output.write(color, gid);
}
This works fine for me.
Try using
vector_float4
instead.

Updating float4 declaration from dx9 to dx11

There's a shader which was given which I'm trying to update to be compatible with the newest Unity 5 (presumably dx11). I don't understand how float4 basic instantiation from dx9 was working. Can someone help me understand the following syntax and then provide an equivalent dx11 syntax?
I understand that float4 normally uses x,y,z,w or xyz,y as arguments, but what does did a single float argument do? Did float4(0.01) make {.01,0,0,0} or does float4(.01) make {.01,.01,.01,.01}?
Original code from the shader:
float4 Multiply19 = float4( 0.01 ) * float4( 0 );
It should make a new float4 with all members (xyzw) set to 0.01 and then multiply all that by 0, effectively making Multiply19 a (0, 0, 0, 0) float4.

resize an image and changing its depth

I need to resize an IplImage and convert it into a CvMat of different depth, this is the code I've written so far:
void cvResize2(IplImage *imgSrc, IplImage *imgDst)
{
IplImage *imgTemp;
imgTemp = cvCreateImage( cvGetSize( imgSrc ), IPL_DEPTH_64F, 1 );
cvScale( imgSrc, imgTemp, 1/255., 0.0 );
cvResize( imgTemp, imgDst );
}
The source image is grayscale, the destination one is 64F bit deep. cvScale only scales between images of same size, hence the temp image.
The program rises the following exception when invoking cvResize:
OpenCV Error: Assertion failed (func != 0) in resize, file /tmp/buildd/opencv-2.1.0/src/cv/cvimgwarp.cpp, line 1488
terminate called after throwing an instance of 'cv::Exception'
what(): /tmp/buildd/opencv-2.1.0/src/cv/cvimgwarp.cpp:1488: error: (-215) func != 0 in function resize
I can't figure out why, I've checked that the images respect the conditions imposed
src: 512x384, 8 depth
tmp: 512x384, 64 depth
dst: 64x64, 64 depth
Any clues?
Thanks in advance
You may have found a bug. I can reproduce it on my end, too (Ubuntu 64-bit, OpenCV-2.1.0). If you use 32-bit floating point precision, it works, but crashes with 64-bit floats. My recommendation is to update your OpenCV to the most recent version and see if the problem goes away. If not, then build the library in debug mode and step through the function that is throwing the assertion. From looking at the culprit source in cvimgwarp.cpp, it looks like it's unable to find an interpolation method to use for the destination image.

Resources